diff --git a/CHANGELOG.md b/CHANGELOG.md index 659705f6..44ed8a7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Various false positive attribute drifts ([#344](https://github.com/Scalr/terraform-provider-scalr/pull/344)) +- `cost_estimation_enabled` attribute is forced to `false` in the `scalr_environment` resource if this attrute is ommited in the configuration ([#366](https://github.com/Scalr/terraform-provider-scalr/pull/366)) ### Changed diff --git a/docs/resources/environment.md b/docs/resources/environment.md index 5d349829..d70b1c07 100644 --- a/docs/resources/environment.md +++ b/docs/resources/environment.md @@ -32,7 +32,7 @@ resource "scalr_environment" "test" { ### Optional - `account_id` (String) ID of the environment account, in the format `acc-`. -- `cost_estimation_enabled` (Boolean, Deprecated) Set (true/false) to enable/disable cost estimation for the environment. Default `true`. +- `cost_estimation_enabled` (Boolean, Deprecated) Set (true/false) to enable/disable cost estimation for the environment. - `default_provider_configurations` (Set of String) List of IDs of provider configurations, used in the environment workspaces by default. - `policy_groups` (List of String, Deprecated) List of the environment policy-groups IDs, in the format `pgrp-`. - `tag_ids` (Set of String) List of tag IDs associated with the environment. diff --git a/scalr/data_source_scalr_environment_test.go b/scalr/data_source_scalr_environment_test.go index 77fe60c7..9c4aced4 100644 --- a/scalr/data_source_scalr_environment_test.go +++ b/scalr/data_source_scalr_environment_test.go @@ -44,7 +44,7 @@ func TestAccEnvironmentDataSource_basic(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.scalr_environment.test", "name", fmt.Sprintf("test-env-%d", rInt)), resource.TestCheckResourceAttr("data.scalr_environment.test", "status", "Active"), - resource.TestCheckResourceAttr("data.scalr_environment.test", "cost_estimation_enabled", "false"), + resource.TestCheckResourceAttr("data.scalr_environment.test", "cost_estimation_enabled", "true"), resource.TestCheckResourceAttr("data.scalr_environment.test", "account_id", defaultAccount), resource.TestCheckResourceAttr("data.scalr_environment.test", "tags.#", "0"), resource.TestCheckResourceAttrSet("data.scalr_environment.test", "created_by.0.full_name"), @@ -58,7 +58,7 @@ func TestAccEnvironmentDataSource_basic(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.scalr_environment.test", "name", fmt.Sprintf("test-env-%d", rInt)), resource.TestCheckResourceAttr("data.scalr_environment.test", "status", "Active"), - resource.TestCheckResourceAttr("data.scalr_environment.test", "cost_estimation_enabled", "false"), + resource.TestCheckResourceAttr("data.scalr_environment.test", "cost_estimation_enabled", "true"), resource.TestCheckResourceAttr("data.scalr_environment.test", "account_id", defaultAccount), resource.TestCheckResourceAttrSet("data.scalr_environment.test", "created_by.0.full_name"), resource.TestCheckResourceAttrSet("data.scalr_environment.test", "created_by.0.email"), @@ -70,7 +70,7 @@ func TestAccEnvironmentDataSource_basic(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.scalr_environment.test", "name", fmt.Sprintf("test-env-%d", rInt)), resource.TestCheckResourceAttr("data.scalr_environment.test", "status", "Active"), - resource.TestCheckResourceAttr("data.scalr_environment.test", "cost_estimation_enabled", "false"), + resource.TestCheckResourceAttr("data.scalr_environment.test", "cost_estimation_enabled", "true"), resource.TestCheckResourceAttr("data.scalr_environment.test", "account_id", defaultAccount), resource.TestCheckResourceAttrSet("data.scalr_environment.test", "created_by.0.full_name"), resource.TestCheckResourceAttrSet("data.scalr_environment.test", "created_by.0.email"), diff --git a/scalr/resource_scalr_environment.go b/scalr/resource_scalr_environment.go index 7eee66b5..f049c362 100644 --- a/scalr/resource_scalr_environment.go +++ b/scalr/resource_scalr_environment.go @@ -4,9 +4,10 @@ import ( "context" "errors" "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "log" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/scalr/go-scalr" ) @@ -29,7 +30,7 @@ func resourceScalrEnvironment() *schema.Resource { Required: true, }, "cost_estimation_enabled": { - Description: "Set (true/false) to enable/disable cost estimation for the environment. Default `true`.", + Description: "Set (true/false) to enable/disable cost estimation for the environment.", Type: schema.TypeBool, Computed: true, Optional: true, @@ -126,10 +127,12 @@ func resourceScalrEnvironmentCreate(ctx context.Context, d *schema.ResourceData, } options := scalr.EnvironmentCreateOptions{ - Name: scalr.String(name), - CostEstimationEnabled: scalr.Bool(d.Get("cost_estimation_enabled").(bool)), - Account: &scalr.Account{ID: accountID}, - PolicyGroups: policyGroups, + Name: scalr.String(name), + Account: &scalr.Account{ID: accountID}, + PolicyGroups: policyGroups, + } + if costEstimationEnabled, ok := d.GetOkExists("cost_estimation_enabled"); ok { //nolint:staticcheck + options.CostEstimationEnabled = scalr.Bool(costEstimationEnabled.(bool)) } if defaultProviderConfigurationsI, ok := d.GetOk("default_provider_configurations"); ok { defaultProviderConfigurations := defaultProviderConfigurationsI.(*schema.Set).List() @@ -228,9 +231,11 @@ func resourceScalrEnvironmentUpdate(ctx context.Context, d *schema.ResourceData, // Create a new options struct. options := scalr.EnvironmentUpdateOptions{ - Name: scalr.String(d.Get("name").(string)), - CostEstimationEnabled: scalr.Bool(d.Get("cost_estimation_enabled").(bool)), - PolicyGroups: policyGroups, + Name: scalr.String(d.Get("name").(string)), + PolicyGroups: policyGroups, + } + if costEstimationEnabled, ok := d.GetOkExists("cost_estimation_enabled"); ok { //nolint:staticcheck + options.CostEstimationEnabled = scalr.Bool(costEstimationEnabled.(bool)) } if defaultProviderConfigurationsI, ok := d.GetOk("default_provider_configurations"); ok {