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

Import branch #220

Merged
merged 3 commits into from
Sep 30, 2020
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
12 changes: 1 addition & 11 deletions tfe/resource_tfe_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,10 @@ func resourceTFEWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
if workspace.VCSRepo != nil {
vcsConfig := map[string]interface{}{
"identifier": workspace.VCSRepo.Identifier,
"branch": workspace.VCSRepo.Branch,
Copy link
Contributor

Choose a reason for hiding this comment

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

sort of the same question here as the one above. i think the goal is to only set the branch if we actually get one back from the API request and it isn't "". there's clearly something wrong with the way we were attempting to do this before but i'm not sure what

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case we should remove the if block below. Read()'s result should not be affected by the HCL config at all, instead it should be reporting what the resource actually looks like.

I'll update this PR shortly!

"ingress_submodules": workspace.VCSRepo.IngressSubmodules,
"oauth_token_id": workspace.VCSRepo.OAuthTokenID,
}

// Get and assert the VCS repo configuration block.
if v, ok := d.GetOk("vcs_repo"); ok {
if vcsRepo, ok := v.([]interface{})[0].(map[string]interface{}); ok {
// Only set the branch if one is configured.
if branch, ok := vcsRepo["branch"].(string); ok && branch != "" {
vcsConfig["branch"] = workspace.VCSRepo.Branch
}
}
}

vcsRepo = append(vcsRepo, vcsConfig)
}

Expand Down
45 changes: 45 additions & 0 deletions tfe/resource_tfe_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,51 @@ func TestAccTFEWorkspace_import(t *testing.T) {
})
}

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

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
if GITHUB_TOKEN == "" {
t.Skip("Please set GITHUB_TOKEN to run this test")
}
if GITHUB_WORKSPACE_IDENTIFIER == "" {
t.Skip("Please set GITHUB_WORKSPACE_IDENTIFIER to run this test")
}
if GITHUB_WORKSPACE_BRANCH == "" {
t.Skip("Please set GITHUB_WORKSPACE_BRANCH to run this test")
}

},
Providers: testAccProviders,
CheckDestroy: testAccCheckTFEWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccTFEWorkspace_updateUpdateVCSRepoBranch,
Check: resource.ComposeTestCheckFunc(
testAccCheckTFEWorkspaceExists("tfe_workspace.foobar", workspace),
testAccCheckTFEWorkspaceUpdatedUpdateVCSRepoBranchAttributes(workspace),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "name", "workspace-test-update-vcs-repo-branch"),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "vcs_repo.0.identifier", GITHUB_WORKSPACE_IDENTIFIER),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "vcs_repo.0.branch", GITHUB_WORKSPACE_BRANCH),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "vcs_repo.0.ingress_submodules", "false"),
),
},

{
ResourceName: "tfe_workspace.foobar",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckTFEWorkspaceExists(
n string, workspace *tfe.Workspace) resource.TestCheckFunc {
return func(s *terraform.State) error {
Expand Down