How to force trigger Terraform execution for resource which has not changed?

Hi,

I would need an advise on the following.
My team is implementing a Provider which has a resource called “workflow_execution” (example below). We need to enable the users of this Provider to trigger the execution of the resource whenever they would like, regardless if there are any changes to the attributes defined in it or not. Currently we do it by exposing a “triggers” attribute. The user must override the previously used value if he would like to start the execution. It is not ideal, to ask for a random value to ensure that the Terraform execution will be triggered. Ideally “triggers” = “true”/”false” would be the more user friendly approach but we didn’t find a way to make it work, since once the user sets it to “true” and executes, if he wants to execute again the value is unchanged and Terraform doesn’t detect any differences. Is there a way to handle this situation more gracefully?

resource "workflow_execution" "my_execution" {
  triggers                     = "value" 
  application                  = "application" 
  workflow                     = "workflow name" 
  package                      = "package" 
  deployment_profile           = "deployment_profile" 
  manual_approval              = "true" 
  approver                     = "JS"
  schedule                     = "2019-12-28T13:44:00Z"  
  override_existing_components = "false"
}

Thanks,
Jeny

Using the random resource might work for you?

resource "random_id" "random" {
  keepers = {
    uuid = uuid()
  }
  byte_length = 8
}
resource "workflow_execution" "my_execution" {
  triggers = random_id.random.hex
  …
}

Hi Paul,
Thanks for the suggestion. Maybe I was not completely clear on what I would like to achieve. I would like to have just a boolean “triggers” and the workflow_execution to be created only when it is set to “true”. If I use the “random_id” it will always trigger the resource creation. And although “triggers” will be mostly set to “true” the users may want to set it to “false” from time to time.

Thinking more about it, I could ask the users to define what you suggested in the template and this will always ensure that Terraform will detect a change. Then I can have a boolean “execute” attribute which could be set to “true”/“false” and the Provider will execute based on the value of this attribute.

Thanks,
Jeny

Hi @jenyss!

This seems to be a similar use-case to those discussed already in this issue:

Would you mind adding the details about your use-case over there? Then we can consider them when designing a new feature to meet this family of use-cases.

Thanks!

Thanks Martin,

I will provide my use case in the mentioned ticket but it seems this feature was requested a long time ago. It is a bit disappointing that it is still missing.

Best,
Jeny

// , Would such a feature go along with the declarative, idempotent model for Terraform’s work flow?

I’m curious why the resource is named “workflow_execution”, describing an activity, rather than describing a cloud resource in a cloud provider.

IMO, if people are trying to move Terraform over to become more of a “job executor” similar to BOSH or Jenkins, I might not say “kill it with fire,” but it does raise some concerns.

Hi Nathan,

When you have created your deployment model via Terraform, it would be nice if you could also execute it from the template. This is indeed not the intended usage of Terraform but certainly makes life easier when you want to automate to the process.

Best,
Jeny