hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.7k stars 9.55k forks source link

Use of resources google_project and google_project_services causes prompt for "region" value #11834

Closed ryan-mf closed 7 years ago

ryan-mf commented 7 years ago

Terraform Version

Terraform v0.8.6

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

// GCP Project for this environment
resource "google_project" "company-env" {
  project_id         = "${var.ENVIRONMENT}"
  org_id             = "${var.GCP_ORG_ID}"
  name               = "${var.ENVIRONMENT}"
  skip_delete        = "true"
}

// APIs to enable for above project
resource "google_project_services" "company-env" {
  project            = "${var.ENVIRONMENT}"
  services           = ["compute_component", "container", "dns.googleapis.com", "sqladmin-json.googleapis.com", "monitoring.googleapis.com", "logging.googleapis.com", "sql-component-json.googleapis.com", "cloudmonitoring.googleapis.com", "storage-component-json.googleapis.com", "iam.googleapis.com"]
}

Expected Behavior

Terraform should provision (apply) or show (plan) the resources I'm requesting.

Actual Behavior

Terraform prompts for a value for "region" like so: user@Ubuntu:~/github/techops/environments/stage/terraform$ TF_VAR_ENV_SHORT=stage TF_VAR_ENVIRONMENT=company-stage GOOGLE_PROJECT=${TF_VAR_ENVIRONMENT} GOOGLE_CREDENTIALS=cat ./company.json terraform plan provider.google.region Enter a value:

Steps to Reproduce

  1. Add resource blocks for google_project and google_project_services to a .tf file.
  2. Define all variables in vars.tf
  3. Run above terraform command (where some VARs are set on the command line before running terraform)
  4. Receive prompt for "region"

Important Factoids

Dnefedkin commented 7 years ago

"Region" is a required property for Google provider (https://github.com/hashicorp/terraform/blob/master/builtin/providers/google/provider.go#L48)

So you have to have something like that in your tf file:

provider "google" { credentials = "${file("account.json")}" project = "my-gce-project" region = "us-central1" }

ryan-mf commented 7 years ago

Yep, I have providers in place with all necessary values and a bunch of resources using them. I was just trying to add creation of the project itself to terraform too. I fiddled around today and got past this issue (not in front of computer here so can't past changes I made) and ran into a new roadblock with Google API errors that I haven't enabled the right APIs to compete the task....on a new project I'm trying to create. Chicken before egg. I'll create a new ticket if I can't get past it.

Thanks!

danawillow commented 7 years ago

@ryan-mf, it sounds like you've solved the issue so I'm going to go ahead and close it. Feel free to reopen or file a new issue if necessary.

ghost commented 4 years ago

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.