diff --git a/examples/authorization_configuration.tf b/examples/authorization_configuration.tf index 4c02a5e..6cbddcc 100644 --- a/examples/authorization_configuration.tf +++ b/examples/authorization_configuration.tf @@ -8,5 +8,5 @@ resource "gocd_auth_config" "password_file_config" { } data "gocd_auth_config" "password_file_config" { - profile_id = "admin_new" + profile_id = gocd_auth_config.password_file_config.id } \ No newline at end of file diff --git a/examples/cluster_profile.tf b/examples/cluster_profile.tf index f6602b8..28b9fa5 100644 --- a/examples/cluster_profile.tf +++ b/examples/cluster_profile.tf @@ -69,5 +69,5 @@ resource "gocd_cluster_profile" "ec2_cluster_profile" { } data "gocd_cluster_profile" "ec2_cluster_profile" { - profile_id = "ec2_cluster_profile" + profile_id = gocd_cluster_profile.ec2_cluster_profile.id } \ No newline at end of file diff --git a/examples/config_repo.tf b/examples/config_repo.tf index b1f98ca..2f7172e 100644 --- a/examples/config_repo.tf +++ b/examples/config_repo.tf @@ -11,7 +11,7 @@ resource "gocd_config_repository" "sample_config_repo" { } configuration { key = "url" - value = "https://github.com/sample/example.git" + value = "https://github.com/config-repo/gocd-json-config-example.git" is_secure = false } material { @@ -35,5 +35,5 @@ resource "gocd_config_repository" "sample_config_repo" { } data "gocd_config_repository" "sample_config_repo" { - profile_id = "sample_config_repo" -} \ No newline at end of file + profile_id = gocd_config_repository.sample_config_repo.id +} diff --git a/examples/elastic_agent_profile.tf b/examples/elastic_agent_profile.tf index 824f4ef..c6f7a5b 100644 --- a/examples/elastic_agent_profile.tf +++ b/examples/elastic_agent_profile.tf @@ -61,5 +61,5 @@ resource "gocd_elastic_agent_profile" "sample_ec2" { } data "gocd_elastic_agent_profile" "sample_ec2" { - profile_id = "sample_ec2" + profile_id = gocd_elastic_agent_profile.sample_ec2.id } \ No newline at end of file diff --git a/examples/environment.tf b/examples/environment.tf index 6cfc309..45a6b15 100644 --- a/examples/environment.tf +++ b/examples/environment.tf @@ -19,5 +19,5 @@ resource "gocd_environment" "sample_environment" { } data "gocd_environment" "sample_environment" { - name = "sample_environment" + name = gocd_environment.sample_environment.id } \ No newline at end of file diff --git a/examples/provider.tf b/examples/provider.tf index e5ea031..0fba790 100644 --- a/examples/provider.tf +++ b/examples/provider.tf @@ -10,7 +10,7 @@ terraform { provider "gocd" { base_url = "http://localhost:8153/go" username = "admin" -// password = "admin" + password = "admin" auth_token = "d8fccbc997d04e917b1490af8e7bf46290ab8c99" loglevel = "debug" } \ No newline at end of file diff --git a/internal/provider/data_auth_config.go b/internal/provider/data_auth_config.go index b6455c7..43e3406 100644 --- a/internal/provider/data_auth_config.go +++ b/internal/provider/data_auth_config.go @@ -57,13 +57,8 @@ func datasourceAuthConfigRead(ctx context.Context, d *schema.ResourceData, meta id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceProfileID)) + id = resourceID } profileID := utils.String(d.Get(utils.TerraformResourceProfileID)) diff --git a/internal/provider/data_cluster_profile.go b/internal/provider/data_cluster_profile.go index e241450..6461df9 100644 --- a/internal/provider/data_cluster_profile.go +++ b/internal/provider/data_cluster_profile.go @@ -50,13 +50,8 @@ func datasourceClusterProfileRead(ctx context.Context, d *schema.ResourceData, m id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceProfileID)) + id = resourceID } profileID := utils.String(d.Get(utils.TerraformResourceProfileID)) diff --git a/internal/provider/data_config_repository.go b/internal/provider/data_config_repository.go index c588878..7478dc0 100644 --- a/internal/provider/data_config_repository.go +++ b/internal/provider/data_config_repository.go @@ -22,13 +22,8 @@ func dataSourceConfigRepositoryRead(ctx context.Context, d *schema.ResourceData, id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceProfileID)) + id = resourceID } profileID := utils.String(d.Get(utils.TerraformResourceProfileID)) diff --git a/internal/provider/data_elastic_agent_profile.go b/internal/provider/data_elastic_agent_profile.go index ab73efe..4bfd482 100644 --- a/internal/provider/data_elastic_agent_profile.go +++ b/internal/provider/data_elastic_agent_profile.go @@ -50,13 +50,8 @@ func datasourceElasticAgentProfileRead(ctx context.Context, d *schema.ResourceDa id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceProfileID)) + id = resourceID } profileID := utils.String(d.Get(utils.TerraformResourceProfileID)) diff --git a/internal/provider/data_environment.go b/internal/provider/data_environment.go index 342c6e9..1d99d6e 100644 --- a/internal/provider/data_environment.go +++ b/internal/provider/data_environment.go @@ -45,13 +45,8 @@ func datasourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceName)) + id = resourceID } envName := utils.String(d.Get(utils.TerraformResourceName)) diff --git a/internal/provider/data_plugin_setting.go b/internal/provider/data_plugin_setting.go index 7adc331..d021fdb 100644 --- a/internal/provider/data_plugin_setting.go +++ b/internal/provider/data_plugin_setting.go @@ -43,13 +43,8 @@ func dataSourcePluginsSettingRead(ctx context.Context, d *schema.ResourceData, m id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformPluginID)) + id = resourceID } pluginID := utils.String(d.Get(utils.TerraformPluginID)) diff --git a/internal/provider/data_secret_config.go b/internal/provider/data_secret_config.go index 0f6b815..8baa4f8 100644 --- a/internal/provider/data_secret_config.go +++ b/internal/provider/data_secret_config.go @@ -65,13 +65,8 @@ func dataSourceSecretConfigRead(ctx context.Context, d *schema.ResourceData, met id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceProfileID)) + id = resourceID } profileID := utils.String(d.Get(utils.TerraformResourceProfileID)) diff --git a/internal/provider/resource_auth_config.go b/internal/provider/resource_auth_config.go index eb839fb..2ab3ca5 100644 --- a/internal/provider/resource_auth_config.go +++ b/internal/provider/resource_auth_config.go @@ -74,13 +74,8 @@ func resourceAuthConfigCreate(ctx context.Context, d *schema.ResourceData, meta id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceProfileID)) + id = resourceID } cfg := gocd.CommonConfig{ diff --git a/internal/provider/resource_cluster_profile.go b/internal/provider/resource_cluster_profile.go index 91bb65a..a60e376 100644 --- a/internal/provider/resource_cluster_profile.go +++ b/internal/provider/resource_cluster_profile.go @@ -70,13 +70,8 @@ func resourceClusterProfileCreate(ctx context.Context, d *schema.ResourceData, m id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceProfileID)) + id = resourceID } cfg := gocd.CommonConfig{ diff --git a/internal/provider/resource_config_repository.go b/internal/provider/resource_config_repository.go index d9267ac..6dc510f 100644 --- a/internal/provider/resource_config_repository.go +++ b/internal/provider/resource_config_repository.go @@ -71,13 +71,8 @@ func resourceConfigRepoCreate(ctx context.Context, d *schema.ResourceData, meta id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceProfileID)) + id = resourceID } rules, err := getRules(d.Get(utils.TerraformResourceRules)) diff --git a/internal/provider/resource_elastic_agent_profile.go b/internal/provider/resource_elastic_agent_profile.go index d715545..c74a899 100644 --- a/internal/provider/resource_elastic_agent_profile.go +++ b/internal/provider/resource_elastic_agent_profile.go @@ -52,13 +52,8 @@ func resourceElasticAgentProfileCreate(ctx context.Context, d *schema.ResourceDa id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceProfileID)) + id = resourceID } cfg := gocd.CommonConfig{ diff --git a/internal/provider/resource_environments.go b/internal/provider/resource_environments.go index d8ba973..54dcad8 100644 --- a/internal/provider/resource_environments.go +++ b/internal/provider/resource_environments.go @@ -61,13 +61,8 @@ func resourceEnvironmentCreate(ctx context.Context, d *schema.ResourceData, meta id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformResourceName)) + id = resourceID } envVars, err := getEnvironments(d.Get(utils.TerraformEnvVar)) diff --git a/internal/provider/resource_plugin_settings.go b/internal/provider/resource_plugin_settings.go index 67e113e..9a37052 100644 --- a/internal/provider/resource_plugin_settings.go +++ b/internal/provider/resource_plugin_settings.go @@ -92,13 +92,8 @@ func resourcePluginsSettingsCreate(ctx context.Context, d *schema.ResourceData, id := d.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - d.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(d.Get(utils.TerraformPluginID)) + id = resourceID } pluginSettings := gocd.PluginSettings{ diff --git a/internal/provider/resource_secret_config.go b/internal/provider/resource_secret_config.go index 3ba906b..693e4dc 100644 --- a/internal/provider/resource_secret_config.go +++ b/internal/provider/resource_secret_config.go @@ -82,13 +82,8 @@ func resourceSecretConfigCreate(ctx context.Context, data *schema.ResourceData, id := data.Id() if len(id) == 0 { - newID, err := utils.GetRandomID() - if err != nil { - data.SetId("") - - return diag.Errorf("errored while fetching randomID %v", err) - } - id = newID + resourceID := utils.String(data.Get(utils.TerraformResourceProfileID)) + id = resourceID } rules, err := getRules(data.Get(utils.TerraformResourceRules))