Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Scalr/terraform-provider-scalr i…
Browse files Browse the repository at this point in the history
…nto feature/SCALRCORE-21545
  • Loading branch information
Artem Vang committed May 11, 2022
2 parents 6e4ef14 + 375f1f5 commit 12ab219
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `scalr_workspace`: added a new attribute `run_operation_timeout` ([#115](https://github.com/Scalr/terraform-provider-scalr/pull/115))

### Changed

- `scalr_workspace`: added new attribute `var_files` ([#118](https://github.com/Scalr/terraform-provider-scalr/pull/118))
- `resource.scalr_role`: added new state migration (include `accounts:set-quotas` permission if needed) ([#116](https://github.com/Scalr/terraform-provider-scalr/pull/108))

### Fixed
Expand Down
1 change: 1 addition & 0 deletions docs/resources/scalr_workspace.md
Expand Up @@ -96,6 +96,7 @@ resource "scalr_workspace" "cli-driven" {
Defaults to `true`.
* `terraform_version` - (Optional) The version of Terraform to use for this workspace. Defaults to the latest available version.
* `working_directory` - (Optional) A relative path that Terraform will be run in. Defaults to the root of the repository `""`.
* `var_files` - (Optional) List of paths to the workspace variables files.
* `run_operation_timeout` - (Optional) The number of minutes run operation can be executed before termination. Defaults to `0` (not set, backend default is used).
* `module_version_id` - (Optional) The identifier of a module version in the format `modver-<RANDOM STRING>`. This attribute conflicts with `vcs_provider_id` and `vcs_repo` attributes.
* `agent_pool_id` - (Optional) The identifier of an agent pool in the format `apool-<RANDOM STRING>`.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -5,7 +5,7 @@ require (
github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734
github.com/scalr/go-scalr v0.0.0-20220429130144-6ee1c7c3d93a
github.com/scalr/go-scalr v0.0.0-20220510084130-4347446d3afe
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -305,6 +305,8 @@ github.com/scalr/go-scalr v0.0.0-20220408125149-98e871983106 h1:2eJf0QIg5LpWqRVU
github.com/scalr/go-scalr v0.0.0-20220408125149-98e871983106/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220429130144-6ee1c7c3d93a h1:P4ANn4rx4tmVLUIIm5V0hUkR0eTUImyhtla8SE1EVhc=
github.com/scalr/go-scalr v0.0.0-20220429130144-6ee1c7c3d93a/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20220510084130-4347446d3afe h1:Gq6oYYwAe6b70HtxwG+3mfim87sHsZJVkE1DErQk2qY=
github.com/scalr/go-scalr v0.0.0-20220510084130-4347446d3afe/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
Expand Down
26 changes: 25 additions & 1 deletion scalr/resource_scalr_workspace.go
Expand Up @@ -71,6 +71,12 @@ func resourceScalrWorkspace() *schema.Resource {
Default: false,
},

"var_files": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"operations": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -291,6 +297,14 @@ func resourceScalrWorkspaceCreate(d *schema.ResourceData, meta interface{}) erro
}
}

if v, ok := d.Get("var_files").([]interface{}); ok {
varFiles := make([]string, 0)
for _, varFile := range v {
varFiles = append(varFiles, varFile.(string))
}
options.VarFiles = varFiles
}

log.Printf("[DEBUG] Create workspace %s for environment: %s", name, environmentID)
workspace, err := scalrClient.Workspaces.Create(ctx, options)
if err != nil {
Expand Down Expand Up @@ -323,6 +337,7 @@ func resourceScalrWorkspaceRead(d *schema.ResourceData, meta interface{}) error
d.Set("working_directory", workspace.WorkingDirectory)
d.Set("environment_id", workspace.Environment.ID)
d.Set("has_resources", workspace.HasResources)
d.Set("var_files", workspace.VarFiles)

if workspace.RunOperationTimeout != nil {
d.Set("run_operation_timeout", &workspace.RunOperationTimeout)
Expand Down Expand Up @@ -387,7 +402,8 @@ func resourceScalrWorkspaceUpdate(d *schema.ResourceData, meta interface{}) erro
d.HasChange("terraform_version") || d.HasChange("working_directory") ||
d.HasChange("vcs_repo") || d.HasChange("operations") ||
d.HasChange("vcs_provider_id") || d.HasChange("agent_pool_id") ||
d.HasChange("hooks") || d.HasChange("module_version_id") || d.HasChange("run_operation_timeout") {
d.HasChange("hooks") || d.HasChange("module_version_id") || d.HasChange("var_files") ||
d.HasChange("run_operation_timeout") {
// Create a new options struct.
options := scalr.WorkspaceUpdateOptions{
Name: scalr.String(d.Get("name").(string)),
Expand All @@ -406,6 +422,14 @@ func resourceScalrWorkspaceUpdate(d *schema.ResourceData, meta interface{}) erro
options.TerraformVersion = scalr.String(tfVersion.(string))
}

if v, ok := d.Get("var_files").([]interface{}); ok {
varFiles := make([]string, 0)
for _, varFile := range v {
varFiles = append(varFiles, varFile.(string))
}
options.VarFiles = varFiles
}

options.WorkingDirectory = scalr.String(d.Get("working_directory").(string))

if runOperationTimeout, ok := d.GetOk("run_operation_timeout"); ok {
Expand Down
12 changes: 12 additions & 0 deletions scalr/resource_scalr_workspace_test.go
Expand Up @@ -36,6 +36,10 @@ func TestAccScalrWorkspace_basic(t *testing.T) {
"scalr_workspace.test", "working_directory", ""),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "run_operation_timeout", "18"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "var_files.0", "test1.tfvars"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "var_files.1", "test2.tfvars"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "hooks.0.pre_plan", "./scripts/pre-plan.sh"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -164,6 +168,8 @@ func TestAccScalrWorkspace_update(t *testing.T) {
resource.TestCheckResourceAttr("scalr_workspace.test", "working_directory", ""),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "run_operation_timeout", "18"),
resource.TestCheckResourceAttr("scalr_workspace.test", "var_files.0", "test1.tfvars"),
resource.TestCheckResourceAttr("scalr_workspace.test", "var_files.1", "test2.tfvars"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "hooks.0.pre_plan", "./scripts/pre-plan.sh"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -193,6 +199,10 @@ func TestAccScalrWorkspace_update(t *testing.T) {
"scalr_workspace.test", "working_directory", "terraform/test"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "run_operation_timeout", "200"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "var_files.0", "test1updated.tfvars"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "var_files.1", "test2updated.tfvars"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "hooks.0.pre_plan", "./scripts/pre-plan_updated.sh"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -430,6 +440,7 @@ resource scalr_workspace test {
environment_id = scalr_environment.test.id
auto_apply = true
run_operation_timeout = 18
var_files = ["test1.tfvars", "test2.tfvars"]
hooks {
pre_plan = "./scripts/pre-plan.sh"
post_plan = "./scripts/post-plan.sh"
Expand Down Expand Up @@ -474,6 +485,7 @@ resource "scalr_workspace" "test" {
terraform_version = "0.12.19"
working_directory = "terraform/test"
run_operation_timeout = 200
var_files = ["test1updated.tfvars", "test2updated.tfvars"]
hooks {
pre_plan = "./scripts/pre-plan_updated.sh"
post_plan = "./scripts/post-plan_updated.sh"
Expand Down

0 comments on commit 12ab219

Please sign in to comment.