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

Fix a bug that prevented to set auto-apply to false #30

Merged
merged 1 commit into from
Nov 3, 2018
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
16 changes: 5 additions & 11 deletions tfe/resource_tfe_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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))
}
Expand Down
13 changes: 7 additions & 6 deletions tfe/resource_tfe_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""),
),
Expand All @@ -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", ""),
),
Expand All @@ -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(
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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 = `
Expand All @@ -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"
}`