Skip to content

Commit

Permalink
feat: [CDS-98117]: Onboard provider APIS to terraform (#1091)
Browse files Browse the repository at this point in the history
* feat: [CDS-98117]: Onboard provider APIS to terraform

* feat: [CDS-98117]: Onboard provider APIS to terraform

* feat: [CDS-98117]: Onboard provider APIS to terraform

* feat: [CDS-98117]: Onboard provider APIS to terraform

* feat: [CDS-98117]: Update go-sdk version
  • Loading branch information
sarthakkasat authored Oct 14, 2024
1 parent e5d6bf2 commit 51eb950
Show file tree
Hide file tree
Showing 7 changed files with 490 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/antihax/optional v1.0.0
github.com/aws/aws-sdk-go v1.46.4
github.com/docker/docker v24.0.5+incompatible
github.com/harness/harness-go-sdk v0.4.10
github.com/harness/harness-go-sdk v0.4.11
github.com/harness/harness-openapi-go-client v0.0.21
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/harness/harness-go-sdk v0.4.10 h1:iRpsG35I1bZ618FOHnAMKG7FBfiEpTGPyLz0mICsuAU=
github.com/harness/harness-go-sdk v0.4.10/go.mod h1:a/1HYTgVEuNEoh3Z3IsOHZdlUNxl94KcX57ZSNVGll0=
github.com/harness/harness-go-sdk v0.4.11 h1:AJ9t7Yh9Ub3SnlDmq/3X4AosCStKBJczWPYVt46WODw=
github.com/harness/harness-go-sdk v0.4.11/go.mod h1:a/1HYTgVEuNEoh3Z3IsOHZdlUNxl94KcX57ZSNVGll0=
github.com/harness/harness-openapi-go-client v0.0.21 h1:VtJnpQKZvCAlaCmUPbNR69OT3c5WRdhNN5TOgUwtwZ4=
github.com/harness/harness-openapi-go-client v0.0.21/go.mod h1:u0vqYb994BJGotmEwJevF4L3BNAdU9i8ui2d22gmLPA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
3 changes: 3 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import (
"github.com/harness/terraform-provider-harness/internal/service/platform/pipeline"
"github.com/harness/terraform-provider-harness/internal/service/platform/pipeline_filters"
"github.com/harness/terraform-provider-harness/internal/service/platform/project"
pl_provider "github.com/harness/terraform-provider-harness/internal/service/platform/provider"
"github.com/harness/terraform-provider-harness/internal/service/platform/repo"
"github.com/harness/terraform-provider-harness/internal/service/platform/resource_group"
"github.com/harness/terraform-provider-harness/internal/service/platform/role_assignments"
Expand Down Expand Up @@ -203,6 +204,7 @@ func Provider(version string) func() *schema.Provider {
"harness_platform_environment_clusters_mapping": pl_environment_clusters_mapping.DataSourceEnvironmentClustersMapping(),
"harness_platform_environment_service_overrides": pl_environment_service_overrides.DataSourceEnvironmentServiceOverrides(),
"harness_platform_service_overrides_v2": pl_service_overrides_v2.DataSourceServiceOverrides(),
"harness_platform_provider": pl_provider.DataSourceProvider(),
"harness_platform_overrides": pl_overrides.DataSourceOverrides(),
"harness_platform_gitops_agent": gitops_agent.DataSourceGitopsAgent(),
"harness_platform_gitops_agent_deploy_yaml": agent_yaml.DataSourceGitopsAgentDeployYaml(),
Expand Down Expand Up @@ -338,6 +340,7 @@ func Provider(version string) func() *schema.Provider {
"harness_platform_feature_flag_target_group": feature_flag_target_group.ResourceFeatureFlagTargetGroup(),
"harness_platform_feature_flag_target": feature_flag_target.ResourceFeatureFlagTarget(),
"harness_platform_service_overrides_v2": pl_service_overrides_v2.ResourceServiceOverrides(),
"harness_platform_provider": pl_provider.ResourceProvider(),
"harness_platform_overrides": pl_overrides.ResourceOverrides(),
"harness_platform_ff_api_key": ff_api_key.ResourceFFApiKey(),
"harness_platform_gitops_agent": gitops_agent.ResourceGitopsAgent(),
Expand Down
47 changes: 47 additions & 0 deletions internal/service/platform/provider/data_source_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package provider

import (
"context"

"github.com/harness/terraform-provider-harness/helpers"
"github.com/harness/terraform-provider-harness/internal"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceProvider() *schema.Resource {
resource := &schema.Resource{
Description: "Data source for Harness Provider.",

ReadContext: dataSourceProviderRead,

Schema: map[string]*schema.Schema{
"identifier": {
Description: "The identifier of the provider entity.",
Type: schema.TypeString,
Required: true,
},
},
}
return resource
}

func dataSourceProviderRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
identifier := d.Get("identifier").(string)

resp, httpResp, err := c.ProviderApi.GetProvider(ctx, identifier, c.AccountId)
if err != nil {
return helpers.HandleApiError(err, d, httpResp)
}

if resp.Data == nil {
d.SetId("")
d.MarkNewResource()
return nil
}

readProvider(d, resp.Data)

return nil
}
51 changes: 51 additions & 0 deletions internal/service/platform/provider/data_source_provider_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package provider_test

import (
"fmt"
"testing"

"github.com/harness/harness-go-sdk/harness/utils"
"github.com/harness/terraform-provider-harness/internal/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestDataSourceProvider(t *testing.T) {

id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(6))
name := id
resourceName := "data.harness_platform_provider.test"

resource.UnitTest(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceProvider(id, name),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "identifier", id),
),
},
},
})
}

func testAccDataSourceProvider(id string, name string) string {
return fmt.Sprintf(`
resource "harness_platform_provider" "test" {
identifier = "%[1]s"
name = "%[2]s"
spec {
type = "BITBUCKET_SERVER"
domain = "https://example.com"
secret_manager_ref = "secret-ref"
delegate_selectors = ["delegate-1", "delegate-2"]
client_id = "client-id"
client_secret_ref = "client-secret-ref"
}
}
data "harness_platform_provider" "test" {
identifier = harness_platform_provider.test.identifier
}
`, id, name)
}
Loading

0 comments on commit 51eb950

Please sign in to comment.