3

I am trying to provision a version 2 cloud function using terraform in gcp. The resource looks like this:

resource "google_cloudfunctions2_function" "function" {
  provider = google-beta
  name = "test-function"
  location = "us-central1"
  description = "a new function"

When I run plan I get this

 Error: Invalid resource type
│
│   on main.tf line 49, in resource "google_cloudfunctions2_function" "function":
│   49: resource "google_cloudfunctions2_function" "function" {
│
│ The provider hashicorp/google-beta does not support resource type "google_cloudfunctions2_function". Did you mean "google_cloudfunctions_function"?

Something I noticed. I can't see a currently existing version 2 cloud function using the gcloud cli:

me@cloudshell:~ (the-project-im-using)$ gcloud functions list
Listed 0 items.
me@cloudshell:~ (the-project-im-using)$ gcloud beta functions list
Listed 0 items.
me@cloudshell:~ (the-project-im-using)$ gcloud alpha functions list
Listed 0 items.
me@cloudshell:~ (the-project-im-using)$

Am I correct in assuming thaat this indicates the version 2 cloud functions are not accessible via rest api?

The reference docs I could find are here: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloudfunctions2_function https://cloud.google.com/functions/docs/tutorials/terraform

Thanks!

1
  • If this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. Another option is to upvote the answer if you feel it is useful for you. There is no obligation to do this. Commented Aug 23, 2022 at 17:17

3 Answers 3

0

I manage to fix it by explicitly forcing the beta tag, google-beta provider in the main.tf file

provider "google-beta" {
   project = local.project
}

and also adding it o every resource I used

resource "google_cloudfunctions2_function" "function" {
  provider = google-beta
  name = "function-v2"
  location = "us-central1"
  description = "a new function"
  ...
resource "google_storage_bucket" "bucket" {
  provider = google-beta
  name     = "${local.project}-gcf-source"  # Every bucket name must be globally unique
  location = "US"
  ...
Sign up to request clarification or add additional context in comments.

Comments

0

I suspect the problem is related to the versions of Terraform and gcloud CLI that are currently running in your Cloud Shell.

With the release 395.0.0 of gcloud, the ability to list 2nd gen Cloud Functions was added:

Updated gcloud functions list to return 2nd gen functions in addition to 1st gen functions.

If you are running a lower version (mine had initially version 394) the 2nd gen functions won't be listed. Keep in mind you can still list the underlying Cloud Run services with gcloud run services list.

As for Terraform, my Cloud Shell had no problem deploying a 2nd gen function (the basic example from the documentation). My local machine has the latest versions of both packages and could also deploy without issue.

I suggest you deploy the function in your local machine with the latest versions of those packages. Otherwise, since Cloud Shell is managed and might reset to the default installation, you could also try customizing the container or waiting for the default installation to be updated. Let me know if this was useful.

Comments

0

For anyone reading this now, google_cloundfunction2_function was just recently added in October 10, 2022 to the google provider, so there's no need to use the google-beta provider anymore. I ran into this problem as well, and I just had to upgrade my google provider to version 4.40. (See the release log here).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.