diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 34a49b3ca..70c5827cb 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -49,6 +49,9 @@ import ( cd_trigger "github.com/harness/terraform-provider-harness/internal/service/cd/trigger" "github.com/harness/terraform-provider-harness/internal/service/cd/user" "github.com/harness/terraform-provider-harness/internal/service/cd/yamlconfig" + cdng_connector_artifactRepositories "github.com/harness/terraform-provider-harness/internal/service/cd_nextgen/connector/artifactRepositories" + cdng_connector_cloudProviders "github.com/harness/terraform-provider-harness/internal/service/cd_nextgen/connector/cloudProviders" + cdng_connector_codeRepositories "github.com/harness/terraform-provider-harness/internal/service/cd_nextgen/connector/codeRepositories" pl_account "github.com/harness/terraform-provider-harness/internal/service/platform/account" pl_apikey "github.com/harness/terraform-provider-harness/internal/service/platform/api_key" "github.com/harness/terraform-provider-harness/internal/service/platform/autostopping/load_balancer" @@ -163,36 +166,36 @@ func Provider(version string) func() *schema.Provider { "harness_platform_connector_azure_cloud_cost": connector.DataSourceConnectorAzureCloudCost(), "harness_platform_connector_appdynamics": connector.DatasourceConnectorAppDynamics(), "harness_platform_connector_elasticsearch": connector.DatasourceConnectorElasticSearch(), - "harness_platform_connector_artifactory": connector.DatasourceConnectorArtifactory(), + "harness_platform_connector_artifactory": cdng_connector_artifactRepositories.DatasourceConnectorArtifactory(), "harness_platform_connector_aws_secret_manager": pl_secretManagers.DatasourceConnectorAwsSM(), - "harness_platform_connector_aws": connector.DatasourceConnectorAws(), + "harness_platform_connector_aws": cdng_connector_cloudProviders.DatasourceConnectorAws(), "harness_platform_connector_awscc": connector.DatasourceConnectorAwsCC(), "harness_platform_connector_awskms": pl_secretManagers.DatasourceConnectorAwsKms(), - "harness_platform_connector_bitbucket": connector.DatasourceConnectorBitbucket(), + "harness_platform_connector_bitbucket": cdng_connector_codeRepositories.DatasourceConnectorBitbucket(), "harness_platform_connector_customhealthsource": connector.DatasourceConnectorCustomHealthSource(), "harness_platform_connector_datadog": connector.DatasourceConnectorDatadog(), - "harness_platform_connector_docker": connector.DatasourceConnectorDocker(), + "harness_platform_connector_docker": cdng_connector_artifactRepositories.DatasourceConnectorDocker(), "harness_platform_connector_jdbc": connector.DatasourceConnectorJDBC(), "harness_platform_connector_dynatrace": connector.DatasourceConnectorDynatrace(), - "harness_platform_connector_gcp": connector.DatasourceConnectorGcp(), + "harness_platform_connector_gcp": cdng_connector_cloudProviders.DatasourceConnectorGcp(), "harness_platform_connector_gcp_secret_manager": pl_secretManagers.DatasourceConnectorGcpSM(), - "harness_platform_connector_git": connector.DatasourceConnectorGit(), - "harness_platform_connector_github": connector.DatasourceConnectorGithub(), - "harness_platform_connector_gitlab": connector.DatasourceConnectorGitlab(), - "harness_platform_connector_helm": connector.DatasourceConnectorHelm(), - "harness_platform_connector_oci_helm": connector.DatasourceConnectorOciHelm(), + "harness_platform_connector_git": cdng_connector_codeRepositories.DatasourceConnectorGit(), + "harness_platform_connector_github": cdng_connector_codeRepositories.DatasourceConnectorGithub(), + "harness_platform_connector_gitlab": cdng_connector_codeRepositories.DatasourceConnectorGitlab(), + "harness_platform_connector_helm": cdng_connector_artifactRepositories.DatasourceConnectorHelm(), + "harness_platform_connector_oci_helm": cdng_connector_artifactRepositories.DatasourceConnectorOciHelm(), "harness_platform_connector_jira": connector.DatasourceConnectorJira(), - "harness_platform_connector_jenkins": connector.DataSourceConnectorJenkins(), - "harness_platform_connector_kubernetes": connector.DatasourceConnectorKubernetes(), - "harness_platform_connector_nexus": connector.DatasourceConnectorNexus(), + "harness_platform_connector_jenkins": cdng_connector_artifactRepositories.DataSourceConnectorJenkins(), + "harness_platform_connector_kubernetes": cdng_connector_cloudProviders.DatasourceConnectorKubernetes(), + "harness_platform_connector_nexus": cdng_connector_artifactRepositories.DatasourceConnectorNexus(), "harness_platform_connector_pagerduty": connector.DatasourceConnectorPagerDuty(), "harness_platform_connector_prometheus": connector.DatasourceConnectorPrometheus(), - "harness_platform_connector_rancher": connector.DatasourceConnectorRancher(), + "harness_platform_connector_rancher": cdng_connector_cloudProviders.DatasourceConnectorRancher(), "harness_platform_connector_splunk": connector.DatasourceConnectorSplunk(), - "harness_platform_connector_spot": connector.DatasourceConnectorSpot(), - "harness_platform_connector_terraform_cloud": connector.DatasourceConnectorTerraformCloud(), + "harness_platform_connector_spot": cdng_connector_cloudProviders.DatasourceConnectorSpot(), + "harness_platform_connector_terraform_cloud": cdng_connector_cloudProviders.DatasourceConnectorTerraformCloud(), "harness_platform_connector_sumologic": connector.DatasourceConnectorSumologic(), - "harness_platform_connector_pdc": connector.DatasourceConnectorPdc(), + "harness_platform_connector_pdc": cdng_connector_cloudProviders.DatasourceConnectorPdc(), "harness_platform_connector_custom_secret_manager": pl_secretManagers.DatasourceConnectorCustomSM(), "harness_platform_current_account": pl_account.DataSourceCurrentAccount(), "harness_platform_current_user": pl_current_user.DataSourceCurrentUser(), @@ -258,8 +261,8 @@ func Provider(version string) func() *schema.Provider { "harness_user_group": user.DataSourceUserGroup(), "harness_user": user.DataSourceUser(), "harness_yaml_config": yamlconfig.DataSourceYamlConfig(), - "harness_platform_connector_azure_cloud_provider": connector.DataSourceConnectorAzureCloudProvider(), - "harness_platform_connector_tas": connector.DataSourceConnectorTas(), + "harness_platform_connector_azure_cloud_provider": cdng_connector_cloudProviders.DataSourceConnectorAzureCloudProvider(), + "harness_platform_connector_tas": cdng_connector_cloudProviders.DataSourceConnectorTas(), "harness_trigger": cd_trigger.DataSourceTrigger(), "harness_platform_policy": policy.DataSourcePolicy(), "harness_platform_policyset": policyset.DataSourcePolicyset(), @@ -300,37 +303,37 @@ func Provider(version string) func() *schema.Provider { "harness_platform_connector_azure_cloud_cost": connector.ResourceConnectorAzureCloudCost(), "harness_platform_connector_appdynamics": connector.ResourceConnectorAppDynamics(), "harness_platform_connector_elasticsearch": connector.ResourceConnectorElasticSearch(), - "harness_platform_connector_artifactory": connector.ResourceConnectorArtifactory(), + "harness_platform_connector_artifactory": cdng_connector_artifactRepositories.ResourceConnectorArtifactory(), "harness_platform_connector_aws_secret_manager": pl_secretManagers.ResourceConnectorAwsSM(), - "harness_platform_connector_aws": connector.ResourceConnectorAws(), + "harness_platform_connector_aws": cdng_connector_cloudProviders.ResourceConnectorAws(), "harness_platform_connector_awscc": connector.ResourceConnectorAwsCC(), "harness_platform_connector_awskms": pl_secretManagers.ResourceConnectorAwsKms(), - "harness_platform_connector_bitbucket": connector.ResourceConnectorBitbucket(), + "harness_platform_connector_bitbucket": cdng_connector_codeRepositories.ResourceConnectorBitbucket(), "harness_platform_connector_customhealthsource": connector.ResourceConnectorCustomHealthSource(), "harness_platform_connector_datadog": connector.ResourceConnectorDatadog(), - "harness_platform_connector_docker": connector.ResourceConnectorDocker(), + "harness_platform_connector_docker": cdng_connector_artifactRepositories.ResourceConnectorDocker(), "harness_platform_connector_jdbc": connector.ResourceConnectorJDBC(), "harness_platform_connector_dynatrace": connector.ResourceConnectorDynatrace(), - "harness_platform_connector_gcp": connector.ResourceConnectorGcp(), + "harness_platform_connector_gcp": cdng_connector_cloudProviders.ResourceConnectorGcp(), "harness_platform_connector_gcp_secret_manager": pl_secretManagers.ResourceConnectorGCPSecretManager(), - "harness_platform_connector_git": connector.ResourceConnectorGit(), - "harness_platform_connector_github": connector.ResourceConnectorGithub(), - "harness_platform_connector_gitlab": connector.ResourceConnectorGitlab(), - "harness_platform_connector_helm": connector.ResourceConnectorHelm(), - "harness_platform_connector_oci_helm": connector.ResourceConnectorOciHelm(), + "harness_platform_connector_git": cdng_connector_codeRepositories.ResourceConnectorGit(), + "harness_platform_connector_github": cdng_connector_codeRepositories.ResourceConnectorGithub(), + "harness_platform_connector_gitlab": cdng_connector_codeRepositories.ResourceConnectorGitlab(), + "harness_platform_connector_helm": cdng_connector_artifactRepositories.ResourceConnectorHelm(), + "harness_platform_connector_oci_helm": cdng_connector_artifactRepositories.ResourceConnectorOciHelm(), "harness_platform_connector_jira": connector.ResourceConnectorJira(), - "harness_platform_connector_jenkins": connector.ResourceConnectorJenkins(), - "harness_platform_connector_kubernetes": connector.ResourceConnectorK8s(), + "harness_platform_connector_jenkins": cdng_connector_artifactRepositories.ResourceConnectorJenkins(), + "harness_platform_connector_kubernetes": cdng_connector_cloudProviders.ResourceConnectorK8s(), "harness_platform_connector_newrelic": connector.ResourceConnectorNewRelic(), - "harness_platform_connector_nexus": connector.ResourceConnectorNexus(), + "harness_platform_connector_nexus": cdng_connector_artifactRepositories.ResourceConnectorNexus(), "harness_platform_connector_pagerduty": connector.ResourceConnectorPagerDuty(), "harness_platform_connector_prometheus": connector.ResourceConnectorPrometheus(), - "harness_platform_connector_rancher": connector.ResourceConnectorK8sRancher(), + "harness_platform_connector_rancher": cdng_connector_cloudProviders.ResourceConnectorK8sRancher(), "harness_platform_connector_splunk": connector.ResourceConnectorSplunk(), - "harness_platform_connector_spot": connector.ResourceConnectorSpot(), - "harness_platform_connector_terraform_cloud": connector.ResourceConnectorTerraformCloud(), + "harness_platform_connector_spot": cdng_connector_cloudProviders.ResourceConnectorSpot(), + "harness_platform_connector_terraform_cloud": cdng_connector_cloudProviders.ResourceConnectorTerraformCloud(), "harness_platform_connector_sumologic": connector.ResourceConnectorSumologic(), - "harness_platform_connector_pdc": connector.ResourceConnectorPdc(), + "harness_platform_connector_pdc": cdng_connector_cloudProviders.ResourceConnectorPdc(), "harness_platform_environment": pl_environment.ResourceEnvironment(), "harness_platform_db_schema": dbschema.ResourceDBSchema(), "harness_platform_db_instance": dbinstance.ResourceDBInstance(), @@ -407,8 +410,8 @@ func Provider(version string) func() *schema.Provider { "harness_user_group_permissions": user.ResourceUserGroupPermissions(), "harness_user": user.ResourceUser(), "harness_yaml_config": yamlconfig.ResourceYamlConfig(), - "harness_platform_connector_azure_cloud_provider": connector.ResourceConnectorAzureCloudProvider(), - "harness_platform_connector_tas": connector.ResourceConnectorTas(), + "harness_platform_connector_azure_cloud_provider": cdng_connector_cloudProviders.ResourceConnectorAzureCloudProvider(), + "harness_platform_connector_tas": cdng_connector_cloudProviders.ResourceConnectorTas(), "harness_platform_policy": policy.ResourcePolicy(), "harness_platform_policyset": policyset.ResourcePolicyset(), "harness_platform_manual_freeze": manual_freeze.ResourceManualFreeze(), diff --git a/internal/service/cd_nextgen/_PreRequisites/main.tf b/internal/service/cd_nextgen/_PreRequisites/main.tf new file mode 100644 index 000000000..ade127b44 --- /dev/null +++ b/internal/service/cd_nextgen/_PreRequisites/main.tf @@ -0,0 +1,50 @@ +# main.tf + +terraform { + required_providers { + harness = { + source = "harness/harness" + } + } +} + +resource "harness_platform_secret_text" "TEST_spot_account_id" { + identifier = "TEST_spot_account_id" + name = "TEST_spot_account_id" + description = "This is a test Spot secret text" + tags = ["foo:bar"] + secret_manager_identifier = "harnessSecretManager" + value_type = "Inline" + value = "my_secret_value" +} +resource "harness_platform_secret_text" "TEST_spot_api_token" { + identifier = "TEST_spot_api_token" + name = "TEST_spot_api_token" + description = "This is a test Spot secret text" + tags = ["foo:bar"] + secret_manager_identifier = "harnessSecretManager" + value_type = "Inline" + value = "my_secret_value" +} + +resource "harness_platform_secret_text" "TEST_api_token_ref" { + identifier = "TEST_api_token_ref" + name = "TEST_api_token_ref" + description = "This is a test Spot secret text" + tags = ["foo:bar"] + secret_manager_identifier = "harnessSecretManager" + value_type = "Inline" + value = "my_secret_value" +} + +resource "harness_platform_secret_text" "doNotDeleteHSM" { + identifier = "doNotDeleteHSM" + name = "doNotDeleteHSM" + description = "This is a test secret text" + tags = ["foo:bar"] + secret_manager_identifier = "harnessSecretManager" + value_type = "Inline" + value = "my_secret_value" +} + +# Additional resources can be added as needed diff --git a/internal/service/cd_nextgen/connector/artifactRepositories/artifactRepositories.go b/internal/service/cd_nextgen/connector/artifactRepositories/artifactRepositories.go new file mode 100644 index 000000000..0629245e4 --- /dev/null +++ b/internal/service/cd_nextgen/connector/artifactRepositories/artifactRepositories.go @@ -0,0 +1,156 @@ +package artifactRepositories + +import ( + "context" + "fmt" + "net/http" + + "github.com/antihax/optional" + "github.com/harness/harness-go-sdk/harness/nextgen" + "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" +) + +type ReadConnectorData func(*schema.ResourceData, *nextgen.ConnectorInfo) error + +func resourceConnectorReadBase(ctx context.Context, d *schema.ResourceData, meta interface{}, connType nextgen.ConnectorType) (*nextgen.ConnectorInfo, diag.Diagnostics) { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + id := d.Id() + if id == "" { + id = d.Get("identifier").(string) + } + + resp, httpResp, err := c.ConnectorsApi.GetConnector(ctx, c.AccountId, id, getReadConnectorOpts(d)) + if err != nil { + return nil, helpers.HandleReadApiError(err, d, httpResp) + } + + if connType != resp.Data.Connector.Type_ { + return nil, diag.FromErr(fmt.Errorf("expected connector to be of type %s, but got %s", connType, resp.Data.Connector.Type_)) + } + + readCommonConnectorData(d, resp.Data.Connector) + + return resp.Data.Connector, nil +} + +func dataConnectorReadBase(ctx context.Context, d *schema.ResourceData, meta interface{}, connType nextgen.ConnectorType) (*nextgen.ConnectorInfo, diag.Diagnostics) { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + id := d.Id() + if id == "" { + id = d.Get("identifier").(string) + } + + resp, httpResp, err := c.ConnectorsApi.GetConnector(ctx, c.AccountId, id, getReadConnectorOpts(d)) + if err != nil { + return nil, helpers.HandleApiError(err, d, httpResp) + } + + if connType != resp.Data.Connector.Type_ { + return nil, diag.FromErr(fmt.Errorf("expected connector to be of type %s, but got %s", connType, resp.Data.Connector.Type_)) + } + + readCommonConnectorData(d, resp.Data.Connector) + + return resp.Data.Connector, nil +} + +func getReadConnectorOpts(d *schema.ResourceData) *nextgen.ConnectorsApiGetConnectorOpts { + connOpts := &nextgen.ConnectorsApiGetConnectorOpts{} + + if attr, ok := d.GetOk("org_id"); ok { + connOpts.OrgIdentifier = optional.NewString(attr.(string)) + } + + if attr, ok := d.GetOk("project_id"); ok { + connOpts.ProjectIdentifier = optional.NewString(attr.(string)) + } + + if attr, ok := d.GetOk("git_sync"); ok { + opts := attr.([]interface{})[0].(map[string]interface{}) + connOpts.Branch = optional.NewString(opts["branch"].(string)) + connOpts.RepoIdentifier = optional.NewString(opts["repo_id"].(string)) + } + + return connOpts +} + +func resourceConnectorCreateOrUpdateBase(ctx context.Context, d *schema.ResourceData, meta interface{}, connector *nextgen.ConnectorInfo) (*nextgen.ConnectorInfo, diag.Diagnostics) { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + id := d.Id() + buildConnector(d, connector) + + var err error + var resp nextgen.ResponseDtoConnectorResponse + var httpResp *http.Response + + if id == "" { + resp, httpResp, err = c.ConnectorsApi.CreateConnector(ctx, nextgen.Connector{Connector: connector}, c.AccountId, &nextgen.ConnectorsApiCreateConnectorOpts{}) + } else { + resp, httpResp, err = c.ConnectorsApi.UpdateConnector(ctx, nextgen.Connector{Connector: connector}, c.AccountId, &nextgen.ConnectorsApiUpdateConnectorOpts{}) + } + + if err != nil { + return nil, helpers.HandleApiError(err, d, httpResp) + } + + readCommonConnectorData(d, resp.Data.Connector) + + return resp.Data.Connector, nil +} + +func resourceConnectorDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + _, httpResp, err := c.ConnectorsApi.DeleteConnector(ctx, c.AccountId, d.Id(), &nextgen.ConnectorsApiDeleteConnectorOpts{ + OrgIdentifier: helpers.BuildField(d, "org_id"), + ProjectIdentifier: helpers.BuildField(d, "project_id"), + ForceDelete: helpers.BuildFieldBool(d, "force_delete")}) + + if err != nil { + return helpers.HandleApiError(err, d, httpResp) + } + + return nil +} + +func buildConnector(d *schema.ResourceData, connector *nextgen.ConnectorInfo) { + if attr := d.Get("name").(string); attr != "" { + connector.Name = attr + } + + if attr := d.Get("identifier").(string); attr != "" { + connector.Identifier = attr + } + + if attr := d.Get("description").(string); attr != "" { + connector.Description = attr + } + + if attr := d.Get("org_id").(string); attr != "" { + connector.OrgIdentifier = attr + } + + if attr := d.Get("project_id").(string); attr != "" { + connector.ProjectIdentifier = attr + } + + if attr := d.Get("tags").(*schema.Set).List(); len(attr) > 0 { + connector.Tags = helpers.ExpandTags(attr) + } +} + +func readCommonConnectorData(d *schema.ResourceData, connector *nextgen.ConnectorInfo) { + d.SetId(connector.Identifier) + d.Set("identifier", connector.Identifier) + d.Set("description", connector.Description) + d.Set("name", connector.Name) + d.Set("org_id", connector.OrgIdentifier) + d.Set("project_id", connector.ProjectIdentifier) + d.Set("tags", helpers.FlattenTags(connector.Tags)) +} diff --git a/internal/service/cd_nextgen/connector/artifactRepositories/artifactRepositories_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/artifactRepositories_test.go new file mode 100644 index 000000000..70a192637 --- /dev/null +++ b/internal/service/cd_nextgen/connector/artifactRepositories/artifactRepositories_test.go @@ -0,0 +1,57 @@ +package artifactRepositories_test + +import ( + "fmt" + + "github.com/antihax/optional" + "github.com/harness/harness-go-sdk/harness/nextgen" + "github.com/harness/terraform-provider-harness/internal/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func testAccConnectorDestroy(resourceName string) resource.TestCheckFunc { + return func(state *terraform.State) error { + connector, _ := testAccGetConnector(resourceName, state) + if connector != nil { + return fmt.Errorf("Found connector: %s", connector.Identifier) + } + + return nil + } +} + +func testAccGetConnector(resourceName string, state *terraform.State) (*nextgen.ConnectorInfo, error) { + r := acctest.TestAccGetResource(resourceName, state) + c, ctx := acctest.TestAccGetPlatformClientWithContext() + id := r.Primary.ID + + options := &nextgen.ConnectorsApiGetConnectorOpts{} + + if attr := r.Primary.Attributes["org_id"]; attr != "" { + options.OrgIdentifier = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["project_id"]; attr != "" { + options.ProjectIdentifier = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["branch"]; attr != "" { + options.Branch = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["repo_id"]; attr != "" { + options.RepoIdentifier = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["repo_id"]; attr != "" { + options.RepoIdentifier = optional.NewString(attr) + } + + resp, _, err := c.ConnectorsApi.GetConnector(ctx, c.AccountId, id, options) + if err != nil { + return nil, err + } + + return resp.Data.Connector, nil +} diff --git a/internal/service/platform/connector/artifactory.go b/internal/service/cd_nextgen/connector/artifactRepositories/artifactory.go similarity index 99% rename from internal/service/platform/connector/artifactory.go rename to internal/service/cd_nextgen/connector/artifactRepositories/artifactory.go index 3df450955..1cd53d090 100644 --- a/internal/service/platform/connector/artifactory.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/artifactory.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "context" diff --git a/internal/service/platform/connector/artifactory_data_source.go b/internal/service/cd_nextgen/connector/artifactRepositories/artifactory_data_source.go similarity index 98% rename from internal/service/platform/connector/artifactory_data_source.go rename to internal/service/cd_nextgen/connector/artifactRepositories/artifactory_data_source.go index c41ab83b2..5c9b4a8d5 100644 --- a/internal/service/platform/connector/artifactory_data_source.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/artifactory_data_source.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/artifactory_data_source_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/artifactory_data_source_test.go similarity index 98% rename from internal/service/platform/connector/artifactory_data_source_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/artifactory_data_source_test.go index e16f2e21c..cbf5f0131 100644 --- a/internal/service/platform/connector/artifactory_data_source_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/artifactory_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/artifactory_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/artifactory_test.go similarity index 99% rename from internal/service/platform/connector/artifactory_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/artifactory_test.go index 4ae02240e..6fadc7d18 100644 --- a/internal/service/platform/connector/artifactory_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/artifactory_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/docker.go b/internal/service/cd_nextgen/connector/artifactRepositories/docker.go similarity index 99% rename from internal/service/platform/connector/docker.go rename to internal/service/cd_nextgen/connector/artifactRepositories/docker.go index f9a3ee5a5..d6ea37e36 100644 --- a/internal/service/platform/connector/docker.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/docker.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "context" diff --git a/internal/service/platform/connector/docker_data_source.go b/internal/service/cd_nextgen/connector/artifactRepositories/docker_data_source.go similarity index 98% rename from internal/service/platform/connector/docker_data_source.go rename to internal/service/cd_nextgen/connector/artifactRepositories/docker_data_source.go index 4ec28c4ab..37963fc96 100644 --- a/internal/service/platform/connector/docker_data_source.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/docker_data_source.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "fmt" diff --git a/internal/service/platform/connector/docker_data_source_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/docker_data_source_test.go similarity index 98% rename from internal/service/platform/connector/docker_data_source_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/docker_data_source_test.go index bbb19e8a7..8fb6143d7 100644 --- a/internal/service/platform/connector/docker_data_source_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/docker_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/docker_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/docker_test.go similarity index 99% rename from internal/service/platform/connector/docker_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/docker_test.go index 6af266d80..b7c195453 100644 --- a/internal/service/platform/connector/docker_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/docker_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/http_helm.go b/internal/service/cd_nextgen/connector/artifactRepositories/http_helm.go similarity index 99% rename from internal/service/platform/connector/http_helm.go rename to internal/service/cd_nextgen/connector/artifactRepositories/http_helm.go index c007d4224..103abfc5e 100644 --- a/internal/service/platform/connector/http_helm.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/http_helm.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "context" diff --git a/internal/service/platform/connector/http_helm_data_source.go b/internal/service/cd_nextgen/connector/artifactRepositories/http_helm_data_source.go similarity index 98% rename from internal/service/platform/connector/http_helm_data_source.go rename to internal/service/cd_nextgen/connector/artifactRepositories/http_helm_data_source.go index 3e3b040f7..7d5894b02 100644 --- a/internal/service/platform/connector/http_helm_data_source.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/http_helm_data_source.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/http_helm_data_source_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/http_helm_data_source_test.go similarity index 98% rename from internal/service/platform/connector/http_helm_data_source_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/http_helm_data_source_test.go index 25151041e..84b2410d4 100644 --- a/internal/service/platform/connector/http_helm_data_source_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/http_helm_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/http_helm_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/http_helm_test.go similarity index 92% rename from internal/service/platform/connector/http_helm_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/http_helm_test.go index 3f105a6bc..e0e6e5d3c 100644 --- a/internal/service/platform/connector/http_helm_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/http_helm_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" @@ -95,6 +95,7 @@ func TestAccResourceConnector_httphelm_UsernameRefPassword(t *testing.T) { id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id resourceName := "harness_platform_connector_helm.test" + secret := fmt.Sprintf("%s_secret", id) resource.UnitTest(t, resource.TestCase{ PreCheck: func() { acctest.TestAccPreCheck(t) }, @@ -114,7 +115,7 @@ func TestAccResourceConnector_httphelm_UsernameRefPassword(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "tags.#", "1"), resource.TestCheckResourceAttr(resourceName, "url", "https://helm.example.com"), resource.TestCheckResourceAttr(resourceName, "delegate_selectors.#", "1"), - resource.TestCheckResourceAttr(resourceName, "credentials.0.username_ref", "account.TestAccResourceConnector_httphelm_UsernamePassword__a8NH"), + resource.TestCheckResourceAttr(resourceName, "credentials.0.username_ref", "account."+secret), ), }, { @@ -194,14 +195,15 @@ func testAccResourceConnector_httphelm_usernamepassword(id string, name string) depends_on = [harness_platform_secret_text.test] destroy_duration = "4s" } + `, id, name) } func testAccResourceConnector_httphelm_usernameRefpassword(id string, name string) string { return fmt.Sprintf(` resource "harness_platform_secret_text" "test" { - identifier = "%[1]s" - name = "%[2]s" + identifier = "%[1]s_secret" + name = "%[2]s_secret" description = "test" tags = ["foo:bar"] @@ -211,23 +213,20 @@ func testAccResourceConnector_httphelm_usernameRefpassword(id string, name strin } resource "harness_platform_connector_helm" "test" { - identifier = "%[1]s" - name = "%[2]s" - description = "test" - tags = ["foo:bar"] - - url = "https://helm.example.com" - delegate_selectors = ["harness-delegate"] - credentials { - username_ref = "account.TestAccResourceConnector_httphelm_UsernamePassword__a8NH" - password_ref = "account.${harness_platform_secret_text.test.id}" - } - depends_on = [time_sleep.wait_4_seconds] - } - - resource "time_sleep" "wait_4_seconds" { - depends_on = [harness_platform_secret_text.test] - destroy_duration = "4s" + identifier = "%[1]s" + name = "%[2]s" + description = "test" + tags = ["foo:bar"] + + url = "https://helm.example.com" + delegate_selectors = ["harness-delegate"] + + credentials { + username_ref = "account.${harness_platform_secret_text.test.id}" + password_ref = "account.${harness_platform_secret_text.test.id}" + } + + depends_on = [harness_platform_secret_text.test] } `, id, name) } diff --git a/internal/service/platform/connector/jenkins.go b/internal/service/cd_nextgen/connector/artifactRepositories/jenkins.go similarity index 99% rename from internal/service/platform/connector/jenkins.go rename to internal/service/cd_nextgen/connector/artifactRepositories/jenkins.go index e37530950..1ef0d6aea 100644 --- a/internal/service/platform/connector/jenkins.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/jenkins.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "context" diff --git a/internal/service/platform/connector/jenkins_data_source.go b/internal/service/cd_nextgen/connector/artifactRepositories/jenkins_data_source.go similarity index 99% rename from internal/service/platform/connector/jenkins_data_source.go rename to internal/service/cd_nextgen/connector/artifactRepositories/jenkins_data_source.go index 3c542eaf9..763c7c232 100644 --- a/internal/service/platform/connector/jenkins_data_source.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/jenkins_data_source.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "context" diff --git a/internal/service/platform/connector/jenkins_data_source_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/jenkins_data_source_test.go similarity index 98% rename from internal/service/platform/connector/jenkins_data_source_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/jenkins_data_source_test.go index da8cb1d6f..df0207856 100644 --- a/internal/service/platform/connector/jenkins_data_source_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/jenkins_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/jenkins_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/jenkins_test.go similarity index 99% rename from internal/service/platform/connector/jenkins_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/jenkins_test.go index 71b44f5ab..66d01234f 100644 --- a/internal/service/platform/connector/jenkins_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/jenkins_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/nexus.go b/internal/service/cd_nextgen/connector/artifactRepositories/nexus.go similarity index 99% rename from internal/service/platform/connector/nexus.go rename to internal/service/cd_nextgen/connector/artifactRepositories/nexus.go index 128c1fff1..9d3b3b897 100644 --- a/internal/service/platform/connector/nexus.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/nexus.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "context" diff --git a/internal/service/platform/connector/nexus_data_source.go b/internal/service/cd_nextgen/connector/artifactRepositories/nexus_data_source.go similarity index 98% rename from internal/service/platform/connector/nexus_data_source.go rename to internal/service/cd_nextgen/connector/artifactRepositories/nexus_data_source.go index 6460ded05..396aeb33a 100644 --- a/internal/service/platform/connector/nexus_data_source.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/nexus_data_source.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "fmt" diff --git a/internal/service/platform/connector/nexus_data_source_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/nexus_data_source_test.go similarity index 98% rename from internal/service/platform/connector/nexus_data_source_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/nexus_data_source_test.go index d402be3ea..8f20eba80 100644 --- a/internal/service/platform/connector/nexus_data_source_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/nexus_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/nexus_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/nexus_test.go similarity index 99% rename from internal/service/platform/connector/nexus_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/nexus_test.go index edb444b42..757ab3ea6 100644 --- a/internal/service/platform/connector/nexus_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/nexus_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/oci_helm.go b/internal/service/cd_nextgen/connector/artifactRepositories/oci_helm.go similarity index 99% rename from internal/service/platform/connector/oci_helm.go rename to internal/service/cd_nextgen/connector/artifactRepositories/oci_helm.go index d5018ee4d..4b5e9aaf6 100644 --- a/internal/service/platform/connector/oci_helm.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/oci_helm.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "context" diff --git a/internal/service/platform/connector/oci_helm_data_source.go b/internal/service/cd_nextgen/connector/artifactRepositories/oci_helm_data_source.go similarity index 98% rename from internal/service/platform/connector/oci_helm_data_source.go rename to internal/service/cd_nextgen/connector/artifactRepositories/oci_helm_data_source.go index 50e2312cb..de9a544b0 100644 --- a/internal/service/platform/connector/oci_helm_data_source.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/oci_helm_data_source.go @@ -1,4 +1,4 @@ -package connector +package artifactRepositories import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/oci_helm_data_source_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/oci_helm_data_source_test.go similarity index 98% rename from internal/service/platform/connector/oci_helm_data_source_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/oci_helm_data_source_test.go index 588a98226..def8272f4 100644 --- a/internal/service/platform/connector/oci_helm_data_source_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/oci_helm_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/oci_helm_test.go b/internal/service/cd_nextgen/connector/artifactRepositories/oci_helm_test.go similarity index 99% rename from internal/service/platform/connector/oci_helm_test.go rename to internal/service/cd_nextgen/connector/artifactRepositories/oci_helm_test.go index d440f5f09..b7b4ed9bf 100644 --- a/internal/service/platform/connector/oci_helm_test.go +++ b/internal/service/cd_nextgen/connector/artifactRepositories/oci_helm_test.go @@ -1,4 +1,4 @@ -package connector_test +package artifactRepositories_test import ( "fmt" diff --git a/internal/service/cd_nextgen/connector/artifactRepositories/secret_util.go b/internal/service/cd_nextgen/connector/artifactRepositories/secret_util.go new file mode 100644 index 000000000..d2aa946d2 --- /dev/null +++ b/internal/service/cd_nextgen/connector/artifactRepositories/secret_util.go @@ -0,0 +1,3 @@ +package artifactRepositories + +const secret_ref_text = " To reference a secret at the organization scope, prefix 'org' to the expression: org.{identifier}. To reference a secret at the account scope, prefix 'account` to the expression: account.{identifier}." diff --git a/internal/service/platform/connector/aws.go b/internal/service/cd_nextgen/connector/cloudProviders/aws.go similarity index 99% rename from internal/service/platform/connector/aws.go rename to internal/service/cd_nextgen/connector/cloudProviders/aws.go index 9d87b26a8..3c8f47666 100644 --- a/internal/service/platform/connector/aws.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/aws.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "context" diff --git a/internal/service/platform/connector/aws_data_source.go b/internal/service/cd_nextgen/connector/cloudProviders/aws_data_source.go similarity index 99% rename from internal/service/platform/connector/aws_data_source.go rename to internal/service/cd_nextgen/connector/cloudProviders/aws_data_source.go index d57febba6..891ae1140 100644 --- a/internal/service/platform/connector/aws_data_source.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/aws_data_source.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/aws_data_source_test.go b/internal/service/cd_nextgen/connector/cloudProviders/aws_data_source_test.go similarity index 99% rename from internal/service/platform/connector/aws_data_source_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/aws_data_source_test.go index beb3756ee..e3dea1995 100644 --- a/internal/service/platform/connector/aws_data_source_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/aws_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/aws_test.go b/internal/service/cd_nextgen/connector/cloudProviders/aws_test.go similarity index 99% rename from internal/service/platform/connector/aws_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/aws_test.go index 28b4ce276..7bee4eca8 100644 --- a/internal/service/platform/connector/aws_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/aws_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/azure_cloud_provider.go b/internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider.go similarity index 99% rename from internal/service/platform/connector/azure_cloud_provider.go rename to internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider.go index 0fbbe0a42..ef2be0a7a 100644 --- a/internal/service/platform/connector/azure_cloud_provider.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "context" diff --git a/internal/service/platform/connector/azure_cloud_provider_data_source.go b/internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider_data_source.go similarity index 99% rename from internal/service/platform/connector/azure_cloud_provider_data_source.go rename to internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider_data_source.go index 2b070ff98..7ddf32c46 100644 --- a/internal/service/platform/connector/azure_cloud_provider_data_source.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider_data_source.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/azure_cloud_provider_data_source_test.go b/internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider_data_source_test.go similarity index 98% rename from internal/service/platform/connector/azure_cloud_provider_data_source_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider_data_source_test.go index 45f9a6489..df5106afc 100644 --- a/internal/service/platform/connector/azure_cloud_provider_data_source_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/azure_cloud_provider_test.go b/internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider_test.go similarity index 99% rename from internal/service/platform/connector/azure_cloud_provider_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider_test.go index c522cdae8..b741876a4 100644 --- a/internal/service/platform/connector/azure_cloud_provider_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/azure_cloud_provider_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/cd_nextgen/connector/cloudProviders/cloudProviders.go b/internal/service/cd_nextgen/connector/cloudProviders/cloudProviders.go new file mode 100644 index 000000000..b0e4030e8 --- /dev/null +++ b/internal/service/cd_nextgen/connector/cloudProviders/cloudProviders.go @@ -0,0 +1,156 @@ +package cloudProviders + +import ( + "context" + "fmt" + "net/http" + + "github.com/antihax/optional" + "github.com/harness/harness-go-sdk/harness/nextgen" + "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" +) + +type ReadConnectorData func(*schema.ResourceData, *nextgen.ConnectorInfo) error + +func resourceConnectorReadBase(ctx context.Context, d *schema.ResourceData, meta interface{}, connType nextgen.ConnectorType) (*nextgen.ConnectorInfo, diag.Diagnostics) { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + id := d.Id() + if id == "" { + id = d.Get("identifier").(string) + } + + resp, httpResp, err := c.ConnectorsApi.GetConnector(ctx, c.AccountId, id, getReadConnectorOpts(d)) + if err != nil { + return nil, helpers.HandleReadApiError(err, d, httpResp) + } + + if connType != resp.Data.Connector.Type_ { + return nil, diag.FromErr(fmt.Errorf("expected connector to be of type %s, but got %s", connType, resp.Data.Connector.Type_)) + } + + readCommonConnectorData(d, resp.Data.Connector) + + return resp.Data.Connector, nil +} + +func dataConnectorReadBase(ctx context.Context, d *schema.ResourceData, meta interface{}, connType nextgen.ConnectorType) (*nextgen.ConnectorInfo, diag.Diagnostics) { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + id := d.Id() + if id == "" { + id = d.Get("identifier").(string) + } + + resp, httpResp, err := c.ConnectorsApi.GetConnector(ctx, c.AccountId, id, getReadConnectorOpts(d)) + if err != nil { + return nil, helpers.HandleApiError(err, d, httpResp) + } + + if connType != resp.Data.Connector.Type_ { + return nil, diag.FromErr(fmt.Errorf("expected connector to be of type %s, but got %s", connType, resp.Data.Connector.Type_)) + } + + readCommonConnectorData(d, resp.Data.Connector) + + return resp.Data.Connector, nil +} + +func getReadConnectorOpts(d *schema.ResourceData) *nextgen.ConnectorsApiGetConnectorOpts { + connOpts := &nextgen.ConnectorsApiGetConnectorOpts{} + + if attr, ok := d.GetOk("org_id"); ok { + connOpts.OrgIdentifier = optional.NewString(attr.(string)) + } + + if attr, ok := d.GetOk("project_id"); ok { + connOpts.ProjectIdentifier = optional.NewString(attr.(string)) + } + + if attr, ok := d.GetOk("git_sync"); ok { + opts := attr.([]interface{})[0].(map[string]interface{}) + connOpts.Branch = optional.NewString(opts["branch"].(string)) + connOpts.RepoIdentifier = optional.NewString(opts["repo_id"].(string)) + } + + return connOpts +} + +func resourceConnectorCreateOrUpdateBase(ctx context.Context, d *schema.ResourceData, meta interface{}, connector *nextgen.ConnectorInfo) (*nextgen.ConnectorInfo, diag.Diagnostics) { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + id := d.Id() + buildConnector(d, connector) + + var err error + var resp nextgen.ResponseDtoConnectorResponse + var httpResp *http.Response + + if id == "" { + resp, httpResp, err = c.ConnectorsApi.CreateConnector(ctx, nextgen.Connector{Connector: connector}, c.AccountId, &nextgen.ConnectorsApiCreateConnectorOpts{}) + } else { + resp, httpResp, err = c.ConnectorsApi.UpdateConnector(ctx, nextgen.Connector{Connector: connector}, c.AccountId, &nextgen.ConnectorsApiUpdateConnectorOpts{}) + } + + if err != nil { + return nil, helpers.HandleApiError(err, d, httpResp) + } + + readCommonConnectorData(d, resp.Data.Connector) + + return resp.Data.Connector, nil +} + +func resourceConnectorDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + _, httpResp, err := c.ConnectorsApi.DeleteConnector(ctx, c.AccountId, d.Id(), &nextgen.ConnectorsApiDeleteConnectorOpts{ + OrgIdentifier: helpers.BuildField(d, "org_id"), + ProjectIdentifier: helpers.BuildField(d, "project_id"), + ForceDelete: helpers.BuildFieldBool(d, "force_delete")}) + + if err != nil { + return helpers.HandleApiError(err, d, httpResp) + } + + return nil +} + +func buildConnector(d *schema.ResourceData, connector *nextgen.ConnectorInfo) { + if attr := d.Get("name").(string); attr != "" { + connector.Name = attr + } + + if attr := d.Get("identifier").(string); attr != "" { + connector.Identifier = attr + } + + if attr := d.Get("description").(string); attr != "" { + connector.Description = attr + } + + if attr := d.Get("org_id").(string); attr != "" { + connector.OrgIdentifier = attr + } + + if attr := d.Get("project_id").(string); attr != "" { + connector.ProjectIdentifier = attr + } + + if attr := d.Get("tags").(*schema.Set).List(); len(attr) > 0 { + connector.Tags = helpers.ExpandTags(attr) + } +} + +func readCommonConnectorData(d *schema.ResourceData, connector *nextgen.ConnectorInfo) { + d.SetId(connector.Identifier) + d.Set("identifier", connector.Identifier) + d.Set("description", connector.Description) + d.Set("name", connector.Name) + d.Set("org_id", connector.OrgIdentifier) + d.Set("project_id", connector.ProjectIdentifier) + d.Set("tags", helpers.FlattenTags(connector.Tags)) +} diff --git a/internal/service/cd_nextgen/connector/cloudProviders/cloudProviders_test.go b/internal/service/cd_nextgen/connector/cloudProviders/cloudProviders_test.go new file mode 100644 index 000000000..503b499b7 --- /dev/null +++ b/internal/service/cd_nextgen/connector/cloudProviders/cloudProviders_test.go @@ -0,0 +1,57 @@ +package cloudProviders_test + +import ( + "fmt" + + "github.com/antihax/optional" + "github.com/harness/harness-go-sdk/harness/nextgen" + "github.com/harness/terraform-provider-harness/internal/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func testAccConnectorDestroy(resourceName string) resource.TestCheckFunc { + return func(state *terraform.State) error { + connector, _ := testAccGetConnector(resourceName, state) + if connector != nil { + return fmt.Errorf("Found connector: %s", connector.Identifier) + } + + return nil + } +} + +func testAccGetConnector(resourceName string, state *terraform.State) (*nextgen.ConnectorInfo, error) { + r := acctest.TestAccGetResource(resourceName, state) + c, ctx := acctest.TestAccGetPlatformClientWithContext() + id := r.Primary.ID + + options := &nextgen.ConnectorsApiGetConnectorOpts{} + + if attr := r.Primary.Attributes["org_id"]; attr != "" { + options.OrgIdentifier = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["project_id"]; attr != "" { + options.ProjectIdentifier = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["branch"]; attr != "" { + options.Branch = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["repo_id"]; attr != "" { + options.RepoIdentifier = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["repo_id"]; attr != "" { + options.RepoIdentifier = optional.NewString(attr) + } + + resp, _, err := c.ConnectorsApi.GetConnector(ctx, c.AccountId, id, options) + if err != nil { + return nil, err + } + + return resp.Data.Connector, nil +} diff --git a/internal/service/platform/connector/gcp.go b/internal/service/cd_nextgen/connector/cloudProviders/gcp.go similarity index 99% rename from internal/service/platform/connector/gcp.go rename to internal/service/cd_nextgen/connector/cloudProviders/gcp.go index 32f382277..a0419b17d 100644 --- a/internal/service/platform/connector/gcp.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/gcp.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "context" diff --git a/internal/service/platform/connector/gcp_data_source.go b/internal/service/cd_nextgen/connector/cloudProviders/gcp_data_source.go similarity index 99% rename from internal/service/platform/connector/gcp_data_source.go rename to internal/service/cd_nextgen/connector/cloudProviders/gcp_data_source.go index 745bdb242..c72afd073 100644 --- a/internal/service/platform/connector/gcp_data_source.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/gcp_data_source.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/gcp_data_source_test.go b/internal/service/cd_nextgen/connector/cloudProviders/gcp_data_source_test.go similarity index 99% rename from internal/service/platform/connector/gcp_data_source_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/gcp_data_source_test.go index 9aecef397..a6374b098 100644 --- a/internal/service/platform/connector/gcp_data_source_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/gcp_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/gcp_test.go b/internal/service/cd_nextgen/connector/cloudProviders/gcp_test.go similarity index 99% rename from internal/service/platform/connector/gcp_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/gcp_test.go index 1374b80aa..1dad7a63b 100644 --- a/internal/service/platform/connector/gcp_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/gcp_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" @@ -75,6 +75,7 @@ func TestAccResourceConnectorGcp_Manual(t *testing.T) { } func TestAccResourceConnectorGcp_OIDC(t *testing.T) { + t.Skip() id := fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(5)) name := id diff --git a/internal/service/platform/connector/k8s_cluster.go b/internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster.go similarity index 99% rename from internal/service/platform/connector/k8s_cluster.go rename to internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster.go index 4030764bc..a7570766b 100644 --- a/internal/service/platform/connector/k8s_cluster.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "context" diff --git a/internal/service/platform/connector/k8s_cluster_data_source.go b/internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster_data_source.go similarity index 99% rename from internal/service/platform/connector/k8s_cluster_data_source.go rename to internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster_data_source.go index 3b0121ed0..e105e13f2 100644 --- a/internal/service/platform/connector/k8s_cluster_data_source.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster_data_source.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "fmt" diff --git a/internal/service/platform/connector/k8s_cluster_data_source_test.go b/internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster_data_source_test.go similarity index 99% rename from internal/service/platform/connector/k8s_cluster_data_source_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster_data_source_test.go index c6d88b8b2..f29d97cf9 100644 --- a/internal/service/platform/connector/k8s_cluster_data_source_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/k8s_cluster_test.go b/internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster_test.go similarity index 99% rename from internal/service/platform/connector/k8s_cluster_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster_test.go index 0330a3f7b..445aa5d91 100644 --- a/internal/service/platform/connector/k8s_cluster_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/k8s_cluster_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/k8s_rancher.go b/internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher.go similarity index 99% rename from internal/service/platform/connector/k8s_rancher.go rename to internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher.go index a29b68588..cb19b2f1c 100644 --- a/internal/service/platform/connector/k8s_rancher.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "context" diff --git a/internal/service/platform/connector/k8s_rancher_data_source.go b/internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher_data_source.go similarity index 98% rename from internal/service/platform/connector/k8s_rancher_data_source.go rename to internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher_data_source.go index 6059456c0..471fed670 100644 --- a/internal/service/platform/connector/k8s_rancher_data_source.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher_data_source.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/k8s_rancher_data_source_test.go b/internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher_data_source_test.go similarity index 98% rename from internal/service/platform/connector/k8s_rancher_data_source_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher_data_source_test.go index 58135546f..425563ee8 100644 --- a/internal/service/platform/connector/k8s_rancher_data_source_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/k8s_rancher_test.go b/internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher_test.go similarity index 99% rename from internal/service/platform/connector/k8s_rancher_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher_test.go index aa3c6218f..dbfe03450 100644 --- a/internal/service/platform/connector/k8s_rancher_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/k8s_rancher_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/pdc.go b/internal/service/cd_nextgen/connector/cloudProviders/pdc.go similarity index 99% rename from internal/service/platform/connector/pdc.go rename to internal/service/cd_nextgen/connector/cloudProviders/pdc.go index 69962061f..b76e64f44 100644 --- a/internal/service/platform/connector/pdc.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/pdc.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "context" diff --git a/internal/service/platform/connector/pdc_data_source.go b/internal/service/cd_nextgen/connector/cloudProviders/pdc_data_source.go similarity index 98% rename from internal/service/platform/connector/pdc_data_source.go rename to internal/service/cd_nextgen/connector/cloudProviders/pdc_data_source.go index 30c055593..fc14d6353 100644 --- a/internal/service/platform/connector/pdc_data_source.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/pdc_data_source.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/pdc_data_source_test.go b/internal/service/cd_nextgen/connector/cloudProviders/pdc_data_source_test.go similarity index 98% rename from internal/service/platform/connector/pdc_data_source_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/pdc_data_source_test.go index c0d25d205..80b698878 100644 --- a/internal/service/platform/connector/pdc_data_source_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/pdc_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/pdc_test.go b/internal/service/cd_nextgen/connector/cloudProviders/pdc_test.go similarity index 99% rename from internal/service/platform/connector/pdc_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/pdc_test.go index 96b1643e1..9ed2b401e 100644 --- a/internal/service/platform/connector/pdc_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/pdc_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/cd_nextgen/connector/cloudProviders/secret_util.go b/internal/service/cd_nextgen/connector/cloudProviders/secret_util.go new file mode 100644 index 000000000..8c9eddef5 --- /dev/null +++ b/internal/service/cd_nextgen/connector/cloudProviders/secret_util.go @@ -0,0 +1,3 @@ +package cloudProviders + +const secret_ref_text = " To reference a secret at the organization scope, prefix 'org' to the expression: org.{identifier}. To reference a secret at the account scope, prefix 'account` to the expression: account.{identifier}." diff --git a/internal/service/platform/connector/spot.go b/internal/service/cd_nextgen/connector/cloudProviders/spot.go similarity index 99% rename from internal/service/platform/connector/spot.go rename to internal/service/cd_nextgen/connector/cloudProviders/spot.go index f9209b2c1..e9c7b9204 100644 --- a/internal/service/platform/connector/spot.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/spot.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "context" diff --git a/internal/service/platform/connector/spot_data_source.go b/internal/service/cd_nextgen/connector/cloudProviders/spot_data_source.go similarity index 98% rename from internal/service/platform/connector/spot_data_source.go rename to internal/service/cd_nextgen/connector/cloudProviders/spot_data_source.go index e70e88945..ac4cad9ec 100644 --- a/internal/service/platform/connector/spot_data_source.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/spot_data_source.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/spot_data_source_test.go b/internal/service/cd_nextgen/connector/cloudProviders/spot_data_source_test.go similarity index 98% rename from internal/service/platform/connector/spot_data_source_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/spot_data_source_test.go index f53a7aaef..1d7fa8f49 100644 --- a/internal/service/platform/connector/spot_data_source_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/spot_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/spot_test.go b/internal/service/cd_nextgen/connector/cloudProviders/spot_test.go similarity index 99% rename from internal/service/platform/connector/spot_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/spot_test.go index feb9b664e..a35ca7359 100644 --- a/internal/service/platform/connector/spot_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/spot_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/tas.go b/internal/service/cd_nextgen/connector/cloudProviders/tas.go similarity index 99% rename from internal/service/platform/connector/tas.go rename to internal/service/cd_nextgen/connector/cloudProviders/tas.go index 15b6736a7..267e36e22 100644 --- a/internal/service/platform/connector/tas.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/tas.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "context" diff --git a/internal/service/platform/connector/tas_data_source.go b/internal/service/cd_nextgen/connector/cloudProviders/tas_data_source.go similarity index 98% rename from internal/service/platform/connector/tas_data_source.go rename to internal/service/cd_nextgen/connector/cloudProviders/tas_data_source.go index 9494058e1..64dad2699 100644 --- a/internal/service/platform/connector/tas_data_source.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/tas_data_source.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/tas_data_source_test.go b/internal/service/cd_nextgen/connector/cloudProviders/tas_data_source_test.go similarity index 98% rename from internal/service/platform/connector/tas_data_source_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/tas_data_source_test.go index e1f58da28..27f8df3cd 100644 --- a/internal/service/platform/connector/tas_data_source_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/tas_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" @@ -10,6 +10,7 @@ import ( ) func TestAccDataSourceConnectorTas(t *testing.T) { + t.Skip() var ( name = fmt.Sprintf("%s_%s", t.Name(), utils.RandStringBytes(4)) diff --git a/internal/service/platform/connector/tas_test.go b/internal/service/cd_nextgen/connector/cloudProviders/tas_test.go similarity index 99% rename from internal/service/platform/connector/tas_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/tas_test.go index 48d100889..9b750dd42 100644 --- a/internal/service/platform/connector/tas_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/tas_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/terraform_cloud.go b/internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud.go similarity index 99% rename from internal/service/platform/connector/terraform_cloud.go rename to internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud.go index c4af38849..3bee6ff35 100644 --- a/internal/service/platform/connector/terraform_cloud.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "context" diff --git a/internal/service/platform/connector/terraform_cloud_data_source.go b/internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud_data_source.go similarity index 98% rename from internal/service/platform/connector/terraform_cloud_data_source.go rename to internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud_data_source.go index f789bca21..a627178c3 100644 --- a/internal/service/platform/connector/terraform_cloud_data_source.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud_data_source.go @@ -1,4 +1,4 @@ -package connector +package cloudProviders import ( "github.com/harness/terraform-provider-harness/helpers" diff --git a/internal/service/platform/connector/terraform_cloud_data_source_test.go b/internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud_data_source_test.go similarity index 98% rename from internal/service/platform/connector/terraform_cloud_data_source_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud_data_source_test.go index e4c05fb23..9ba7088e6 100644 --- a/internal/service/platform/connector/terraform_cloud_data_source_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/terraform_cloud_test.go b/internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud_test.go similarity index 99% rename from internal/service/platform/connector/terraform_cloud_test.go rename to internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud_test.go index 3c819863d..d5147caef 100644 --- a/internal/service/platform/connector/terraform_cloud_test.go +++ b/internal/service/cd_nextgen/connector/cloudProviders/terraform_cloud_test.go @@ -1,4 +1,4 @@ -package connector_test +package cloudProviders_test import ( "fmt" diff --git a/internal/service/platform/connector/bitbucket.go b/internal/service/cd_nextgen/connector/codeRepositories/bitbucket.go similarity index 97% rename from internal/service/platform/connector/bitbucket.go rename to internal/service/cd_nextgen/connector/codeRepositories/bitbucket.go index 9f9033139..6cfe71276 100644 --- a/internal/service/platform/connector/bitbucket.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/bitbucket.go @@ -1,4 +1,4 @@ -package connector +package codeRepositories import ( "context" @@ -60,14 +60,14 @@ func ResourceConnectorBitbucket() *schema.Resource { AtLeastOneOf: []string{"api_authentication.0.username", "api_authentication.0.username_ref"}, }, "username_ref": { - Description: "The name of the Harness secret containing the username." + secret_ref_text, + Description: "The name of the Harness secret containing the username." + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"api_authentication.0.username"}, AtLeastOneOf: []string{"api_authentication.0.username", "api_authentication.0.username_ref"}, }, "token_ref": { - Description: "Personal access token for interacting with the BitBucket api." + secret_ref_text, + Description: "Personal access token for interacting with the BitBucket api." + secretRefText, Type: schema.TypeString, Required: true, }, @@ -98,14 +98,14 @@ func ResourceConnectorBitbucket() *schema.Resource { ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref"}, }, "username_ref": { - Description: "Reference to a secret containing the username to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the username to use for authentication." + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.username"}, ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref"}, }, "password_ref": { - Description: "Reference to a secret containing the password to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the password to use for authentication." + secretRefText, Type: schema.TypeString, Optional: true, }, @@ -122,7 +122,7 @@ func ResourceConnectorBitbucket() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "ssh_key_ref": { - Description: "Reference to the Harness secret containing the ssh key." + secret_ref_text, + Description: "Reference to the Harness secret containing the ssh key." + secretRefText, Type: schema.TypeString, Required: true, }, diff --git a/internal/service/platform/connector/bitbucket_data_source.go b/internal/service/cd_nextgen/connector/codeRepositories/bitbucket_data_source.go similarity index 94% rename from internal/service/platform/connector/bitbucket_data_source.go rename to internal/service/cd_nextgen/connector/codeRepositories/bitbucket_data_source.go index b0c2b3954..8f7ba0fd4 100644 --- a/internal/service/platform/connector/bitbucket_data_source.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/bitbucket_data_source.go @@ -1,4 +1,4 @@ -package connector +package codeRepositories import ( "fmt" @@ -48,12 +48,12 @@ func DatasourceConnectorBitbucket() *schema.Resource { Computed: true, }, "username_ref": { - Description: "The name of the Harness secret containing the username." + secret_ref_text, + Description: "The name of the Harness secret containing the username." + secretRefText, Type: schema.TypeString, Computed: true, }, "token_ref": { - Description: "Personal access token for interacting with the BitBucket api." + secret_ref_text, + Description: "Personal access token for interacting with the BitBucket api." + secretRefText, Type: schema.TypeString, Computed: true, }, @@ -78,12 +78,12 @@ func DatasourceConnectorBitbucket() *schema.Resource { Computed: true, }, "username_ref": { - Description: "Reference to a secret containing the username to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the username to use for authentication." + secretRefText, Type: schema.TypeString, Computed: true, }, "password_ref": { - Description: "Reference to a secret containing the password to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the password to use for authentication." + secretRefText, Type: schema.TypeString, Computed: true, }, @@ -97,7 +97,7 @@ func DatasourceConnectorBitbucket() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "ssh_key_ref": { - Description: "Reference to the Harness secret containing the ssh key." + secret_ref_text, + Description: "Reference to the Harness secret containing the ssh key." + secretRefText, Type: schema.TypeString, Computed: true, }, diff --git a/internal/service/platform/connector/bitbucket_data_source_test.go b/internal/service/cd_nextgen/connector/codeRepositories/bitbucket_data_source_test.go similarity index 98% rename from internal/service/platform/connector/bitbucket_data_source_test.go rename to internal/service/cd_nextgen/connector/codeRepositories/bitbucket_data_source_test.go index dd07ec800..352d56999 100644 --- a/internal/service/platform/connector/bitbucket_data_source_test.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/bitbucket_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package codeRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/bitbucket_test.go b/internal/service/cd_nextgen/connector/codeRepositories/bitbucket_test.go similarity index 99% rename from internal/service/platform/connector/bitbucket_test.go rename to internal/service/cd_nextgen/connector/codeRepositories/bitbucket_test.go index 9faba07d7..12e466e42 100644 --- a/internal/service/platform/connector/bitbucket_test.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/bitbucket_test.go @@ -1,4 +1,4 @@ -package connector_test +package codeRepositories_test import ( "fmt" diff --git a/internal/service/cd_nextgen/connector/codeRepositories/codeRepositories.go b/internal/service/cd_nextgen/connector/codeRepositories/codeRepositories.go new file mode 100644 index 000000000..1ebb98a98 --- /dev/null +++ b/internal/service/cd_nextgen/connector/codeRepositories/codeRepositories.go @@ -0,0 +1,156 @@ +package codeRepositories + +import ( + "context" + "fmt" + "net/http" + + "github.com/antihax/optional" + "github.com/harness/harness-go-sdk/harness/nextgen" + "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" +) + +type ReadConnectorData func(*schema.ResourceData, *nextgen.ConnectorInfo) error + +func resourceConnectorReadBase(ctx context.Context, d *schema.ResourceData, meta interface{}, connType nextgen.ConnectorType) (*nextgen.ConnectorInfo, diag.Diagnostics) { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + id := d.Id() + if id == "" { + id = d.Get("identifier").(string) + } + + resp, httpResp, err := c.ConnectorsApi.GetConnector(ctx, c.AccountId, id, getReadConnectorOpts(d)) + if err != nil { + return nil, helpers.HandleReadApiError(err, d, httpResp) + } + + if connType != resp.Data.Connector.Type_ { + return nil, diag.FromErr(fmt.Errorf("expected connector to be of type %s, but got %s", connType, resp.Data.Connector.Type_)) + } + + readCommonConnectorData(d, resp.Data.Connector) + + return resp.Data.Connector, nil +} + +func dataConnectorReadBase(ctx context.Context, d *schema.ResourceData, meta interface{}, connType nextgen.ConnectorType) (*nextgen.ConnectorInfo, diag.Diagnostics) { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + id := d.Id() + if id == "" { + id = d.Get("identifier").(string) + } + + resp, httpResp, err := c.ConnectorsApi.GetConnector(ctx, c.AccountId, id, getReadConnectorOpts(d)) + if err != nil { + return nil, helpers.HandleApiError(err, d, httpResp) + } + + if connType != resp.Data.Connector.Type_ { + return nil, diag.FromErr(fmt.Errorf("expected connector to be of type %s, but got %s", connType, resp.Data.Connector.Type_)) + } + + readCommonConnectorData(d, resp.Data.Connector) + + return resp.Data.Connector, nil +} + +func getReadConnectorOpts(d *schema.ResourceData) *nextgen.ConnectorsApiGetConnectorOpts { + connOpts := &nextgen.ConnectorsApiGetConnectorOpts{} + + if attr, ok := d.GetOk("org_id"); ok { + connOpts.OrgIdentifier = optional.NewString(attr.(string)) + } + + if attr, ok := d.GetOk("project_id"); ok { + connOpts.ProjectIdentifier = optional.NewString(attr.(string)) + } + + if attr, ok := d.GetOk("git_sync"); ok { + opts := attr.([]interface{})[0].(map[string]interface{}) + connOpts.Branch = optional.NewString(opts["branch"].(string)) + connOpts.RepoIdentifier = optional.NewString(opts["repo_id"].(string)) + } + + return connOpts +} + +func resourceConnectorCreateOrUpdateBase(ctx context.Context, d *schema.ResourceData, meta interface{}, connector *nextgen.ConnectorInfo) (*nextgen.ConnectorInfo, diag.Diagnostics) { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + id := d.Id() + buildConnector(d, connector) + + var err error + var resp nextgen.ResponseDtoConnectorResponse + var httpResp *http.Response + + if id == "" { + resp, httpResp, err = c.ConnectorsApi.CreateConnector(ctx, nextgen.Connector{Connector: connector}, c.AccountId, &nextgen.ConnectorsApiCreateConnectorOpts{}) + } else { + resp, httpResp, err = c.ConnectorsApi.UpdateConnector(ctx, nextgen.Connector{Connector: connector}, c.AccountId, &nextgen.ConnectorsApiUpdateConnectorOpts{}) + } + + if err != nil { + return nil, helpers.HandleApiError(err, d, httpResp) + } + + readCommonConnectorData(d, resp.Data.Connector) + + return resp.Data.Connector, nil +} + +func resourceConnectorDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx) + + _, httpResp, err := c.ConnectorsApi.DeleteConnector(ctx, c.AccountId, d.Id(), &nextgen.ConnectorsApiDeleteConnectorOpts{ + OrgIdentifier: helpers.BuildField(d, "org_id"), + ProjectIdentifier: helpers.BuildField(d, "project_id"), + ForceDelete: helpers.BuildFieldBool(d, "force_delete")}) + + if err != nil { + return helpers.HandleApiError(err, d, httpResp) + } + + return nil +} + +func buildConnector(d *schema.ResourceData, connector *nextgen.ConnectorInfo) { + if attr := d.Get("name").(string); attr != "" { + connector.Name = attr + } + + if attr := d.Get("identifier").(string); attr != "" { + connector.Identifier = attr + } + + if attr := d.Get("description").(string); attr != "" { + connector.Description = attr + } + + if attr := d.Get("org_id").(string); attr != "" { + connector.OrgIdentifier = attr + } + + if attr := d.Get("project_id").(string); attr != "" { + connector.ProjectIdentifier = attr + } + + if attr := d.Get("tags").(*schema.Set).List(); len(attr) > 0 { + connector.Tags = helpers.ExpandTags(attr) + } +} + +func readCommonConnectorData(d *schema.ResourceData, connector *nextgen.ConnectorInfo) { + d.SetId(connector.Identifier) + d.Set("identifier", connector.Identifier) + d.Set("description", connector.Description) + d.Set("name", connector.Name) + d.Set("org_id", connector.OrgIdentifier) + d.Set("project_id", connector.ProjectIdentifier) + d.Set("tags", helpers.FlattenTags(connector.Tags)) +} diff --git a/internal/service/cd_nextgen/connector/codeRepositories/codeRepositories_test.go b/internal/service/cd_nextgen/connector/codeRepositories/codeRepositories_test.go new file mode 100644 index 000000000..6dacd5ef1 --- /dev/null +++ b/internal/service/cd_nextgen/connector/codeRepositories/codeRepositories_test.go @@ -0,0 +1,57 @@ +package codeRepositories_test + +import ( + "fmt" + + "github.com/antihax/optional" + "github.com/harness/harness-go-sdk/harness/nextgen" + "github.com/harness/terraform-provider-harness/internal/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" +) + +func testAccConnectorDestroy(resourceName string) resource.TestCheckFunc { + return func(state *terraform.State) error { + connector, _ := testAccGetConnector(resourceName, state) + if connector != nil { + return fmt.Errorf("Found connector: %s", connector.Identifier) + } + + return nil + } +} + +func testAccGetConnector(resourceName string, state *terraform.State) (*nextgen.ConnectorInfo, error) { + r := acctest.TestAccGetResource(resourceName, state) + c, ctx := acctest.TestAccGetPlatformClientWithContext() + id := r.Primary.ID + + options := &nextgen.ConnectorsApiGetConnectorOpts{} + + if attr := r.Primary.Attributes["org_id"]; attr != "" { + options.OrgIdentifier = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["project_id"]; attr != "" { + options.ProjectIdentifier = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["branch"]; attr != "" { + options.Branch = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["repo_id"]; attr != "" { + options.RepoIdentifier = optional.NewString(attr) + } + + if attr := r.Primary.Attributes["repo_id"]; attr != "" { + options.RepoIdentifier = optional.NewString(attr) + } + + resp, _, err := c.ConnectorsApi.GetConnector(ctx, c.AccountId, id, options) + if err != nil { + return nil, err + } + + return resp.Data.Connector, nil +} diff --git a/internal/service/platform/connector/git.go b/internal/service/cd_nextgen/connector/codeRepositories/git.go similarity index 97% rename from internal/service/platform/connector/git.go rename to internal/service/cd_nextgen/connector/codeRepositories/git.go index b13cddb20..748f3a0e8 100644 --- a/internal/service/platform/connector/git.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/git.go @@ -1,4 +1,4 @@ -package connector +package codeRepositories import ( "context" @@ -48,7 +48,7 @@ func ResourceConnectorGit() *schema.Resource { "execute_on_delegate": { Description: "Execute on delegate or not.", Type: schema.TypeBool, - Optional: true, + Optional: true, }, "credentials": { Description: "Credentials to use for the connection.", @@ -74,14 +74,14 @@ func ResourceConnectorGit() *schema.Resource { ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref"}, }, "username_ref": { - Description: "Reference to a secret containing the username to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the username to use for authentication." + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.username"}, ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref"}, }, "password_ref": { - Description: "Reference to a secret containing the password to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the password to use for authentication." + secretRefText, Type: schema.TypeString, Required: true, }, @@ -98,7 +98,7 @@ func ResourceConnectorGit() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "ssh_key_ref": { - Description: "Reference to the Harness secret containing the ssh key." + secret_ref_text, + Description: "Reference to the Harness secret containing the ssh key." + secretRefText, Type: schema.TypeString, Required: true, }, diff --git a/internal/service/platform/connector/git_data_source.go b/internal/service/cd_nextgen/connector/codeRepositories/git_data_source.go similarity index 94% rename from internal/service/platform/connector/git_data_source.go rename to internal/service/cd_nextgen/connector/codeRepositories/git_data_source.go index 0d5246ea6..f752eabf3 100644 --- a/internal/service/platform/connector/git_data_source.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/git_data_source.go @@ -1,4 +1,4 @@ -package connector +package codeRepositories import ( "fmt" @@ -54,12 +54,12 @@ func DatasourceConnectorGit() *schema.Resource { Computed: true, }, "username_ref": { - Description: "Reference to a secret containing the username to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the username to use for authentication." + secretRefText, Type: schema.TypeString, Computed: true, }, "password_ref": { - Description: "Reference to a secret containing the password to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the password to use for authentication." + secretRefText, Type: schema.TypeString, Computed: true, }, @@ -73,7 +73,7 @@ func DatasourceConnectorGit() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "ssh_key_ref": { - Description: "Reference to the Harness secret containing the ssh key." + secret_ref_text, + Description: "Reference to the Harness secret containing the ssh key." + secretRefText, Type: schema.TypeString, Computed: true, }, diff --git a/internal/service/platform/connector/git_data_source_test.go b/internal/service/cd_nextgen/connector/codeRepositories/git_data_source_test.go similarity index 98% rename from internal/service/platform/connector/git_data_source_test.go rename to internal/service/cd_nextgen/connector/codeRepositories/git_data_source_test.go index c171300bb..ca0041219 100644 --- a/internal/service/platform/connector/git_data_source_test.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/git_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package codeRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/git_test.go b/internal/service/cd_nextgen/connector/codeRepositories/git_test.go similarity index 99% rename from internal/service/platform/connector/git_test.go rename to internal/service/cd_nextgen/connector/codeRepositories/git_test.go index 29e82b221..c53245b1a 100644 --- a/internal/service/platform/connector/git_test.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/git_test.go @@ -1,4 +1,4 @@ -package connector_test +package codeRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/github.go b/internal/service/cd_nextgen/connector/codeRepositories/github.go similarity index 97% rename from internal/service/platform/connector/github.go rename to internal/service/cd_nextgen/connector/codeRepositories/github.go index 7cd970111..8283d0229 100644 --- a/internal/service/platform/connector/github.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/github.go @@ -1,4 +1,4 @@ -package connector +package codeRepositories import ( "context" @@ -82,21 +82,21 @@ func ResourceConnectorGithub() *schema.Resource { ExactlyOneOf: []string{"api_authentication.0.github_app.0.application_id", "api_authentication.0.github_app.0.application_id_ref"}, }, "application_id_ref": { - Description: "Reference to the secret containing application id" + secret_ref_text, + Description: "Reference to the secret containing application id" + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"api_authentication.0.github_app.0.application_id"}, ExactlyOneOf: []string{"api_authentication.0.github_app.0.application_id", "api_authentication.0.github_app.0.application_id_ref"}, }, "installation_id_ref": { - Description: "Reference to the secret containing installation id." + secret_ref_text, + Description: "Reference to the secret containing installation id." + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"api_authentication.0.github_app.0.installation_id"}, ExactlyOneOf: []string{"api_authentication.0.github_app.0.installation_id", "api_authentication.0.github_app.0.installation_id_ref"}, }, "private_key_ref": { - Description: "Reference to the secret containing the private key." + secret_ref_text, + Description: "Reference to the secret containing the private key." + secretRefText, Type: schema.TypeString, Required: true, }, @@ -104,7 +104,7 @@ func ResourceConnectorGithub() *schema.Resource { }, }, "token_ref": { - Description: "Personal access token for interacting with the github api." + secret_ref_text, + Description: "Personal access token for interacting with the github api." + secretRefText, Type: schema.TypeString, Optional: true, AtLeastOneOf: []string{"api_authentication.0.token_ref", "api_authentication.0.github_app"}, @@ -137,14 +137,14 @@ func ResourceConnectorGithub() *schema.Resource { ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref", "credentials.0.http.0.github_app", "credentials.0.http.0.anonymous"}, }, "username_ref": { - Description: "Reference to a secret containing the username to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the username to use for authentication." + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.username"}, ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref", "credentials.0.http.0.github_app", "credentials.0.http.0.anonymous"}, }, "token_ref": { - Description: "Reference to a secret containing the personal access to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the personal access to use for authentication." + secretRefText, Type: schema.TypeString, Optional: true, }, @@ -171,21 +171,21 @@ func ResourceConnectorGithub() *schema.Resource { ExactlyOneOf: []string{"credentials.0.http.0.github_app.0.application_id", "credentials.0.http.0.github_app.0.application_id_ref"}, }, "application_id_ref": { - Description: "Reference to the secret containing application id" + secret_ref_text, + Description: "Reference to the secret containing application id" + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.github_app.0.application_id"}, ExactlyOneOf: []string{"credentials.0.http.0.github_app.0.application_id", "credentials.0.http.0.github_app.0.application_id_ref"}, }, "installation_id_ref": { - Description: "Reference to the secret containing installation id." + secret_ref_text, + Description: "Reference to the secret containing installation id." + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.github_app.0.installation_id"}, ExactlyOneOf: []string{"credentials.0.http.0.github_app.0.installation_id", "credentials.0.http.0.github_app.0.installation_id_ref"}, }, "private_key_ref": { - Description: "Reference to the secret containing the private key." + secret_ref_text, + Description: "Reference to the secret containing the private key." + secretRefText, Type: schema.TypeString, Required: true, }, @@ -214,7 +214,7 @@ func ResourceConnectorGithub() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "ssh_key_ref": { - Description: "Reference to the Harness secret containing the ssh key." + secret_ref_text, + Description: "Reference to the Harness secret containing the ssh key." + secretRefText, Type: schema.TypeString, Required: true, }, diff --git a/internal/service/platform/connector/github_data_source.go b/internal/service/cd_nextgen/connector/codeRepositories/github_data_source.go similarity index 94% rename from internal/service/platform/connector/github_data_source.go rename to internal/service/cd_nextgen/connector/codeRepositories/github_data_source.go index d137191ba..2b926f205 100644 --- a/internal/service/platform/connector/github_data_source.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/github_data_source.go @@ -1,4 +1,4 @@ -package connector +package codeRepositories import ( "fmt" @@ -64,17 +64,17 @@ func DatasourceConnectorGithub() *schema.Resource { Computed: true, }, "application_id_ref": { - Description: "Reference to the secret containing application id" + secret_ref_text, + Description: "Reference to the secret containing application id" + secretRefText, Type: schema.TypeString, Computed: true, }, "installation_id_ref": { - Description: "Reference to the secret containing installation id." + secret_ref_text, + Description: "Reference to the secret containing installation id." + secretRefText, Type: schema.TypeString, Computed: true, }, "private_key_ref": { - Description: "Reference to the secret containing the private key." + secret_ref_text, + Description: "Reference to the secret containing the private key." + secretRefText, Type: schema.TypeString, Computed: true, }, @@ -82,7 +82,7 @@ func DatasourceConnectorGithub() *schema.Resource { }, }, "token_ref": { - Description: "Personal access token for interacting with the github api." + secret_ref_text, + Description: "Personal access token for interacting with the github api." + secretRefText, Type: schema.TypeString, Computed: true, }, @@ -107,12 +107,12 @@ func DatasourceConnectorGithub() *schema.Resource { Computed: true, }, "username_ref": { - Description: "Reference to a secret containing the username to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the username to use for authentication." + secretRefText, Type: schema.TypeString, Computed: true, }, "token_ref": { - Description: "Reference to a secret containing the personal access to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the personal access to use for authentication." + secretRefText, Type: schema.TypeString, Computed: true, }, @@ -133,17 +133,17 @@ func DatasourceConnectorGithub() *schema.Resource { Computed: true, }, "application_id_ref": { - Description: "Reference to the secret containing application id" + secret_ref_text, + Description: "Reference to the secret containing application id" + secretRefText, Type: schema.TypeString, Computed: true, }, "installation_id_ref": { - Description: "Reference to the secret containing installation id." + secret_ref_text, + Description: "Reference to the secret containing installation id." + secretRefText, Type: schema.TypeString, Computed: true, }, "private_key_ref": { - Description: "Reference to the secret containing the private key." + secret_ref_text, + Description: "Reference to the secret containing the private key." + secretRefText, Type: schema.TypeString, Computed: true, }, @@ -168,7 +168,7 @@ func DatasourceConnectorGithub() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "ssh_key_ref": { - Description: "Reference to the Harness secret containing the ssh key." + secret_ref_text, + Description: "Reference to the Harness secret containing the ssh key." + secretRefText, Type: schema.TypeString, Computed: true, }, diff --git a/internal/service/platform/connector/github_data_source_test.go b/internal/service/cd_nextgen/connector/codeRepositories/github_data_source_test.go similarity index 99% rename from internal/service/platform/connector/github_data_source_test.go rename to internal/service/cd_nextgen/connector/codeRepositories/github_data_source_test.go index add871ff1..25b465487 100644 --- a/internal/service/platform/connector/github_data_source_test.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/github_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package codeRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/github_test.go b/internal/service/cd_nextgen/connector/codeRepositories/github_test.go similarity index 99% rename from internal/service/platform/connector/github_test.go rename to internal/service/cd_nextgen/connector/codeRepositories/github_test.go index cd002ac77..186623b09 100644 --- a/internal/service/platform/connector/github_test.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/github_test.go @@ -1,4 +1,4 @@ -package connector_test +package codeRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/gitlab.go b/internal/service/cd_nextgen/connector/codeRepositories/gitlab.go similarity index 97% rename from internal/service/platform/connector/gitlab.go rename to internal/service/cd_nextgen/connector/codeRepositories/gitlab.go index 119cddb4b..1aec6668f 100644 --- a/internal/service/platform/connector/gitlab.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/gitlab.go @@ -1,4 +1,4 @@ -package connector +package codeRepositories import ( "context" @@ -53,7 +53,7 @@ func ResourceConnectorGitlab() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "token_ref": { - Description: "Personal access token for interacting with the gitlab api." + secret_ref_text, + Description: "Personal access token for interacting with the gitlab api." + secretRefText, Type: schema.TypeString, Required: true, }, @@ -84,21 +84,21 @@ func ResourceConnectorGitlab() *schema.Resource { ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref"}, }, "username_ref": { - Description: "Reference to a secret containing the username to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the username to use for authentication." + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.username"}, ExactlyOneOf: []string{"credentials.0.http.0.username", "credentials.0.http.0.username_ref"}, }, "token_ref": { - Description: "Reference to a secret containing the personal access to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the personal access to use for authentication." + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.password_ref"}, AtLeastOneOf: []string{"credentials.0.http.0.token_ref", "credentials.0.http.0.password_ref"}, }, "password_ref": { - Description: "Reference to a secret containing the password to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the password to use for authentication." + secretRefText, Type: schema.TypeString, Optional: true, ConflictsWith: []string{"credentials.0.http.0.token_ref"}, @@ -117,7 +117,7 @@ func ResourceConnectorGitlab() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "ssh_key_ref": { - Description: "Reference to the Harness secret containing the ssh key." + secret_ref_text, + Description: "Reference to the Harness secret containing the ssh key." + secretRefText, Type: schema.TypeString, Required: true, }, diff --git a/internal/service/platform/connector/gitlab_data_source.go b/internal/service/cd_nextgen/connector/codeRepositories/gitlab_data_source.go similarity index 93% rename from internal/service/platform/connector/gitlab_data_source.go rename to internal/service/cd_nextgen/connector/codeRepositories/gitlab_data_source.go index 5ecc80136..8097c65ef 100644 --- a/internal/service/platform/connector/gitlab_data_source.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/gitlab_data_source.go @@ -1,4 +1,4 @@ -package connector +package codeRepositories import ( "fmt" @@ -43,7 +43,7 @@ func DatasourceConnectorGitlab() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "token_ref": { - Description: "Personal access token for interacting with the gitlab api." + secret_ref_text, + Description: "Personal access token for interacting with the gitlab api." + secretRefText, Type: schema.TypeString, Computed: true, }, @@ -68,17 +68,17 @@ func DatasourceConnectorGitlab() *schema.Resource { Computed: true, }, "username_ref": { - Description: "Reference to a secret containing the username to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the username to use for authentication." + secretRefText, Type: schema.TypeString, Computed: true, }, "token_ref": { - Description: "Reference to a secret containing the personal access to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the personal access to use for authentication." + secretRefText, Type: schema.TypeString, Computed: true, }, "password_ref": { - Description: "Reference to a secret containing the password to use for authentication." + secret_ref_text, + Description: "Reference to a secret containing the password to use for authentication." + secretRefText, Type: schema.TypeString, Computed: true, }, @@ -92,7 +92,7 @@ func DatasourceConnectorGitlab() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "ssh_key_ref": { - Description: "Reference to the Harness secret containing the ssh key." + secret_ref_text, + Description: "Reference to the Harness secret containing the ssh key." + secretRefText, Type: schema.TypeString, Computed: true, }, diff --git a/internal/service/platform/connector/gitlab_data_source_test.go b/internal/service/cd_nextgen/connector/codeRepositories/gitlab_data_source_test.go similarity index 98% rename from internal/service/platform/connector/gitlab_data_source_test.go rename to internal/service/cd_nextgen/connector/codeRepositories/gitlab_data_source_test.go index 2319e9ebc..3ae2b746f 100644 --- a/internal/service/platform/connector/gitlab_data_source_test.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/gitlab_data_source_test.go @@ -1,4 +1,4 @@ -package connector_test +package codeRepositories_test import ( "fmt" diff --git a/internal/service/platform/connector/gitlab_test.go b/internal/service/cd_nextgen/connector/codeRepositories/gitlab_test.go similarity index 99% rename from internal/service/platform/connector/gitlab_test.go rename to internal/service/cd_nextgen/connector/codeRepositories/gitlab_test.go index a8c93588e..7f58cf6ce 100644 --- a/internal/service/platform/connector/gitlab_test.go +++ b/internal/service/cd_nextgen/connector/codeRepositories/gitlab_test.go @@ -1,4 +1,4 @@ -package connector_test +package codeRepositories_test import ( "fmt" diff --git a/internal/service/cd_nextgen/connector/codeRepositories/secret_util.go b/internal/service/cd_nextgen/connector/codeRepositories/secret_util.go new file mode 100644 index 000000000..70c977eb9 --- /dev/null +++ b/internal/service/cd_nextgen/connector/codeRepositories/secret_util.go @@ -0,0 +1,3 @@ +package codeRepositories + +const secretRefText = " To reference a secret at the organization scope, prefix 'org' to the expression: org.{identifier}. To reference a secret at the account scope, prefix 'account` to the expression: account.{identifier}."