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

Import branch #220

merged 3 commits into from
Sep 30, 2020

Conversation

koikonom
Copy link
Contributor

@koikonom koikonom commented Sep 21, 2020

Description

Importing a workspace with a non-default branch fails to import the branch.

Output from acceptance tests

Please run the full suite of acceptance tests locally and include the output here.

PASS tfe.TestAccTFEWorkspace_importVCSBranch (4.10s)
...

@ghost ghost added size/XS and removed size/XS labels Sep 21, 2020
@koikonom koikonom marked this pull request as ready for review September 21, 2020 18:48
@@ -163,6 +163,7 @@ func resourceTFEWorkspaceCreate(d *schema.ResourceData, meta interface{}) error

options.VCSRepo = &tfe.VCSRepoOptions{
Identifier: tfe.String(vcsRepo["identifier"].(string)),
Branch: tfe.String(vcsRepo["branch"].(string)),
Copy link
Contributor

Choose a reason for hiding this comment

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

does this override the conditional setting of branch on lines 171-175?
it seemed like previously, this was attempting to only set the branch if it was actually set in the config.
i'm pretty sure it will work either way but i think we might want to pick one way or the other and remove the redundant code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right on this one, I missed it on the initial review because the diff was too short :) Good catch!

@@ -231,6 +232,7 @@ 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!

The Create method was already adding the branch name.
The Read method on the other hand was conditionally updating
the branch value based on the TF config, which was causing issues
when importing branches.
Copy link
Contributor

@lafentres lafentres left a comment

Choose a reason for hiding this comment

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

this looks great to me! imported and created some workspaces locally and everything worked as expected 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants