Open marekaf opened 2 years ago
Actually, nevermind... I just figured it out.
The annotations for secret alias has to be BOTH in metadata.annotations as well as template.metadata.annotations.
RIP my time. Hope this helps somebody before they blow their brains out.
resource "google_cloud_run_service" "main" {
name = "main"
location = var.region
autogenerate_revision_name = true
metadata {
annotations = {
"run.googleapis.com/secrets" = "db-password:projects/1234567890/secrets/db-password"
}
}
template {
spec {
service_account_name = google_service_account.main.email
timeout_seconds = 60
containers {
image = var.image
resources {
limits = {
cpu = "1"
memory = "128Mi"
}
}
ports {
name = "http1"
container_port = 80
}
env {
name = "DB_PASSWORD"
value_from {
secret_key_ref {
name = "db-password"
key = "1" // secret version
}
}
}
}
}
metadata {
annotations = {
"run.googleapis.com/secrets" = "db-password:projects/1234567890/secrets/db-password"
}
}
}
}
Hope this helps somebody before they blow their brains out.
π This really should be made more clear in the docs, adding an example would be great.
When I set this up with provider version 4.42.0
, I only needed to add the annotation to the template
block, and it returned with an error when I tried to add it to the top level metadata.annotations
for the cloud run service itself.
Community Note
modular-magician
user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned tohashibot
, a community member has claimed the issue already.Terraform Version
Affected Resource(s)
Terraform Configuration Files
Debug Output
Panic Output
Expected Behavior
Terraform should create the cloud run service and pull a secret from another GCP project without any errors.
Actual Behavior
For some reason, terraform is trying to look for the secret in this GCP project, even though the annotation properly references the aliased secret & secret id of another project
Steps to Reproduce
terraform apply
Important Factoids
doing this in console by hand works without any issues
if I take the random alias that is created by doing this manually in the console, the alias looks like this
if I put this as the alias to my .tf file and run plan, drift is shown
If I have the same configuration in terraform, I do terraform plan and no drift
References