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

Ensure that changes are applied for monorepos #81

Merged
merged 1 commit into from
Jun 26, 2019
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
3 changes: 2 additions & 1 deletion tfe/resource_tfe_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ func resourceTFEWorkspaceUpdate(d *schema.ResourceData, meta interface{}) error
}

if d.HasChange("name") || d.HasChange("auto_apply") || d.HasChange("queue_all_runs") ||
d.HasChange("terraform_version") || d.HasChange("working_directory") || d.HasChange("vcs_repo") {
d.HasChange("terraform_version") || d.HasChange("working_directory") || d.HasChange("vcs_repo") ||
d.HasChange("file_triggers_enabled") || d.HasChange("trigger_prefixes") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it makes more sense to write this check as if !d.HasChange(“ssh_key_id”)?

If this method gets called it means something changed, and the only special case seems to be the SSH key stuff.

Copy link
Contributor Author

@alisdair alisdair Jun 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would prevent updates to any other fields at the same time as SSH key changes, which seems incorrect.

Edit: I do agree that this condition is a footgun, but I can't think of any clear way of avoiding it, other than removing the conditional and always making the PATCH request.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes... You are correct on that one 👍🏻I'll silence myself 😉

// Create a new options struct.
options := tfe.WorkspaceUpdateOptions{
Name: tfe.String(d.Get("name").(string)),
Expand Down
44 changes: 44 additions & 0 deletions tfe/resource_tfe_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,37 @@ func TestAccTFEWorkspace_update(t *testing.T) {
})
}

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

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckTFEWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccTFEWorkspace_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckTFEWorkspaceExists(
"tfe_workspace.foobar", workspace),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "file_triggers_enabled", "true"),
),
},

{
Config: testAccTFEWorkspace_basicFileTriggersOff,
Check: resource.ComposeTestCheckFunc(
testAccCheckTFEWorkspaceExists(
"tfe_workspace.foobar", workspace),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "file_triggers_enabled", "false"),
),
},
},
})
}

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

Expand Down Expand Up @@ -506,6 +537,19 @@ resource "tfe_workspace" "foobar" {
auto_apply = true
}`

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

resource "tfe_workspace" "foobar" {
name = "workspace-test"
organization = "${tfe_organization.foobar.id}"
auto_apply = true
file_triggers_enabled = false
}`

const testAccTFEWorkspace_monorepo = `
resource "tfe_organization" "foobar" {
name = "terraform-test"
Expand Down