Skip to content

Commit

Permalink
Merge pull request #185 from Scalr/fix/SCALRCORE-23652
Browse files Browse the repository at this point in the history
SCALRCORE-23652 - Workspaces > Auto-queue runs
  • Loading branch information
emocharnik committed Oct 17, 2022
2 parents dbb4053 + 9cd4ad0 commit 55369f2
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 13 deletions.
9 changes: 8 additions & 1 deletion docs/data-sources/scalr_workspace.md
Expand Up @@ -37,7 +37,14 @@ All arguments plus:
* `vcs_repo` - If a workspace is linked to a VCS repository this block shows the details, otherwise `{}`
* `created_by` - Details of the user that created the workspace.
* `has_resources` - The presence of active terraform resources in the current state version.
* `auto_queue_runs` - Indicates if runs have to be queued automatically when a new configuration version is uploaded.
* `auto_queue_runs` - Indicates if runs have to be queued automatically when a new configuration version is uploaded.

Supported values are `skip_first`, `always`, `never`:

* `skip_first` - after the very first configuration version is uploaded into the workspace the run will not be triggered. But the following configurations will do. This is the default behavior.
* `always` - runs will be triggered automatically on every upload of the configuration version.
* `never` - configuration versions are uploaded into the workspace, but runs will not be triggered.

* `hooks` - List of custom hooks in a workspace.

The `hooks` block supports:
Expand Down
9 changes: 8 additions & 1 deletion docs/resources/scalr_workspace.md
Expand Up @@ -96,7 +96,14 @@ resource "scalr_workspace" "cli-driven" {
* `auto_apply` - (Optional) Set (true/false) to configure if `terraform apply` should automatically run when `terraform plan` ends without error. Default `false`.
* `force_latest_run` - (Optional) Set (true/false) to configure if latest new run will be automatically raised in priority. Default `false`.
* `operations` - Deprecated. Use `execution-mode` instead.
* `auto_queue_runs` - (Optional) Indicates if runs have to be queued automatically when a new configuration version is uploaded.
* `auto_queue_runs` - Indicates if runs have to be queued automatically when a new configuration version is uploaded.

Supported values are `skip_first`, `always`, `never`:

* `skip_first` - after the very first configuration version is uploaded into the workspace the run will not be triggered. But the following configurations will do. This is the default behavior.
* `always` - runs will be triggered automatically on every upload of the configuration version.
* `never` - configuration versions are uploaded into the workspace, but runs will not be triggered.

* `execution-mode` - (Optional) 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).
* `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 `""`.
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-20221006121629-1ad602533b2a
github.com/scalr/go-scalr v0.0.0-20221017093222-a55f66132481
)

require (
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Expand Up @@ -302,6 +302,10 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/scalr/go-scalr v0.0.0-20221006121629-1ad602533b2a h1:FXk5I5opUwGEpx61L+iCyroXIF+C+KUp7uQxdF21gaY=
github.com/scalr/go-scalr v0.0.0-20221006121629-1ad602533b2a/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20221013183921-cfda501ccab8 h1:ghmHzTKdE/TIoxS2VdXU97Kjl0h8q9o982iWbtB7nQM=
github.com/scalr/go-scalr v0.0.0-20221013183921-cfda501ccab8/go.mod h1:xMnwfer9UxugeNITZjTpQBwQ/4bw6/JdyDLpGdmyorE=
github.com/scalr/go-scalr v0.0.0-20221017093222-a55f66132481 h1:2k89jDfme5jPSUxp+TOBku3tryg/C0jEyoVjz+acyxU=
github.com/scalr/go-scalr v0.0.0-20221017093222-a55f66132481/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
2 changes: 1 addition & 1 deletion scalr/data_source_workspace.go
Expand Up @@ -73,7 +73,7 @@ func dataSourceScalrWorkspace() *schema.Resource {
},

"auto_queue_runs": {
Type: schema.TypeBool,
Type: schema.TypeString,
Computed: true,
},

Expand Down
2 changes: 2 additions & 0 deletions scalr/data_source_workspace_test.go
Expand Up @@ -26,6 +26,8 @@ func TestAccScalrWorkspaceDataSource_basic(t *testing.T) {
"data.scalr_workspace.test", "terraform_version", "0.12.19"),
resource.TestCheckResourceAttr(
"data.scalr_workspace.test", "working_directory", "terraform/test"),
resource.TestCheckResourceAttr(
"data.scalr_workspace.test", "auto_queue_runs", "skip_first"),
resource.TestCheckResourceAttrSet("data.scalr_workspace.test", "environment_id"),
resource.TestCheckResourceAttrSet("data.scalr_workspace.test", "has_resources"),
resource.TestCheckResourceAttrSet("data.scalr_workspace.test", "created_by.0.full_name"),
Expand Down
26 changes: 22 additions & 4 deletions scalr/resource_scalr_workspace.go
Expand Up @@ -167,9 +167,17 @@ func resourceScalrWorkspace() *schema.Resource {
},

"auto_queue_runs": {
Type: schema.TypeBool,
Type: schema.TypeString,
Optional: true,
Default: nil,
ValidateFunc: validation.StringInSlice(
[]string{
string(scalr.AutoQueueRunsModeSkipFirst),
string(scalr.AutoQueueRunsModeAlways),
string(scalr.AutoQueueRunsModeNever),
},
false,
),
Default: string(scalr.AutoQueueRunsModeSkipFirst),
},

"vcs_repo": {
Expand Down Expand Up @@ -298,7 +306,6 @@ func resourceScalrWorkspaceCreate(d *schema.ResourceData, meta interface{}) erro
ForceLatestRun: scalr.Bool(d.Get("force_latest_run").(bool)),
Environment: &scalr.Environment{ID: environmentID},
Hooks: &scalr.HooksOptions{},
AutoQueueRuns: scalr.Bool(d.Get("auto_queue_runs").(bool)),
}

// Process all configured options.
Expand All @@ -312,6 +319,12 @@ func resourceScalrWorkspaceCreate(d *schema.ResourceData, meta interface{}) erro
)
}

if autoQueueRunsI, ok := d.GetOk("auto_queue_runs"); ok {
options.AutoQueueRuns = scalr.AutoQueueRunsModePtr(
scalr.WorkspaceAutoQueueRuns(autoQueueRunsI.(string)),
)
}

if tfVersion, ok := d.GetOk("terraform_version"); ok {
options.TerraformVersion = scalr.String(tfVersion.(string))
}
Expand Down Expand Up @@ -552,7 +565,6 @@ func resourceScalrWorkspaceUpdate(d *schema.ResourceData, meta interface{}) erro
Name: scalr.String(d.Get("name").(string)),
AutoApply: scalr.Bool(d.Get("auto_apply").(bool)),
ForceLatestRun: scalr.Bool(d.Get("force_latest_run").(bool)),
AutoQueueRuns: scalr.Bool(d.Get("auto_queue_runs").(bool)),
Hooks: &scalr.HooksOptions{
PreInit: scalr.String(""),
PrePlan: scalr.String(""),
Expand All @@ -573,6 +585,12 @@ func resourceScalrWorkspaceUpdate(d *schema.ResourceData, meta interface{}) erro
)
}

if autoQueueRunsI, ok := d.GetOk("auto_queue_runs"); ok {
options.AutoQueueRuns = scalr.AutoQueueRunsModePtr(
scalr.WorkspaceAutoQueueRuns(autoQueueRunsI.(string)),
)
}

if tfVersion, ok := d.GetOk("terraform_version"); ok {
options.TerraformVersion = scalr.String(tfVersion.(string))
}
Expand Down
16 changes: 11 additions & 5 deletions scalr/resource_scalr_workspace_test.go
Expand Up @@ -34,7 +34,7 @@ func TestAccScalrWorkspace_basic(t *testing.T) {
resource.TestCheckResourceAttr(
"scalr_workspace.test", "operations", "true"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "auto_queue_runs", "true"),
"scalr_workspace.test", "auto_queue_runs", string(scalr.AutoQueueRunsModeAlways)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "execution_mode", string(scalr.WorkspaceExecutionModeRemote)),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestAccScalrWorkspace_monorepo(t *testing.T) {
resource.TestCheckResourceAttr(
"scalr_workspace.test", "operations", "true"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "auto_queue_runs", "false"),
"scalr_workspace.test", "auto_queue_runs", string(scalr.AutoQueueRunsModeNever)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "execution_mode", string(scalr.WorkspaceExecutionModeRemote)),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -138,6 +138,8 @@ func TestAccScalrWorkspace_renamed(t *testing.T) {
"scalr_workspace.test", "operations", "true"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "execution_mode", string(scalr.WorkspaceExecutionModeRemote)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "auto_queue_runs", string(scalr.AutoQueueRunsModeAlways)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "working_directory", ""),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -169,6 +171,8 @@ func TestAccScalrWorkspace_renamed(t *testing.T) {
"scalr_workspace.test", "operations", "true"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "execution_mode", string(scalr.WorkspaceExecutionModeRemote)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "auto_queue_runs", string(scalr.AutoQueueRunsModeAlways)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "working_directory", ""),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -205,6 +209,8 @@ func TestAccScalrWorkspace_update(t *testing.T) {
resource.TestCheckResourceAttr("scalr_workspace.test", "operations", "true"),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "execution_mode", string(scalr.WorkspaceExecutionModeRemote)),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "auto_queue_runs", string(scalr.AutoQueueRunsModeAlways)),
resource.TestCheckResourceAttr("scalr_workspace.test", "working_directory", ""),
resource.TestCheckResourceAttr(
"scalr_workspace.test", "run_operation_timeout", "18"),
Expand Down Expand Up @@ -661,7 +667,7 @@ resource scalr_workspace test {
auto_apply = true
run_operation_timeout = 18
var_files = ["test1.tfvars", "test2.tfvars"]
auto_queue_runs = true
auto_queue_runs = "always"
hooks {
pre_init = "./scripts/pre-init.sh"
pre_plan = "./scripts/pre-plan.sh"
Expand All @@ -678,7 +684,7 @@ resource "scalr_workspace" "test" {
name = "workspace-monorepo"
environment_id = scalr_environment.test.id
working_directory = "/db"
auto_queue_runs = false
auto_queue_runs = "never"
}`)
}

Expand All @@ -688,8 +694,8 @@ resource "scalr_workspace" "test" {
name = "renamed-out-of-band"
environment_id = scalr_environment.test.id
auto_apply = true
auto_queue_runs = true
run_operation_timeout = 18
auto_queue_runs = "always"
hooks {
pre_init = "./scripts/pre-init.sh"
pre_plan = "./scripts/pre-plan.sh"
Expand Down

0 comments on commit 55369f2

Please sign in to comment.