Skip to content

Commit

Permalink
Merge pull request #220 from terraform-providers/import_branch
Browse files Browse the repository at this point in the history
Import branch
  • Loading branch information
koikonom authored Sep 30, 2020
2 parents 79892b5 + e105e7a commit 3dfe1e8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
12 changes: 1 addition & 11 deletions tfe/resource_tfe_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,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,
"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 @@ -502,6 +502,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

0 comments on commit 3dfe1e8

Please sign in to comment.