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

Add Git tags support #549

Merged
merged 8 commits into from Aug 11, 2022
Merged

Add Git tags support #549

merged 8 commits into from Aug 11, 2022

Conversation

hashimoon
Copy link
Contributor

@hashimoon hashimoon commented Jul 12, 2022

Description

Adding support to Git Tags

Testing plan

Use resource like the following:

locals {
  organization = "..."
  oauth_token_id = "..."
  identifier = "user/repo
}

resource "tfe_workspace" "my-workspace" {
  name                  = "my-workspace"
  organization          = local.organization
  allow_destroy_plan    = true
  auto_apply            = true
  execution_mode        = "remote"
  speculative_enabled   = true
  file_triggers_enabled = false

  vcs_repo {
    identifier         = local.identifier
    ingress_submodules = false
    oauth_token_id = local.oauth_token_id
    tags_regex = "^\\d+.\\d+.\\d+$" # semantic versioning
  }
}
  1. Verify the correct settings were set in TF Cloud/TFE VCS settings for the workspace that git tags semantic versioning is selected
    • Release a new tagged release in the repo specified in local.identifier
    • See a new run has been trigged
  2. Change configuration to the following
locals {
  organization = "..." # set
  oauth_token_id = "..." # set
  identifier = "user/repo
  working_directory = "..." # set
}

resource "tfe_workspace" "my-workspace" {
  name                  = "my-workspace"
  organization          = local.organization
  allow_destroy_plan    = true
  auto_apply            = true
  execution_mode        = "remote"
  speculative_enabled   = true
  file_triggers_enabled = true
  working_directory = local.working_directory

  vcs_repo {
    identifier         = local.identifier
    ingress_submodules = false
    oauth_token_id = local.oauth_token_id
  }
}
  1. Terraform plan/apply succeeds
  2. Verify in TF Cloud/TFE in VCS settings git tags is not selected.

External links

Include any links here that might be helpful for people reviewing your PR. If there are none, feel free to delete this section.

Output from acceptance tests

Please run applicable acceptance tests locally and include the output here. See TESTS.md to learn how to run acceptance tests.

If you are an external contributor, your contribution(s) will first be reviewed before running them against the project's CI pipeline.

$ TESTARGS="-run TestAccTFEWorkspace" make testacc

...

@hashimoon hashimoon force-pushed the hashimoon/git-tags branch 3 times, most recently from c238c0b to e108cd9 Compare July 12, 2022 19:39
@hashimoon hashimoon marked this pull request as ready for review July 12, 2022 19:45
Copy link
Contributor

@omarismail omarismail left a comment

Choose a reason for hiding this comment

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

Overall looks good, but we should add a number of tests for this

@hashimoon hashimoon force-pushed the hashimoon/git-tags branch 3 times, most recently from e75a1fb to ac02684 Compare July 14, 2022 00:11
Copy link
Contributor

@omarismail omarismail left a comment

Choose a reason for hiding this comment

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

great addition of tests, just one more change needed to use ConflictsWith to keep consistent with the API

@hashimoon hashimoon force-pushed the hashimoon/git-tags branch 2 times, most recently from 0a4a33a to e209606 Compare July 14, 2022 18:49
Copy link
Contributor

@omarismail omarismail left a comment

Choose a reason for hiding this comment

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

lgtm! I think there are some test failures tho

@hashimoon
Copy link
Contributor Author

great addition of tests, just one more change needed to use ConflictsWith to keep consistent with the API

Is ConflictsWith going to be applicable if we need to set the other values as nil/[]? @omarismail

@hashimoon hashimoon force-pushed the hashimoon/git-tags branch 7 times, most recently from 3c74d85 to c9c5f88 Compare July 16, 2022 02:29
@hashimoon hashimoon requested a review from a team as a code owner July 18, 2022 18:42
@brandonc
Copy link
Collaborator

@omarismail @hashimoon Do you think it would be best to land this after the beta flag is removed and the feature is GA?

@hashimoon hashimoon force-pushed the hashimoon/git-tags branch 2 times, most recently from 75a1f96 to d55c76c Compare July 19, 2022 02:08
@@ -95,6 +95,12 @@ func resourceTfeWorkspaceResourceV0() *schema.Resource {
Type: schema.TypeString,
Required: true,
},

"tags_regex": {
Copy link
Contributor

Choose a reason for hiding this comment

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

learning: What do we actually migrate here? I would argue that v0 of workspace didn't have tags_regex. I might be wrong about the purpose of migrations in the tfe provider.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I don't think we need this. This is called from here and its about state migration. We don't have tags_regex for in state, so no need to migrate anything.

@hashimoon hashimoon marked this pull request as draft July 20, 2022 18:21
},
},
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add another test where we start a new config without tags_regex, then add it, then delete it

@@ -124,6 +124,7 @@ The `vcs_repo` block supports:
cloning the VCS repository. Defaults to `false`.
* `oauth_token_id` - (Required) The VCS Connection (OAuth Connection + Token) to use.
This ID can be obtained from a `tfe_oauth_client` resource.
* `tags_regex` - (Optional) A regular expression used to trigger a Workspace run for matching Git tags.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add that this conflicts with trigger_patterns and trigger_prefixes

Copy link
Contributor

@omarismail omarismail left a comment

Choose a reason for hiding this comment

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

A couple comments regarding:

  1. Adding another test
  2. removing the migration
  3. updating docs

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
if GITHUB_TOKEN == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is third time these checks are repeated in this file, IMHO it warrants method extraction

@mjyocca mjyocca marked this pull request as ready for review August 10, 2022 19:22
@mjyocca
Copy link
Contributor

mjyocca commented Aug 10, 2022

Updating go-tfe package with pr fixes the current broken test

Copy link
Contributor

@omarismail omarismail left a comment

Choose a reason for hiding this comment

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

lgtm!

@mjyocca mjyocca requested a review from brandonc August 11, 2022 18:15
@brandonc
Copy link
Collaborator

I re-ran the tests in SSH so I could extract the GITHUB_WORKSPACE config and cancelling it caused the CI failure. I will straighten it out!

Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

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

Works well!

I had some trouble removing the entire vcs_repo config. This did not seem to delete the ingress trigger from the workspace, so tags_regex continues to trigger conflicts with trigger_prefixes etc. I think this problem is not specific to git_tags and probably is a separate provider bug.

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.

None yet

5 participants