-
Notifications
You must be signed in to change notification settings - Fork 160
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
[FR] {r,d}/tfe_workspace_run #534
Comments
@drewmullen Hey, Drew. Thanks for the recent interesting contribution and FR! I'm thinking through the use case that you described, specifically:
Can you give me a little more detail about how this works? When an auto-apply, VCS-connected workspace is created, my understanding was that you have to trigger the very first run and that it doesn't happen automatically. Is this run triggered in another way? Perhaps with workspace run triggers? |
Hi @brandonc ! So in my case I have a set of workspaces that each connect to a VCS thats pre-registered in my organization. when it does, the apply is launched. i assume its auto launching because i have heres an example of the workspace state: $ terraform state show 'module.multi_region_deployment.tfe_workspace.main["eastcoast"]'
# module.multi_region_deployment.tfe_workspace.main["eastcoast"]:
resource "tfe_workspace" "main" {
allow_destroy_plan = true
auto_apply = true
execution_mode = "remote"
file_triggers_enabled = true
global_remote_state = false
id = <>
name = "eastcoast"
operations = true
organization = <>
queue_all_runs = true
remote_state_consumer_ids = []
speculative_enabled = true
structured_run_output_enabled = true
tag_names = []
terraform_version = "1.2.3"
trigger_prefixes = []
vcs_repo {
branch = <>
identifier = <>
ingress_submodules = false
oauth_token_id = <>
}
} |
I believe the Run is automatically triggered upon Workspace creation because https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/workspace#queue_all_runs |
Thanks @alexbasista I appreciate you pointing that out! If this proposal is approved then I probably would flip that to false on new workspaces and let this new resource perform the first "manual" apply Any thoughts from the developers on if this kind of PR would be accepted? |
I have a superficial objection to this specific proposal because it highlights the resource as a side effect (triggering a run on a workspace) and not really a resource under management. It's not clear when or how the resource as you defined it interacts with CRUD operations. On the other hand, a run is a first class resource in TFE and I'd like some time to evaluate how to structure it and speak to some colleagues about the possibility. Some questions that spring to mind about a
The problem of automatically applying a workspace that is missing a varset does feel like a legitimate gap, though. We don't have the API support to specify varsets when creating a workspace, which would easily solve this. Until then, I've been trying to devise an escape hatch that solves this issue. The only thing I've come up with involves external which has very few guarantees in Terraform Enterprise. |
Thank you for your consideration and input!
# proposed new argument
# whether resource completion should wait for the apply to be complete (successful) or should just fire the job and continue on
wait_for_completion = bool
100% agree. I was heavily influenced by the {r/ds}/ Another question I have is whether |
aws_lambda_invocation is a very interesting data source to consider. If I may contrast it with what we're proposing: aws_lambda_invocation represents an invocation as a read operation (the result of the function) which conceptually is a lot cleaner than what we are proposing, which is queuing a run every time a read operation happens. Queuing a run has more known side effects (like blocking other runs) and there is no clear data output to be read. So far, I've been more focused on the run as a resource, because the create action maps more cleanly to what is taking place in Terraform Cloud/Enterprise. Other thoughts:
Runs can be discarded/canceled/force canceled and these might be good candidates for destroy. If a tfe_run resource did depend on existing config, that would be the most flexible design because it would allow for the existence of a tfe_configuration_version later on. Tomorrow I'm going to finish testing your workspace varset attachment PR and I'll get back to this after that. Thanks again. |
just to clarify, there is both a data source & a resource for lambda invocation. I'm personally more interested in the resource for |
I was checking issues to see if I should report this resource race condition. We also attach varsets and leave default queue_all_runs = true. We'd have to override default value of queue_all_runs to false if we don't want to see workspaces fail on first run. We do not want our users to see errors. My opinion is behavior of this default value queue_all_runs = true should wait for the variables and varsets to be added before completion. |
Wanted to follow up on this to see if theres any input from the team, @brandonc ? Also - thank you for adopting that PR for the latest release! love the new functionality. Here is the module that is the impetus of that issue and this one too. |
I know that some people are leveraging this provider which will trigger a run on the workspace. They would declare a |
Having had some time to consider, I do believe that a more narrowly focused logical provider like multispace would be a better solution for this. |
Much of this was fixed when the tfe provider was updated to include attaching var_sets and policy_sets, things outside of the workspace resource that we needed attached prior to the first run. Before that we had to use depends_on with local_exec python scripts, and this caused other complications. |
Use-cases
We have situations where we create multiple workspaces based on the same repo to deploy the same configuration in many aws regions. when the workspace is created it automatically kicks off an apply which sometimes fails due to race condition with adding the variable set to the workspace.
Attempted Solutions
n/a
Proposal
Create a new resource and a data source that can trigger an apply on a workspace. The resource is useful for situations where you only want to apply once. The data source fire an apply every time the root is run
Links:
The text was updated successfully, but these errors were encountered: