Search code examples
terraforminfrastructure-as-codeterraform-enterprise

How to use Terraform Cloud/Enterprise Provider?


I came across TFE Provider during experimenting with Terraform Cloud. I do not see any good use case since I can set everything with *.auto.tvars.

Apart from that I tried it with an arbitrary tfe_variable:

provider "tfe" {
  
}

resource "tfe_variable" "test" {
  key          = "listTest"
  value        = "logs, datatransfer"
  category     = "terraform"
  workspace_id = "my_workspace"
  hcl          = true
  description  = "a useful description"
  sensitive    = false
}

However this always results in:

Error: Error creating terraform variable listTest: resource not found

I do not understand the sense of this message with the block above I want to create this very variable.


Solution

  • I faced the same issue and was able to resolve it by changing the "Execution Mode" of the workspace in Terraform Cloud.

    If you click the workspace and then click on the "Settings" dropdown menu and visit "General", there is a radio button for "Execution Mode". If you select "Local" and click "Save settings" and re-run terraform apply it should be able to create the variable.

    The tradeoff with this approach is that all Terraform operations must be run locally.

    There is also an open issue in the TFE provider repository regarding this behavior.