From d759741952ed32696cfdfae70a0a1a92d25ab00b Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Sat, 3 Nov 2018 15:45:09 +0100 Subject: [PATCH] Fix a bug that prevented to set auto-apply to false --- tfe/resource_tfe_workspace.go | 16 +++++----------- tfe/resource_tfe_workspace_test.go | 13 +++++++------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/tfe/resource_tfe_workspace.go b/tfe/resource_tfe_workspace.go index 5ac123ea8..73000bc36 100644 --- a/tfe/resource_tfe_workspace.go +++ b/tfe/resource_tfe_workspace.go @@ -34,7 +34,7 @@ func resourceTFEWorkspace() *schema.Resource { "auto_apply": &schema.Schema{ Type: schema.TypeBool, Optional: true, - Computed: true, + Default: false, }, "terraform_version": &schema.Schema{ @@ -97,14 +97,11 @@ func resourceTFEWorkspaceCreate(d *schema.ResourceData, meta interface{}) error // Create a new options struct. options := tfe.WorkspaceCreateOptions{ - Name: tfe.String(name), + Name: tfe.String(name), + AutoApply: tfe.Bool(d.Get("auto_apply").(bool)), } // Process all configured options. - if autoApply, ok := d.GetOk("auto_apply"); ok { - options.AutoApply = tfe.Bool(autoApply.(bool)) - } - if tfVersion, ok := d.GetOk("terraform_version"); ok { options.TerraformVersion = tfe.String(tfVersion.(string)) } @@ -222,14 +219,11 @@ func resourceTFEWorkspaceUpdate(d *schema.ResourceData, meta interface{}) error // Create a new options struct. options := tfe.WorkspaceUpdateOptions{ - Name: tfe.String(d.Get("name").(string)), + Name: tfe.String(d.Get("name").(string)), + AutoApply: tfe.Bool(d.Get("auto_apply").(bool)), } // Process all configured options. - if autoApply, ok := d.GetOk("auto_apply"); ok { - options.AutoApply = tfe.Bool(autoApply.(bool)) - } - if tfVersion, ok := d.GetOk("terraform_version"); ok { options.TerraformVersion = tfe.String(tfVersion.(string)) } diff --git a/tfe/resource_tfe_workspace_test.go b/tfe/resource_tfe_workspace_test.go index de7cb81c5..3e91fd1c8 100644 --- a/tfe/resource_tfe_workspace_test.go +++ b/tfe/resource_tfe_workspace_test.go @@ -106,7 +106,7 @@ func TestAccTFEWorkspace_basic(t *testing.T) { resource.TestCheckResourceAttr( "tfe_workspace.foobar", "name", "workspace-test"), resource.TestCheckResourceAttr( - "tfe_workspace.foobar", "auto_apply", "false"), + "tfe_workspace.foobar", "auto_apply", "true"), resource.TestCheckResourceAttr( "tfe_workspace.foobar", "working_directory", ""), ), @@ -132,7 +132,7 @@ func TestAccTFEWorkspace_update(t *testing.T) { resource.TestCheckResourceAttr( "tfe_workspace.foobar", "name", "workspace-test"), resource.TestCheckResourceAttr( - "tfe_workspace.foobar", "auto_apply", "false"), + "tfe_workspace.foobar", "auto_apply", "true"), resource.TestCheckResourceAttr( "tfe_workspace.foobar", "working_directory", ""), ), @@ -147,7 +147,7 @@ func TestAccTFEWorkspace_update(t *testing.T) { resource.TestCheckResourceAttr( "tfe_workspace.foobar", "name", "workspace-updated"), resource.TestCheckResourceAttr( - "tfe_workspace.foobar", "auto_apply", "true"), + "tfe_workspace.foobar", "auto_apply", "false"), resource.TestCheckResourceAttr( "tfe_workspace.foobar", "terraform_version", "0.11.1"), resource.TestCheckResourceAttr( @@ -224,7 +224,7 @@ func testAccCheckTFEWorkspaceAttributes( return fmt.Errorf("Bad name: %s", workspace.Name) } - if workspace.AutoApply != false { + if workspace.AutoApply != true { return fmt.Errorf("Bad auto apply: %t", workspace.AutoApply) } @@ -243,7 +243,7 @@ func testAccCheckTFEWorkspaceAttributesUpdated( return fmt.Errorf("Bad name: %s", workspace.Name) } - if workspace.AutoApply != true { + if workspace.AutoApply != false { return fmt.Errorf("Bad auto apply: %t", workspace.AutoApply) } @@ -295,6 +295,7 @@ resource "tfe_organization" "foobar" { resource "tfe_workspace" "foobar" { name = "workspace-test" organization = "${tfe_organization.foobar.id}" + auto_apply = true }` const testAccTFEWorkspace_update = ` @@ -306,7 +307,7 @@ resource "tfe_organization" "foobar" { resource "tfe_workspace" "foobar" { name = "workspace-updated" organization = "${tfe_organization.foobar.id}" - auto_apply = true + auto_apply = false terraform_version = "0.11.1" working_directory = "terraform/test" }`