Skip to content

Commit

Permalink
feat: Add ability to customize state bucket name (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjerrems committed Jan 15, 2021
1 parent 4ec9fa0 commit 1af1405
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ For the cloudbuild submodule, see the README [cloudbuild](./modules/cloudbuild).
| org\_id | GCP Organization ID | `string` | n/a | yes |
| org\_project\_creators | Additional list of members to have project creator role accross the organization. Prefix of group: user: or serviceAccount: is required. | `list(string)` | `[]` | no |
| parent\_folder | GCP parent folder ID in the form folders/{id} | `string` | `""` | no |
| project\_id | Custom project ID to use for project created. | `string` | `""` | no |
| project\_id | Custom project ID to use for project created. If not supplied, the default id is {project\_prefix}-seed-{random suffix}. | `string` | `""` | no |
| project\_labels | Labels to apply to the project. | `map(string)` | `{}` | no |
| project\_prefix | Name prefix to use for projects created. | `string` | `"cft"` | no |
| sa\_enable\_impersonation | Allow org\_admins group to impersonate service account & enable APIs required. | `bool` | `false` | no |
| sa\_org\_iam\_permissions | List of permissions granted to Terraform service account across the GCP organization. | `list(string)` | <pre>[<br> "roles/billing.user",<br> "roles/compute.networkAdmin",<br> "roles/compute.xpnAdmin",<br> "roles/iam.securityAdmin",<br> "roles/iam.serviceAccountAdmin",<br> "roles/logging.configWriter",<br> "roles/orgpolicy.policyAdmin",<br> "roles/resourcemanager.folderAdmin",<br> "roles/resourcemanager.organizationViewer"<br>]</pre> | no |
| state\_bucket\_name | Custom state bucket name. If not supplied, the default name is {project\_prefix}-tfstate-{random suffix}. | `string` | `""` | no |
| storage\_bucket\_labels | Labels to apply to the storage bucket. | `map(string)` | `{}` | no |

## Outputs
Expand Down
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

locals {
seed_project_id = var.project_id != "" ? var.project_id : format("%s-%s", var.project_prefix, "seed")
state_bucket_name = var.state_bucket_name != "" ? var.state_bucket_name : format("%s-%s-%s", var.project_prefix, "tfstate", random_id.suffix.hex)
impersonation_apis = distinct(concat(var.activate_apis, ["serviceusage.googleapis.com", "iamcredentials.googleapis.com"]))
impersonation_enabled_count = var.sa_enable_impersonation == true ? 1 : 0
activate_apis = var.sa_enable_impersonation == true ? local.impersonation_apis : var.activate_apis
Expand Down Expand Up @@ -80,7 +81,7 @@ resource "google_service_account" "org_terraform" {

resource "google_storage_bucket" "org_terraform_state" {
project = module.seed_project.project_id
name = format("%s-%s-%s", var.project_prefix, "tfstate", random_id.suffix.hex)
name = local.state_bucket_name
location = var.default_region
labels = var.storage_bucket_labels
uniform_bucket_level_access = true
Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ variable "project_prefix" {
}

variable "project_id" {
description = "Custom project ID to use for project created."
description = "Custom project ID to use for project created. If not supplied, the default id is {project_prefix}-seed-{random suffix}."
default = ""
type = string
}
Expand Down Expand Up @@ -114,6 +114,12 @@ variable "sa_enable_impersonation" {
default = false
}

variable "state_bucket_name" {
description = "Custom state bucket name. If not supplied, the default name is {project_prefix}-tfstate-{random suffix}."
default = ""
type = string
}

variable "grant_billing_user" {
description = "Grant roles/billing.user role to CFT service account"
type = bool
Expand Down

0 comments on commit 1af1405

Please sign in to comment.