Skip to content
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

Terraform ignores Cloud Function module when plan/apply #4712

Closed
HebertCL opened this issue Oct 18, 2019 · 8 comments
Closed

Terraform ignores Cloud Function module when plan/apply #4712

HebertCL opened this issue Oct 18, 2019 · 8 comments
Assignees
Labels
bug forward/review In review; remove label to forward service/cloudfunctions

Comments

@HebertCL
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "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 to "hashibot", a community member has claimed the issue already.

Description

I've been working on a Cloud Function module that uses PubSub topic as trigger. My main.tf looks like this:

module "grumman_pubsub" {
  source = "git::ssh://[email protected]/crabi/tf-titan-centaur.git//modules/google_pubsub?ref=development"
  
  provision_ready                       = var.provision_ready
  gcp_pubsub_topic_name                 = var.gcp_pubsub_topic_name
}

module "grumman_function" {
  source = "git::ssh://[email protected]/crabi/tf-titan-centaur.git//modules/google_functions?ref=development"
  
  provision_ready                     = module.grumman_pubsub.pubsub_complete
  gcp_function_name                   = var.gcp_function_name
  gcp_function_runtime                = var.gcp_function_runtime
  gcp_function_available_memory       = var.gcp_function_available_memory
  gcp_function_archive_bucket         = var.gcp_function_archive_bucket
  gcp_function_archive_object         = var.gcp_function_archive_object
  gcp_function_trigger_topic          = module.grumman_pubsub.pubsub_topic
  gcp_function_environment_variables  = var.gcp_function_environment_variables
}

To provide complete context, I am using a couple null resources called provision_ready and <RESOURCE>_complete. This is a trick to be able to chain small modules together and have the ability to give them dependency between each other. This is how the actual cloud function module looks like:

resource "google_cloudfunctions_function" "gcp_function" {
  depends_on  = [
    "null_resource.provision_ready",
  ]

  name                  = var.gcp_function_name
  runtime               = var.gcp_function_runtime
  available_memory_mb   = var.gcp_function_available_memory
  source_archive_bucket = var.gcp_function_archive_bucket
  source_archive_object = var.gcp_function_archive_object
  trigger_topic         = var.gcp_function_trigger_topic
  for_each              = var.gcp_function_environment_variables

  environment_variables = {
    key   = each.key
    value = each.value
  }
}

resource "null_resource" "provision_ready" {
  triggers = {
    provision_ready = var.provision_ready
  }
}

resource "null_resource" "function_complete" {
  depends_on  = [
    "null_resource.provision_ready",
    "google_cloudfunctions_function.gcp_function",
  ]
}

Theoretically, both plan and apply of this module should fail because trigger_topic config have been deprecated in favor of event_trigger. Not only configuration plans and applies with no errors, but in fact is straight up ignoring cloud function resource. It even provisions both null resources that come with cloud function module even though function_complete resource depends on cloud function resource completion. This is an example:

terraform plan -var-file=default.tfvars                  
Acquiring state lock. This may take a few moments...
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.terraform_remote_state.network: Refreshing state...
module.grumman_pubsub.null_resource.provision_ready: Refreshing state... [id=2356592622897044922]
module.grumman_pubsub.google_pubsub_topic.gcp_pubsub_topic: Refreshing state... [id=projects/crabi-dev/topics/grumman-llv]
module.grumman_pubsub.null_resource.pubsub_complete: Refreshing state... [id=1108154725870172411]
module.grumman_function.null_resource.provision_ready: Refreshing state... [id=7314214457929094293]
module.grumman_function.null_resource.function_complete: Refreshing state... [id=6508101179358063719]

------------------------------------------------------------------------

No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

I noticed this behavior couple days ago. I was using a similar cloud function configuration which deployed successfully, and suddenly noticed my cloud functions were not being provisioned anymore.
Right now I cannot provision anymore cloud functions at the moment, but that seems to be a different issue I plan to report separately. I also share a gist with debug mode execution. Thanks for checking this out.

Terraform Version

Terraform v0.12.11
Terraform v0.12.9

Affected Resource(s)

google_cloudfunctions_function.function

Debug Output

https://gist.github.com/HebertCL/aa83b5b7073812c42e887977e4cc6d82

Expected Behavior

Terraform should either create all resources in the modules or fail due deprecated configuration used in the modules.

Actual Behavior

Terraform applies and create all resources but cloud function resource. It creates resources that depend from cloud function resource as well.

Steps to Reproduce

Use this gist as reference:
https://gist.github.com/HebertCL/a5756ea86a871fda9ddf548772a0883a

  1. terraform init
  2. terraform apply
@slevenick
Copy link
Collaborator

Strange. The field is marked Removed: in the cloud function resource, so I'm imagining that for some reason terraform is not handling the error coming from that.

I attempted to reproduce locally with a cloudfunction module that uses trigger_topic, but I encounter the following error which is expected:

Error: "trigger_topic": [REMOVED] This field is removed. Use `event_trigger` instead.

  on my-mod/main.tf line 11, in resource "google_cloudfunctions_function" "function":
  11: resource "google_cloudfunctions_function" "function" {

What version of the google provider are you running?

@HebertCL
Copy link
Author

@slevenick thanks for the quick reply! This is the list of providers I am using:

Terraform v0.12.11
+ provider.google v2.17.0
+ provider.google-beta v2.17.0
+ provider.null v2.1.2

Worth to mention I have used the event_trigger before to workaround that issue you mention, but the result remains the same and cloud function is ignored. This is the block I use:

event_trigger {
    event_type = "google.pubsub.topic.publish"
    resource = module.grumman_pubsub.pubsub_topic
  }

I use a module output that exposes pubsub topic name. Hope this helps.

@slevenick
Copy link
Collaborator

I'm not sure what is happening here, but it seems like an issue with your module setup rather than the terraform provider. If you combine your modules into a single one temporarily, does it create the cloud function? I'd guess there is something strange happening with trying to depend on the output of one module in another, but really without access to the modules I can only guess.

@HebertCL
Copy link
Author

The modules are very simple. You can find them along with the main file I am using are here. I'll give it a shot putting both cloud function and pubsub topic in the same module. My guess is it should work just fine although it kind of defeats the purpose I wanted to achieve since not all our cloud functions depend on PubSub. I will let you know the outcome.

@ghost ghost removed the waiting-response label Oct 22, 2019
@venkykuberan venkykuberan self-assigned this Jan 15, 2020
@venkykuberan
Copy link
Contributor

@HebertCL are you still needing help on this issue ? or can i go head and close it if you have what you needed.

@HebertCL
Copy link
Author

@venkykuberan I haven't had the chance to revisit this issue. For now I have integrated it to my workflow using gcloud, so for now it's safe to close it. If I get back to it and find it happening, I will reopen it.

@ghost ghost removed the waiting-response label Jan 15, 2020
@venkykuberan
Copy link
Contributor

Thank you @HebertCL. I am closing it.

@ghost
Copy link

ghost commented Feb 15, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Feb 15, 2020
@github-actions github-actions bot added service/cloudfunctions forward/review In review; remove label to forward labels Jan 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug forward/review In review; remove label to forward service/cloudfunctions
Projects
None yet
Development

No branches or pull requests

4 participants