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

Reset trigger prefixes for workspace resources when removed from the config #138

Merged
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
## 0.15.0 (Unreleased)
## 0.14.1 (Unreleased)
BUG FIXES:

* t/tfe_workspace: Issues with updating `working_directory` ([[#137](https://github.com/terraform-providers/terraform-provider-tfe/pull/137)])
and `trigger_prefixes` ([[#138](https://github.com/terraform-providers/terraform-provider-tfe/pull/138)]) when removed from the configuration.
Special note: if you have workspaces which are configured through the TFE provider, but have set the working directory or trigger prefixes manually, through the UI, you'll need to update your configuration.

## 0.14.0 (February 20, 2020)

FEATURES:
Expand Down
3 changes: 3 additions & 0 deletions tfe/resource_tfe_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ func resourceTFEWorkspaceUpdate(d *schema.ResourceData, meta interface{}) error
for _, tp := range tps.([]interface{}) {
options.TriggerPrefixes = append(options.TriggerPrefixes, tp.(string))
}
} else {
// Reset trigger prefixes when none are present in the config.
options.TriggerPrefixes = []string{}
}

if workingDir, ok := d.GetOk("working_directory"); ok {
Expand Down
64 changes: 64 additions & 0 deletions tfe/resource_tfe_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,42 @@ func TestAccTFEWorkspace_updateFileTriggers(t *testing.T) {
})
}

func TestAccTFEWorkspace_updateTriggerPrefixes(t *testing.T) {
workspace := &tfe.Workspace{}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFEWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccTFEWorkspace_triggerPrefixes,
Check: resource.ComposeTestCheckFunc(
testAccCheckTFEWorkspaceExists(
"tfe_workspace.foobar", workspace),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "trigger_prefixes.#", "2"),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "trigger_prefixes.0", "/modules"),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "trigger_prefixes.1", "/shared"),
),
},

{
Config: testAccTFEWorkspace_updateEmptyTriggerPrefixes,
Check: resource.ComposeTestCheckFunc(
testAccCheckTFEWorkspaceExists(
"tfe_workspace.foobar", workspace),
testAccCheckTFEWorkspaceAttributes(workspace),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "trigger_prefixes.#", "0"),
),
},
},
})
}

func TestAccTFEWorkspace_sshKey(t *testing.T) {
workspace := &tfe.Workspace{}

Expand Down Expand Up @@ -479,6 +515,10 @@ func testAccCheckTFEWorkspaceAttributes(
return fmt.Errorf("Bad working directory: %s", workspace.WorkingDirectory)
}

if len(workspace.TriggerPrefixes) != 0 {
return fmt.Errorf("Bad trigger prefixes: %s", workspace.TriggerPrefixes)
}

return nil
}
}
Expand Down Expand Up @@ -695,6 +735,7 @@ resource "tfe_workspace" "foobar" {
terraform_version = "0.11.1"
trigger_prefixes = ["/modules", "/shared"]
working_directory = "terraform/test"
operations = false
}`

const testAccTFEWorkspace_updateAddWorkingDirectory = `
Expand Down Expand Up @@ -758,3 +799,26 @@ resource "tfe_workspace" "foobar" {
organization = "${tfe_organization.foobar.id}"
auto_apply = true
}`

const testAccTFEWorkspace_triggerPrefixes = `
resource "tfe_organization" "foobar" {
name = "tst-terraform"
email = "admin@company.com"
}

resource "tfe_workspace" "foobar" {
name = "workspace"
organization = "${tfe_organization.foobar.id}"
trigger_prefixes = ["/modules", "/shared"]
}`

const testAccTFEWorkspace_updateEmptyTriggerPrefixes = `
resource "tfe_organization" "foobar" {
name = "tst-terraform"
email = "admin@company.com"
}
resource "tfe_workspace" "foobar" {
name = "workspace-test"
organization = "${tfe_organization.foobar.id}"
auto_apply = true
}`