hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.28k stars 1.72k forks source link

Creation of google_logging_project_bucket_config fails when project used to run Terraform SA does not have billing enabled #11368

Open traittinen opened 2 years ago

traittinen commented 2 years ago

Community Note

Terraform Version

Terraform v1.0.5 on linux_amd64

Affected Resource(s)

Terraform Configuration Files

Resource configuration:

resource "google_logging_project_bucket_config" "fw_log_bucket" {
    count = var.export_fw_logs_to_clb ? 1 : 0

  project        = var.project_id
  location       = var.fw_log_clb_location
  retention_days = var.fw_log_clb_retention
  bucket_id      = var.fw_log_clb_name
}

Debug Output

  # module.network-baseline.module.fw_logs.google_logging_project_bucket_config.fw_log_bucket[0] will be created
  + resource "google_logging_project_bucket_config" "fw_log_bucket" {
      + bucket_id       = "xxxxx-fw-logs"
      + description     = (known after apply)
      + id              = (known after apply)
      + lifecycle_state = (known after apply)
      + location        = "global"
      + name            = (known after apply)
      + project         = "xxxxx-network-log"
      + retention_days  = 90
    }

β”‚ Error: Error creating Bucket: googleapi: Error 403: This API method requires billing to be enabled. Please enable billing on project #1016471542722 by visiting https://console.developers.google.com/billing/enable?project=1016471542722 then retry. If you enabled billing for this project recently, wait a few minutes for the action to propagate to our systems and retry.
β”‚ Details:
β”‚ [
β”‚   {
β”‚     "@type": "type.googleapis.com/google.rpc.Help",
β”‚     "links": [
β”‚       {
β”‚         "description": "Google developers console billing",
β”‚         "url": "https://console.developers.google.com/billing/enable?project=1016471542711"
β”‚       }
β”‚     ]
β”‚   },
β”‚   {
β”‚     "@type": "type.googleapis.com/google.rpc.ErrorInfo",
β”‚     "domain": "googleapis.com",
β”‚     "metadata": {
β”‚       "consumer": "projects/1016471542711",
β”‚       "service": "logging.googleapis.com"
β”‚     },
β”‚     "reason": "BILLING_DISABLED"
β”‚   }
β”‚ ]
β”‚ 
β”‚   with module.network-baseline.module.fw_logs.google_logging_project_bucket_config.fw_log_bucket[0],
β”‚   on .terraform/modules/network-baseline/modules/org_fw_logs/log_sink_clb.tf line 19, in resource "google_logging_project_bucket_config" "fw_log_bucket":
β”‚   19: resource "google_logging_project_bucket_config" "fw_log_bucket" {
β”‚ 

Error: Apply operation failed

$ terraform state show 'module.network-baseline.module.fw_logs.google_logging_project_bucket_config.fw_log_bucket[0]'
# module.network-baseline.module.fw_logs.google_logging_project_bucket_config.fw_log_bucket[0]: (tainted)
resource "google_logging_project_bucket_config" "fw_log_bucket" {
    bucket_id      = "xxxxx-fw-logs"
    id             = "projects/xxxxx-network-log/locations/global/buckets/xxxxx-fw-logs"
    location       = "global"
    project        = "xxxxx-network-log"
    retention_days = 90
}

Project 1016471542711 is the project hosting the service account that is used to run Terraform and different from "xxxxx-network-log" that should host the log bucket.

Panic Output

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. Use service account on a project that has not billing enabled to run Terraform
  2. Use different project ID in google_logging_project_bucket_config with billing enabled
  3. terraform apply

Important Factoids

References

b/300742899

ScottSuarez commented 2 years ago

Is it possible to get logs for this?

You can set TF_LOG=DEBUG and TF_LOG_PATH=./your-file.log