Skip to content

Add iac-platform attribute to Terraform Scalr Provider #290

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

Merged
merged 4 commits into from
Dec 4, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- `scalr_service_account`: new attribute `owners` ([#289](https://github.com/Scalr/terraform-provider-scalr/pull/289))
- `data.scalr_service_account`: new attribute `owners` ([#289](https://github.com/Scalr/terraform-provider-scalr/pull/289))
- `scalr_workspace`: new attribute `iac-platform` ([#290](https://github.com/Scalr/terraform-provider-scalr/pull/290))
- `data.scalr_workspace`: new attribute `iac-platform` ([#290](https://github.com/Scalr/terraform-provider-scalr/pull/290))

### Changed

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ data "scalr_workspace" "example2" {
- `operations` (Boolean) Boolean indicates if the workspace is being used for remote execution.
- `tag_ids` (List of String) List of tag IDs associated with the workspace.
- `terraform_version` (String) The version of Terraform used for this workspace.
- `iac_platform` (String) The IaC platform used for this workspace.
- `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.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ resource "scalr_workspace" "example-b" {
- `execution_mode` (String) Which execution mode to use. Valid values are `remote` and `local`. When set to `local`, the workspace will be used for state storage only. Defaults to `remote` (not set, backend default is used).
- `force_latest_run` (Boolean) Set (true/false) to configure if latest new run will be automatically raised in priority. Default `false`.
- `hooks` (Block List) Settings for the workspaces custom hooks. (see [below for nested schema](#nestedblock--hooks))
- `iac_platform` (String) The IaC platform to use for this workspace. Valid values are `terraform` and `opentofu`. Defaults to `terraform`.
- `module_version_id` (String) The identifier of a module version in the format `modver-<RANDOM STRING>`. This attribute conflicts with `vcs_provider_id` and `vcs_repo` attributes.
- `operations` (Boolean, Deprecated) Set (true/false) to configure workspace remote execution. When `false` workspace is only used to store state. Defaults to `true`.
- `provider_configuration` (Block Set) Provider configurations used in workspace runs. (see [below for nested schema](#nestedblock--provider_configuration))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/hashicorp/terraform-plugin-docs v0.16.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.24.1
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
github.com/scalr/go-scalr v0.0.0-20231127161513-5526b467eebc
github.com/scalr/go-scalr v0.0.0-20231204095619-3b9fb0c63094
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
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-20231127161513-5526b467eebc h1:TvEXZ34Q3rS8dab1zO5pNqTQDDjPZrKBBw44PycKV3A=
github.com/scalr/go-scalr v0.0.0-20231127161513-5526b467eebc/go.mod h1:p34SHb25YRvbgft7SUjSDYESeoQhWzAlxGXId/BbaSE=
github.com/scalr/go-scalr v0.0.0-20231204095619-3b9fb0c63094 h1:pc9Hejjd9h4+P8ZSrGLYjiZYFJqRs6Wk03Dt2gJyXEw=
github.com/scalr/go-scalr v0.0.0-20231204095619-3b9fb0c63094/go.mod h1:p34SHb25YRvbgft7SUjSDYESeoQhWzAlxGXId/BbaSE=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
Expand Down
7 changes: 7 additions & 0 deletions scalr/data_source_scalr_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ func dataSourceScalrWorkspace() *schema.Resource {
Computed: true,
},

"iac_platform": {
Description: "The IaC platform used for this workspace.",
Type: schema.TypeString,
Computed: true,
},

"working_directory": {
Description: "A relative path that Terraform will execute within.",
Type: schema.TypeString,
Expand Down Expand Up @@ -262,6 +268,7 @@ 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("iac_platform", workspace.IaCPlatform)
_ = d.Set("working_directory", workspace.WorkingDirectory)
_ = d.Set("has_resources", workspace.HasResources)
_ = d.Set("auto_queue_runs", workspace.AutoQueueRuns)
Expand Down
3 changes: 3 additions & 0 deletions scalr/data_source_scalr_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func TestAccScalrWorkspaceDataSource_basic(t *testing.T) {
"data.scalr_workspace.test", "auto_apply", "true"),
resource.TestCheckResourceAttr(
"data.scalr_workspace.test", "terraform_version", "1.1.9"),
resource.TestCheckResourceAttr(
"data.scalr_workspace.test", "iac_platform", "terraform"),
resource.TestCheckResourceAttr(
"data.scalr_workspace.test", "working_directory", "terraform/test"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -115,6 +117,7 @@ resource scalr_workspace test {
environment_id = scalr_environment.test.id
auto_apply = true
terraform_version = "1.1.9"
iac_platform = "terraform"
working_directory = "terraform/test"
hooks {
pre_init = "./scripts/pre-init.sh"
Expand Down
30 changes: 27 additions & 3 deletions scalr/resource_scalr_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"context"
"errors"
"fmt"
"github.com/scalr/go-scalr"
"log"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/scalr/go-scalr"
)

func resourceScalrWorkspace() *schema.Resource {
Expand Down Expand Up @@ -142,6 +141,22 @@ func resourceScalrWorkspace() *schema.Resource {
Computed: true,
},

"iac_platform": {
Description: "The IaC platform to use for this workspace. Valid values are `terraform` and `opentofu`. Defaults to `terraform`.",
Type: schema.TypeString,
Optional: true,
Default: string(scalr.WorkspaceIaCPlatformTerraform),
ValidateDiagFunc: validation.ToDiagFunc(
validation.StringInSlice(
[]string{
string(scalr.WorkspaceIaCPlatformTerraform),
string(scalr.WorkspaceIaCPlatformOpenTofu),
},
false,
),
),
},

"working_directory": {
Description: "A relative path that Terraform will be run in. Defaults to the root of the repository `\"\"`.",
Type: schema.TypeString,
Expand Down Expand Up @@ -390,6 +405,10 @@ func resourceScalrWorkspaceCreate(ctx context.Context, d *schema.ResourceData, m
options.TerraformVersion = scalr.String(tfVersion.(string))
}

if iacPlatform, ok := d.GetOk("iac_platform"); ok {
options.IacPlatform = scalr.WorkspaceIaCPlatformPtr(scalr.WorkspaceIaCPlatform(iacPlatform.(string)))
}

if workingDir, ok := d.GetOk("working_directory"); ok {
options.WorkingDirectory = scalr.String(workingDir.(string))
}
Expand Down Expand Up @@ -521,6 +540,7 @@ func resourceScalrWorkspaceRead(ctx context.Context, d *schema.ResourceData, met
_ = d.Set("operations", workspace.Operations)
_ = d.Set("execution_mode", workspace.ExecutionMode)
_ = d.Set("terraform_version", workspace.TerraformVersion)
_ = d.Set("iac_platform", workspace.IaCPlatform)
_ = d.Set("working_directory", workspace.WorkingDirectory)
_ = d.Set("environment_id", workspace.Environment.ID)
_ = d.Set("has_resources", workspace.HasResources)
Expand Down Expand Up @@ -625,7 +645,7 @@ func resourceScalrWorkspaceUpdate(ctx context.Context, d *schema.ResourceData, m
d.HasChange("vcs_repo") || d.HasChange("operations") || d.HasChange("execution_mode") ||
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("run_operation_timeout") || d.HasChange("iac_platform") {
// Create a new options struct.
options := scalr.WorkspaceUpdateOptions{
Name: scalr.String(d.Get("name").(string)),
Expand Down Expand Up @@ -662,6 +682,10 @@ func resourceScalrWorkspaceUpdate(ctx context.Context, d *schema.ResourceData, m
options.TerraformVersion = scalr.String(tfVersion.(string))
}

if iacPlatform, ok := d.GetOk("iac_platform"); ok {
options.IacPlatform = scalr.WorkspaceIaCPlatformPtr(scalr.WorkspaceIaCPlatform(iacPlatform.(string)))
}

if v, ok := d.Get("var_files").([]interface{}); ok {
varFiles := make([]string, 0)
for _, varFile := range v {
Expand Down
4 changes: 4 additions & 0 deletions scalr/resource_scalr_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ func TestAccScalrWorkspace_update(t *testing.T) {
"scalr_workspace.test", "execution_mode", string(scalr.WorkspaceExecutionModeLocal)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "terraform_version", "1.1.9"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "iac_platform", string(scalr.WorkspaceIaCPlatformTerraform)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "working_directory", "terraform/test"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -287,6 +289,8 @@ func TestAccScalrWorkspace_update(t *testing.T) {
"scalr_workspace.test", "execution_mode", string(scalr.WorkspaceExecutionModeLocal)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "terraform_version", "1.1.9"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "iac_platform", string(scalr.WorkspaceIaCPlatformTerraform)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "working_directory", "terraform/test"),
resource.TestCheckResourceAttr(
Expand Down
1 change: 1 addition & 0 deletions templates/data-sources/workspace.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ hidden: false
- `operations` (Boolean) Boolean indicates if the workspace is being used for remote execution.
- `tag_ids` (List of String) List of tag IDs associated with the workspace.
- `terraform_version` (String) The version of Terraform used for this workspace.
- `iac_platform` (String) The IaC platform used for this workspace.
- `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.
Expand Down