Skip to content

Commit

Permalink
Add support for GCP project as env vars (#43)
Browse files Browse the repository at this point in the history
Signed-off-by: Jim Enright <jenright@cloudera.com>
  • Loading branch information
jimright authored Sep 30, 2024
1 parent 228e27e commit ce2bd0d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ export ARM_SUBSCRIPTION_ID="<sp_subscription_id>"

* The Google Cloud IAM roles listed below are required by the provisioning account to create the GCP pre-requisite resources.

| IAM Role |
| ------------------------- |
| Compute Network Admin |
| Compute Security Admin |
| Role Administrator |
| Security Admin |
| Service Account Admin |
| Service Account Key Admin |
| Storage Admin |
| Viewer |
| IAM Role |
| ------------------------- |
| Compute Network Admin |
| Compute Security Admin |
| Role Administrator |
| Security Admin |
| Service Account Admin |
| Service Account Key Admin |
| Storage Admin |
| Viewer |

* The Google project Id can be specified via the `gcp_project` input variable, the `GOOGLE_PROJECT` environment variable or the default project set via the Cloud SDK. 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.

### Input file configuration

Expand Down
5 changes: 4 additions & 1 deletion gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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 = local.public_key_text
deployment_template = var.deployment_template
Expand Down Expand Up @@ -105,6 +105,9 @@ module "cdp_deploy" {
]
}

# Use the Google Cloud Provider to retrieve GCP project details
data "google_project" "project" {}

# ------- Create SSH Keypair if input public_key_text variable is not specified
locals {
# flag to determine if keypair should be created
Expand Down
4 changes: 3 additions & 1 deletion gcp/variables.tf
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 ce2bd0d

Please sign in to comment.