Skip to content

Commit

Permalink
SCALRCORE-33151 BE > Provider > User is not able to disable cost esti… (
Browse files Browse the repository at this point in the history
#366)

* SCALRCORE-33151 BE > Provider > User is not able to disable cost estimation from environment settings when Infracost integration is configured with "shared for all" option

* SCALRCORE-33151 add changelog

* SCALRCORE-33151 update the documentation

* SCALRCORE-33151 use getOkExists for bool values

* SCALRCORE-33151 fix linter

* SCALRCORE-33151 ci fix
  • Loading branch information
DayS1eeper authored Nov 25, 2024
1 parent 69b372b commit 8d0301b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ resource "scalr_environment" "test" {
### Optional

- `account_id` (String) ID of the environment account, in the format `acc-<RANDOM STRING>`.
- `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-<RANDOM STRING>`.
- `tag_ids` (Set of String) List of tag IDs associated with the environment.
Expand Down
6 changes: 3 additions & 3 deletions scalr/data_source_scalr_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down
23 changes: 14 additions & 9 deletions scalr/resource_scalr_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8d0301b

Please sign in to comment.