Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCALRCORE-32726 Add the ability to disable the Scalr backend to API/P… #378

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `data.scalr_environments`: changed type of `ids` attribute from TypeList to TypeSet ([373](https://github.com/Scalr/terraform-provider-scalr/pull/373))

- `scalr_workspace` and `data.scalr_workspace`: new attributes `terragrunt_version` and `terragrunt_use_run_all` ([#378](https://github.com/Scalr/terraform-provider-scalr/pull/378))
- `scalr_environment` and `data.scalr_environment`: new attribute `remote_backend` ([#378](https://github.com/Scalr/terraform-provider-scalr/pull/378))

## [2.2.0] - 2024-11-22

### Added
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data "scalr_environment" "example2" {
- `created_by` (List of Object) Details of the user that created the environment. (see [below for nested schema](#nestedatt--created_by))
- `default_provider_configurations` (List of String) List of IDs of provider configurations, used in the environment workspaces by default.
- `policy_groups` (List of String) List of the environment policy-groups IDs, in the format `pgrp-<RANDOM STRING>`.
- `remote_backend` (Boolean) If Scalr exports the remote backend configuration and state storage for your infrastructure management. Disabling this feature will also prevent the ability to perform state locking, which ensures that concurrent operations do not conflict. Additionally, it will disable the capability to initiate CLI-driven runs through Scalr.
- `status` (String) The status of an environment.
- `tag_ids` (List of String) List of tag IDs associated with the environment.

Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ data "scalr_workspace" "example2" {
- `vcs_provider_id` (String) The identifier of a VCS provider in the format `vcs-<RANDOM STRING>`.
- `vcs_repo` (List of Object) If a workspace is linked to a VCS repository this block shows the details, otherwise `{}` (see [below for nested schema](#nestedatt--vcs_repo))
- `working_directory` (String) A relative path that Terraform will execute within.
- `terragrunt_version` (String) The version of Terragrunt the workspace performs runs on.
- `terragrunt_use_run_all` (Boolean) Indicates whether the workspace uses `terragrunt run-all`.

<a id="nestedatt--created_by"></a>
### Nested Schema for `created_by`
Expand Down
1 change: 1 addition & 0 deletions docs/resources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ resource "scalr_environment" "test" {
- `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>`.
- `remote_backend` (Boolean) If Scalr exports the remote backend configuration and state storage for your infrastructure management. Disabling this feature will also prevent the ability to perform state locking, which ensures that concurrent operations do not conflict. Additionally, it will disable the capability to initiate CLI-driven runs through Scalr.
- `tag_ids` (Set of String) List of tag IDs associated with the environment.

### Read-Only
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ resource "scalr_workspace" "example-b" {
- `ssh_key_id` (String) The identifier of the SSH key to use for the workspace.
- `tag_ids` (Set of String) List of tag IDs associated with the workspace.
- `terraform_version` (String) The version of Terraform to use for this workspace. Defaults to the latest available version.
- `terragrunt_use_run_all` (Boolean) Indicates whether the workspace uses `terragrunt run-all`.
- `terragrunt_version` (String) The version of Terragrunt the workspace performs runs on.
- `type` (String) The type of the Scalr Workspace environment, available options: `production`, `staging`, `testing`, `development`, `unmapped`.
- `var_files` (List of String) A list of paths to the `.tfvars` file(s) to be used as part of the workspace configuration.
- `vcs_provider_id` (String) ID of VCS provider - required if vcs-repo present and vice versa, in the format `vcs-<RANDOM STRING>`.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0
github.com/hashicorp/terraform-plugin-testing v1.11.0
github.com/hashicorp/terraform-svchost v0.1.1
github.com/scalr/go-scalr v0.0.0-20241111151759-2c33e05ca45e
github.com/scalr/go-scalr v0.0.0-20241217115214-520118b5f6e3
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBO
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/scalr/go-scalr v0.0.0-20241111151759-2c33e05ca45e h1:dRpwrWotOKjMEmUJQEavyoM/20QTXshBeY7bAmg+84s=
github.com/scalr/go-scalr v0.0.0-20241111151759-2c33e05ca45e/go.mod h1:p34SHb25YRvbgft7SUjSDYESeoQhWzAlxGXId/BbaSE=
github.com/scalr/go-scalr v0.0.0-20241217115214-520118b5f6e3 h1:S1NUPU0JSImn29HJfPRaRxQLPSR4G8HwWi6tl99bgbo=
github.com/scalr/go-scalr v0.0.0-20241217115214-520118b5f6e3/go.mod h1:p34SHb25YRvbgft7SUjSDYESeoQhWzAlxGXId/BbaSE=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
Expand Down
6 changes: 6 additions & 0 deletions internal/provider/data_source_scalr_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func dataSourceScalrEnvironment() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"remote_backend": {
Description: "If Scalr exports the remote backend configuration and state storage for your infrastructure management. Disabling this feature will also prevent the ability to perform state locking, which ensures that concurrent operations do not conflict. Additionally, it will disable the capability to initiate CLI-driven runs through Scalr.",
Type: schema.TypeBool,
Computed: true,
},
}}
}

Expand Down Expand Up @@ -131,6 +136,7 @@ func dataSourceEnvironmentRead(ctx context.Context, d *schema.ResourceData, meta
_ = d.Set("name", environment.Name)
_ = d.Set("cost_estimation_enabled", environment.CostEstimationEnabled)
_ = d.Set("status", environment.Status)
_ = d.Set("remote_backend", environment.RemoteBackend)

var createdBy []interface{}
if environment.CreatedBy != nil {
Expand Down
13 changes: 12 additions & 1 deletion internal/provider/data_source_scalr_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,16 @@ func dataSourceScalrWorkspace() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"terragrunt_version": {
Description: "The version of Terragrunt the workspace performs runs on.",
Type: schema.TypeString,
Computed: true,
},
"terragrunt_use_run_all": {
Description: "Indicates whether the workspace uses `terragrunt run-all`.",
Type: schema.TypeBool,
Computed: true,
},
"iac_platform": {
Description: "The IaC platform used for this workspace.",
Type: schema.TypeString,
Expand Down Expand Up @@ -275,6 +284,8 @@ func dataSourceScalrWorkspaceRead(ctx context.Context, d *schema.ResourceData, m
_ = d.Set("operations", workspace.Operations)
_ = d.Set("execution_mode", workspace.ExecutionMode)
_ = d.Set("terraform_version", workspace.TerraformVersion)
_ = d.Set("terragrunt_version", workspace.TerragruntVersion)
_ = d.Set("terragrunt_use_run_all", workspace.TerragruntUseRunAll)
_ = d.Set("iac_platform", workspace.IaCPlatform)
_ = d.Set("type", workspace.EnvironmentType)
_ = d.Set("working_directory", workspace.WorkingDirectory)
Expand Down
12 changes: 12 additions & 0 deletions internal/provider/resource_scalr_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ func resourceScalrEnvironment() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"remote_backend": {
Description: "If Scalr exports the remote backend configuration and state storage for your infrastructure management. Disabling this feature will also prevent the ability to perform state locking, which ensures that concurrent operations do not conflict. Additionally, it will disable the capability to initiate CLI-driven runs through Scalr.",
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},
},
}
}
Expand Down Expand Up @@ -134,6 +141,10 @@ func resourceScalrEnvironmentCreate(ctx context.Context, d *schema.ResourceData,
if costEstimationEnabled, ok := d.GetOkExists("cost_estimation_enabled"); ok { //nolint:staticcheck
options.CostEstimationEnabled = ptr(costEstimationEnabled.(bool))
}
if remoteBackend, ok := d.GetOkExists("remote_backend"); ok { //nolint:staticcheck
options.RemoteBackend = ptr(remoteBackend.(bool))
}

if defaultProviderConfigurationsI, ok := d.GetOk("default_provider_configurations"); ok {
defaultProviderConfigurations := defaultProviderConfigurationsI.(*schema.Set).List()
pcfgValues := make([]*scalr.ProviderConfiguration, 0)
Expand Down Expand Up @@ -183,6 +194,7 @@ func resourceScalrEnvironmentRead(ctx context.Context, d *schema.ResourceData, m
_ = d.Set("name", environment.Name)
_ = d.Set("account_id", environment.Account.ID)
_ = d.Set("cost_estimation_enabled", environment.CostEstimationEnabled)
_ = d.Set("remote_backend", environment.RemoteBackend)
_ = d.Set("status", environment.Status)

defaultProviderConfigurations := make([]string, 0)
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/resource_scalr_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccEnvironment_basic(t *testing.T) {
testAccCheckScalrEnvironmentAttributes(environment, rInt),
resource.TestCheckResourceAttr("scalr_environment.test", "name", fmt.Sprintf("test-env-%d", rInt)),
resource.TestCheckResourceAttr("scalr_environment.test", "cost_estimation_enabled", "true"),
resource.TestCheckResourceAttr("scalr_environment.test", "remote_backend", "false"),
resource.TestCheckResourceAttr("scalr_environment.test", "status", "Active"),
resource.TestCheckResourceAttr("scalr_environment.test", "account_id", defaultAccount),
resource.TestCheckResourceAttr("scalr_environment.test", "policy_groups.%", "0"),
Expand Down Expand Up @@ -233,6 +234,7 @@ resource "scalr_environment" "test" {
name = "test-env-%d"
account_id = "%s"
cost_estimation_enabled = true
remote_backend = false
}`, rInt, defaultAccount)
}

Expand Down
28 changes: 27 additions & 1 deletion internal/provider/resource_scalr_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ func resourceScalrWorkspace() *schema.Resource {
Optional: true,
Computed: true,
},
"terragrunt_version": {
Description: "The version of Terragrunt the workspace performs runs on.",
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"terragrunt_use_run_all": {
Description: "Indicates whether the workspace uses `terragrunt run-all`.",
Type: schema.TypeBool,
Optional: true,
Computed: true,
},

"iac_platform": {
Description: "The IaC platform to use for this workspace. Valid values are `terraform` and `opentofu`. Defaults to `terraform`.",
Expand Down Expand Up @@ -412,6 +424,12 @@ func resourceScalrWorkspaceCreate(ctx context.Context, d *schema.ResourceData, m
if operations, ok := d.GetOk("operations"); ok {
options.Operations = ptr(operations.(bool))
}
if terragruntVersion, ok := d.GetOk("terragrunt_version"); ok {
options.TerragruntVersion = ptr(terragruntVersion.(string))
}
if terragruntUseRunAll, ok := d.GetOk("terragrunt_use_run_all"); ok {
options.TerragruntUseRunAll = ptr(terragruntUseRunAll.(bool))
}

if executionMode, ok := d.GetOk("execution_mode"); ok {
options.ExecutionMode = ptr(
Expand Down Expand Up @@ -585,6 +603,8 @@ func resourceScalrWorkspaceRead(ctx context.Context, d *schema.ResourceData, met
_ = d.Set("auto_queue_runs", workspace.AutoQueueRuns)
_ = d.Set("type", workspace.EnvironmentType)
_ = d.Set("var_files", workspace.VarFiles)
_ = d.Set("terragrunt_version", workspace.TerragruntVersion)
_ = d.Set("terragrunt_use_run_all", workspace.TerragruntUseRunAll)

if workspace.RunOperationTimeout != nil {
_ = d.Set("run_operation_timeout", &workspace.RunOperationTimeout)
Expand Down Expand Up @@ -689,7 +709,7 @@ func resourceScalrWorkspaceUpdate(ctx context.Context, d *schema.ResourceData, m
d.HasChange("vcs_provider_id") || d.HasChange("agent_pool_id") || d.HasChange("deletion_protection_enabled") ||
d.HasChange("hooks") || d.HasChange("module_version_id") || d.HasChange("var_files") ||
d.HasChange("run_operation_timeout") || d.HasChange("iac_platform") ||
d.HasChange("type") {
d.HasChange("type") || d.HasChange("terragrunt_version") || d.HasChange("terragrunt_use_run_all") {
// Create a new options struct.
options := scalr.WorkspaceUpdateOptions{
Name: ptr(d.Get("name").(string)),
Expand All @@ -715,6 +735,12 @@ func resourceScalrWorkspaceUpdate(ctx context.Context, d *schema.ResourceData, m
scalr.WorkspaceExecutionMode(executionMode.(string)),
)
}
if terragruntVersion, ok := d.GetOk("terragrunt_version"); ok {
options.TerragruntVersion = ptr(terragruntVersion.(string))
}
if terragruntUseRunAll, ok := d.GetOkExists("terragrunt_use_run_all"); ok { //nolint:staticcheck
options.TerragruntUseRunAll = ptr(terragruntUseRunAll.(bool))
}

if autoQueueRunsI, ok := d.GetOk("auto_queue_runs"); ok {
options.AutoQueueRuns = ptr(
Expand Down
2 changes: 2 additions & 0 deletions templates/data-sources/workspace.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ hidden: false
- `vcs_provider_id` (String) The identifier of a VCS provider in the format `vcs-<RANDOM STRING>`.
- `vcs_repo` (List of Object) If a workspace is linked to a VCS repository this block shows the details, otherwise `{}` (see [below for nested schema](#nestedatt--vcs_repo))
- `working_directory` (String) A relative path that Terraform will execute within.
- `terragrunt_version` (String) The version of Terragrunt the workspace performs runs on.
- `terragrunt_use_run_all` (Boolean) Indicates whether the workspace uses `terragrunt run-all`.

<a id="nestedatt--created_by"></a>
### Nested Schema for `created_by`
Expand Down
Loading