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

Feature/add trigger patterns #502

Merged
merged 26 commits into from
Jul 8, 2022
Merged

Feature/add trigger patterns #502

merged 26 commits into from
Jul 8, 2022

Conversation

matejrisek
Copy link
Contributor

@matejrisek matejrisek commented May 20, 2022

Description

We're introducing a new field to the workspace model. The field is called trigger-patterns and it is meant to be another way of defining when to trigger a run based on file changes. It is mutually exclusive with trigger-prefixes which is reflect in the provider, as well as on the backend.

Remember to:

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.

@matejrisek matejrisek requested a review from a team May 20, 2022 13:11
file_triggers_enabled = true
trigger_patterns = ["/modules/**/*", "/**/network/*"]
working_directory = "terraform/test"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Although this technically works as a data source test, it would be better to just only the data source. The way to do this is in the test itself TestAccTFEWorkspaceDataSource_with_trigger_patterns, to use the go-tfe client to create a workspace with the trigger patterns, then pass that workspace.name and org.name here in this testAccTFEWorkspaceDataSourceConfigWithTriggerPatterns config to be used as strings in the data source fields (name and organization). Then continue with verifying that the data is the same.

This way you also don't need a depends_on.

for _, tp := range tps.([]interface{}) {
if t, ok := tp.(string); ok {
options.TriggerPrefixes = append(options.TriggerPrefixes, t)
if 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.

This HasChange is needed in create function?

Copy link
Contributor Author

@matejrisek matejrisek May 23, 2022

Choose a reason for hiding this comment

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

Yeah, good point, we'd need https://github.com/hashicorp/go-tfe/pull/410/files merged for that

}
} else {
options.TriggerPatterns = []string{}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So now we've handled all the potential data conflicts over on the API side?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests should prove that since they're hitting the real thing :-)

Yeah on backend we allow for the presence of both trigger-patterns and trigger-prefixes at the same time, but both cannot be populated.

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.

just one test comment, otherwise LGTM

@@ -52,6 +52,7 @@ In addition to all arguments above, the following attributes are exported:
* `tag_names` - The names of tags added to this workspace.
* `terraform_version` - The version (or version constraint) of Terraform used for this workspace.
* `trigger_prefixes` - List of repository-root-relative paths which describe all locations to be tracked for changes.
* `trigger_patterns` - List of repository-root-relative GLOB patterns which describe all locations to be tracked for changes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should probably link to a page explaining GLOB patterns being used here.
We also need the GLOB page for the UI changes currently in work, so once we decide what to link I'll add it here as well.

@sebasslash sebasslash added the feature-flag Features that sit behind a feature flag label Jun 1, 2022
@@ -12,6 +12,8 @@ Provides a workspace resource.

~> **NOTE:** Using `global_remote_state` or `remote_state_consumer_ids` requires using the provider with Terraform Cloud or an instance of Terraform Enterprise at least as recent as v202104-1.

~> **NOTE:** Using `trigger-patterns` requires using the provider with Terraform Cloud.

Choose a reason for hiding this comment

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

I wonder if we could put this under the actual trigger patterns bullet? I also wonder if it needs to be a note, or if we could incorporate it into the bullet text. The reason why is that I'm thinking it'd be easy for someone to kind of skip right to the available attributes and miss this note. I think it'd be more helpful for users to see the information about its requirements in context:

"trigger_prefixes - (Optional) List of prefixes that describe the paths Terraform Cloud monitors for changes, in addition to the working directory. Trigger prefixes are always appended to the root directory of the repository. Terraform Cloud or Terraform Enterprise will start a run when files are changed in any directory path matching the provided set of prefixes. Mutually exclusive with trigger-patterns. Only available for Terraform Cloud."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point -> 8a22a37

Comment on lines 54 to 56
* `trigger_prefixes` - List of trigger prefixes that describe the paths Terraform Cloud monitors for changes, in addition to the working directory. Trigger prefixes are always appended to the root directory of the repository.
Terraform Cloud or Terraform Enterprise will start a run when files are changed in any directory path matching the provided set of prefixes.
* `trigger_patterns` - List of glob patterns that describe the files Terraform Cloud monitors for changes. Trigger patterns are always appended to the root directory of the repository.

Choose a reason for hiding this comment

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

Do we also need to say here that the prefixes are only available for Terraform Cloud?

Also - and feel free to push back here because I don't want to go against what we typically do in these docs, but do we ever provide links to the documentation where folks can find out more about these? Like. wonder if the patterns section could benefit from a link to that new glob patterns section you're adding onto the actual VCS settings page?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll link it once the Atlas documentation is published. This will not be merged for few days at least. Thanks for the suggestion.

@annawinkler
Copy link
Contributor

Does the changelog need to be updated also?

Copy link
Contributor

@annawinkler annawinkler left a comment

Choose a reason for hiding this comment

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

Thank you for submitting this PR! I think we want to update the Changelog too.

@matejrisek
Copy link
Contributor Author

Does the changelog need to be updated also?

@annawinkler sure, thanks for the reminder. 7232415

I think I'll have to update it with a link to glob patterns once the Atlas documentation is published

@annawinkler
Copy link
Contributor

Note: this feature is already in GA. It's in TFC UI and API docs

@sebasslash sebasslash removed the feature-flag Features that sit behind a feature flag label Jul 7, 2022
@annawinkler
Copy link
Contributor

@omarismail This PR is a little hard for folks to test without testing instructions. Wondering if you could contribute a few bullet points?

Things that I've collected:

  • We've got this related go-tfe PR
  • The API docs are here

@omarismail
Copy link
Contributor

omarismail commented Jul 7, 2022

Testing Plan

  1. Create a new config with
terraform {
  required_providers {
    tfe = {
      version = "~> 0.25.0"
    }
  }
}

provider "tfe" {
  hostname = "app.terraform.io"
  token    = "<atlas-token>"
}

resource "tfe_organization" "foobar" {
  name  = "tst-terraform-random-name"
  email = "admin@company.com"
}
resource "tfe_workspace" "foobar" {
  name             = "workspace-test"
  organization     = tfe_organization.foobar.id
  auto_apply       = true
  trigger_prefixes = []
}
  1. Then terraform apply it.
  2. Then go into TFC -> Newly created workspace -> Settings. Validate that the trigger_prefixes are empty
  3. Then modify the config resource "tfe_workspace" "foobar" { to be
resource "tfe_workspace" "foobar" {
  name             = "workspace-test"
  organization     = tfe_organization.foobar.id
  auto_apply       = true
  trigger_prefixes = ["submodules/**"]
}
  1. then terraform apply it.
  2. Then go back into that same Worksapce -> Settings and verify that the trigger_prefixes are set to "submodules/**"
  3. Then remove the field trigger_prefixes from the tfe_workspace resource, and go back to Workspace Settings to verify its removed.

@annawinkler
Copy link
Contributor

For folks who test, make sure you follow the steps to build the provider manually, then update the dev overrides in your .terraformrc:

provider_installation {
  dev_overrides {
    "hashicorp/tfe" = "/Users/YOURNAME/go/bin"
  }
  direct {}
}

Copy link
Contributor

@annawinkler annawinkler left a comment

Choose a reason for hiding this comment

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

🌟 Looks good! Thank you for the testing steps. Let's make sure to squash the commits.

@omarismail omarismail merged commit 33de91d into main Jul 8, 2022
@omarismail omarismail deleted the feature/add-trigger-patterns branch July 8, 2022 16:12
matejrisek added a commit that referenced this pull request Jul 20, 2022
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.

5 participants