'GCF - evnironment variables are not changing when deployed from terraform
I have a Terraform code that is deploying Google Cloud Function. When I modify environment_variables by changing the variable name e.g.: DOMAIN to APP_DOMAIN, the code in GCF is being updated, version is being increased, but the variables don't. I have to destroy the function and recreate it to make new env variable work.
resource "google_cloudfunctions_function" "pubsub_triggered_function" {
region = var.region
name = var.pubsub_triggered_function_name
runtime = "python39"
available_memory_mb = 128
source_archive_bucket = google_storage_bucket.code_archive_bucket.name
source_archive_object = google_storage_bucket_object.archive.name
entry_point = var.function_entry_point
service_account_email = "${var.service_account_email}"
event_trigger {
event_type = "providers/cloud.pubsub/eventTypes/topic.publish"
resource = var.pubsub_topic
failure_policy {
retry = true
}
}
environment_variables = {
DOMAIN = var.app_domain
ENVIRONMENT = var.environment
PROJECT_ID = var.project
}
}
When I change this manually, the variables do change and new version of the cloud function has new variable. It's seems to be a Terraform bug. (Terraform v1.1.5)
--- EDIT #1 ---
Adding the first part of the code - zip archive might be relevant.
locals {
timestamp = formatdate("YYYY-MM-DD_hh-mm-ss", timestamp())
root_dir = abspath("../src")
}
data "archive_file" "archived_source_code" {
type = "zip"
source_dir = local.root_dir
output_path = "/tmp/pubsub-triggered-code-${local.timestamp}.zip"
}
resource "google_storage_bucket" "code_archive_bucket" {
name = "pubsub-triggered-code-archive"
location = "EU"
storage_class = "ARCHIVE"
uniform_bucket_level_access = true
lifecycle_rule {
condition {
age = 367
}
action {
type = "Delete"
}
}
}
resource "google_storage_bucket_object" "archive" {
name = "pubsub-triggered-code-${local.timestamp}.zip"
bucket = google_storage_bucket.code_archive_bucket.name
source = data.archive_file.archived_source_code.output_path
}
--- EDIT #2 ---
After manual modification of the variable in the GUI of GCP and running terraform plan, I've been warned by Terraform that variable has been manually changed and it's presenting new variable name.
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the last "terraform apply":
- "DOMAIN" = "TEST" -> null
+ "APP_DOMAIN" = "TEST"
--- EDIT #3 ---
After manual change mentioned in previous edit it's working. I remember I was having this issue before, so it's likely to happen in the future, really close one. This is the second time I'm using this code and second time I was having this issue.
--- EDIT #4 ---
Now the code does not update at all. I have to do some manual actions, like remove the function to see changes. This was the official example presented in the Terraform docs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
