-
Notifications
You must be signed in to change notification settings - Fork 64
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
Provider failing to use TFC as a backend #218
Comments
FWIW using the same code without creating the Terraform cloud workspace causes the following behavior.
It seems like it is waiting for a response the same way we are requested to select a Terraform workspace for our run. |
Does the content of the |
Well besides the exact name there are other options that can be used in the
|
I have the same error with the elastic terraform provider, so I made a simple test to check it, and I found that a really basic example has the same issue. In this case, creating a ---
apiVersion: tf.upbound.io/v1beta1
kind: ProviderConfig
metadata:
name: default-tf
spec:
# This optional configuration block can be used to inject HCL into any
# workspace that uses this provider config, for example to setup Terraform
# providers.
configuration: |
terraform {
required_version = ">= 1.5.0"
}
---
apiVersion: tf.upbound.io/v1beta1
kind: Workspace
metadata:
name: example-inline
annotations:
# The terraform workspace will be named 'hello-world'. If you omitted this
# annotation it would be derived from metadata.name - i.e. 'example-inline'.
crossplane.io/external-name: example-inline
spec:
forProvider:
# For simple cases you can use an inline source to specify the content of
# main.tf as opaque, inline HCL.
source: Inline
module: |
resource "random_id" "example" {
byte_length = 4
}
output "hello_world" {
value = "Hello, World! - ${terraform.workspace}-${random_id.example.hex}"
}
resource "local_file" "example" {
content = "${random_id.example.hex}"
filename = "${path.module}/example.txt"
}
data "template_file" "init" {
template = ""
vars = {
consul_address = ""
}
}
writeConnectionSecretToRef:
namespace: default
name: terraform-workspace-hello-world
providerConfigRef:
name: default-tf
I have tested with
|
@kuisathaverat your
|
@nalshamaajc 🤦♂️ I trusted the provider to manage the terraform state for me in the k8s cluster, but it does not do it. You MUST configure a backend, something I did not see in the documentation set as required. Also, the error does not help here to realize that the provider does not manage the default backend. ---
apiVersion: tf.upbound.io/v1beta1
kind: ProviderConfig
metadata:
name: default-tf
spec:
configuration: |
terraform {
required_version = ">= 1.5.0"
backend "kubernetes" {
secret_suffix = "k8s-backend"
namespace = "crossplane-system"
in_cluster_config = true
}
} |
The terraform state configuration is documented in the provider's documentation in the marketplace : https://marketplace.upbound.io/providers/upbound/provider-terraform/v0.12.0/docs/quickstart configuration: |
provider "google" {
credentials = "gcp-credentials.json"
project = "YOUR-GCP-PROJECT-ID"
}
// Modules _must_ use remote state. The provider does not persist state.
terraform {
backend "kubernetes" {
secret_suffix = "providerconfig-default"
namespace = "upbound-system"
in_cluster_config = true
}
} However, I agree that this is not the default behavior we should expect if we omit it. |
The docs mention somewhere that it will use whatever you configure as a backend if I'm not mistaken. @kuisathaverat Did the workaround work for you? |
yep, there is a comment in the terraform plans in the Quickstart and in the known limitations
yes, using the k8s backend works like a charm, I have configured the Elastic Terraform provider without issues |
provider-terraform/internal/terraform/terraform.go
Line 414 in b21417f
The issue started with me getting an error when supplying a TFC workspace name that is different than the one in the
external-name
annotation different changed the value of theexternal-name
annotation to match the workspace I created and the "workspace not supported" error mentioned in this comment was gone.I was now left with a different error which was complaining about the absence of a state file in this backend.
What environment did it happen in?
Expected Behavior
Use the workspace with no errors.
Code
Workaround
The workaround for this problem is seeding the state in the terraform cloud workspace with a data resource.
Code
Create a local file ex:
providers.tf
Output
The text was updated successfully, but these errors were encountered: