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

Provide explicit project information #3060

Merged
merged 1 commit into from
Oct 7, 2024

Conversation

wiktorn
Copy link
Contributor

@wiktorn wiktorn commented Sep 21, 2024

Submission Checklist

Explicitly provide project information, otherwise if environment doesn't set any project information, the plan/apply will fail with following error:

╷                                     
│ Error: Failed to retrieve project, pid: , err: project: required field is not set
│                                                                                                        
│   with module.ps-connect.google_compute_global_address.private_ip_alloc,
│   on modules/private-service-access-5f9b/main.tf line 26, in resource "google_compute_global_address" "private_ip_alloc":
│   26: resource "google_compute_global_address" "private_ip_alloc" {
│                                          

NOTE: Community submissions can take up to 2 weeks to be reviewed.

Please take the following actions before submitting this pull request.

  • Fork your PR branch from the Toolkit "develop" branch (not main)
  • Test all changes with pre-commit in a local branch #
  • Confirm that "make tests" passes all tests
  • Add or modify unit tests to cover code changes
  • Ensure that unit test coverage remains above 80%
  • Update all applicable documentation
  • Follow Cluster Toolkit Contribution guidelines #

Copy link
Collaborator

@mr0re1 mr0re1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@mr0re1
Copy link
Collaborator

mr0re1 commented Oct 2, 2024

/gcbrun

@mr0re1
Copy link
Collaborator

mr0re1 commented Oct 2, 2024

While I welcome this change. this is strange that you got this error, resources should fallback to the provider settings and toolkit configures provider with var.project_id value. Does you blueprint have var.project_id specified?

@tpdownes tpdownes added the release-bugfix Added to release notes under the "Bug fixes" heading. label Oct 7, 2024
@tpdownes tpdownes self-assigned this Oct 7, 2024
@tpdownes
Copy link
Member

tpdownes commented Oct 7, 2024

I was not able to reproduce this with this code. I also tried with the latest v6 Terraform plugin for Google Cloud.

variable "project_id" {
  description = "Toolkit deployment variable: project_id"
  type        = string
}

variable "region" {
  description = "Toolkit deployment variable: region"
  type        = string
}

variable "zone" {
  description = "Toolkit deployment variable: zone"
  type        = string
}

variable "address" {
  description = "The IP address or beginning of the address range allocated for the private service access."
  type        = string
  default     = null
}

variable "network_id" {
  description = <<-EOT
    The ID of the GCE VPC network to configure private service Access.:
    `projects/<project_id>/global/networks/<network_name>`"
    EOT
  type        = string
  validation {
    condition     = length(split("/", var.network_id)) == 5
    error_message = "The network id must be provided in the following format: projects/<project_id>/global/networks/<network_name>."
  }
}

variable "prefix_length" {
  description = "The prefix length of the IP range allocated for the private service access."
  type        = number
  default     = 16
}

terraform {
  required_version = ">= 1.2"

  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 5.38.0"
    }
    google-beta = {
      source  = "hashicorp/google-beta"
      version = "~> 5.38.0"
    }
  }
}

provider "google" {
  project = var.project_id
  region  = var.region
  zone    = var.zone
}

provider "google-beta" {
  project = var.project_id
  region  = var.region
  zone    = var.zone
}

resource "random_id" "resource_name_suffix" {
  byte_length = 4
}

resource "google_compute_global_address" "private_ip_alloc" {
  provider      = google-beta
  name          = "global-psconnect-ip-${random_id.resource_name_suffix.hex}"
  purpose       = "VPC_PEERING"
  address_type  = "INTERNAL"
  network       = var.network_id
  prefix_length = var.prefix_length
  labels        = {}
  address       = var.address
}

and these variables:

region = "us-central1"
zone = "us-central1-a"
project_id = "my-project"
network_id = "projects/my-project/global/networks/default"

terraform plan works as I'd expect:

  # google_compute_global_address.private_ip_alloc will be created
  + resource "google_compute_global_address" "private_ip_alloc" {
      + address            = (known after apply)
      + address_type       = "INTERNAL"
      + creation_timestamp = (known after apply)
      + effective_labels   = {
          + "goog-terraform-provisioned" = "true"
        }
      + id                 = (known after apply)
      + label_fingerprint  = (known after apply)
      + name               = (known after apply)
      + network            = "projects/toolkit-demo-zero-e913/global/networks/default"
      + prefix_length      = 16
      + project            = "my-project"
      + purpose            = "VPC_PEERING"
      + self_link          = (known after apply)
      + terraform_labels   = {
          + "goog-terraform-provisioned" = "true"
        }
    }

@mr0re1 mr0re1 merged commit 23cbf00 into GoogleCloudPlatform:develop Oct 7, 2024
9 of 56 checks passed
@harshthakkar01 harshthakkar01 mentioned this pull request Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-bugfix Added to release notes under the "Bug fixes" heading.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants