Skip to content

Commit

Permalink
Add notes and update example to support GCP project as env vars (#78)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Enright <[email protected]>
  • Loading branch information
jimright authored Sep 30, 2024
1 parent 829e223 commit 1cf2a81
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ As outlined in the [Getting Started Docs for Google Terraform Provider](https://
export GOOGLE_APPLICATION_CREDENTIALS=<location_of_gcp_sa_json_file>
```

The Google project Id can be specified via the Google provider configuration variable or the `GOOGLE_PROJECT` environment variable. This is described in the [Google Provider Default Values Configuration](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#provider-default-values-configuration) documentation.

## Local Development Environment

See the [DEVELOPMENT.md](./DEVELOPMENT.md) file for instructions on how to set up an environment for local development of modules.
6 changes: 4 additions & 2 deletions modules/terraform-cdp-deploy/examples/ex03-gcp-basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ provider "google" {
region = var.gcp_region
}


module "cdp_gcp_prereqs" {
source = "../../../terraform-cdp-gcp-pre-reqs"

Expand All @@ -66,7 +65,7 @@ module "cdp_deploy" {

env_prefix = var.env_prefix
infra_type = "gcp"
gcp_project_id = var.gcp_project
gcp_project_id = data.google_project.project.project_id
region = var.gcp_region
public_key_text = var.public_key_text
deployment_template = var.deployment_template
Expand Down Expand Up @@ -100,3 +99,6 @@ module "cdp_deploy" {
module.cdp_gcp_prereqs
]
}

# Use the Google Cloud Provider to retrieve GCP project details
data "google_project" "project" {}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ variable "env_prefix" {

variable "gcp_project" {
type = string
description = "Region which Cloud resources will be created"
description = "Region which Cloud resources will be created. Can also be set via gcloud project default or environment variable."

default = null
}

variable "gcp_region" {
Expand Down

0 comments on commit 1cf2a81

Please sign in to comment.