Skip to content

Commit

Permalink
fix: add bucket prefix for bootstrap (#407)
Browse files Browse the repository at this point in the history
* update bootstrap example

* update bootstrap example

Co-authored-by: Zaynab Shah <zaynabs@google.com>
  • Loading branch information
z-shah and Zaynab Shah committed Apr 8, 2021
1 parent c2b8200 commit 03bd05a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions 0-bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Currently, the bucket information is replaced in the state backends as a part of
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| billing\_account | The ID of the billing account to associate projects with. | `string` | n/a | yes |
| bucket\_prefix | Name prefix to use for state bucket created. | `string` | `"bkt"` | no |
| cloud\_source\_repos | List of Cloud Source Repositories created during bootstrap project build stage for use with Cloud Build. | `list(string)` | <pre>[<br> "gcp-org",<br> "gcp-environments",<br> "gcp-networks",<br> "gcp-projects"<br>]</pre> | no |
| default\_region | Default region to create resources where applicable. | `string` | `"us-central1"` | no |
| folder\_prefix | Name prefix to use for folders created. | `string` | `"fldr"` | no |
Expand Down
7 changes: 7 additions & 0 deletions 0-bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ resource "google_folder" "bootstrap" {
parent = local.parent
}

resource "random_id" "suffix" {
byte_length = 2
}

module "seed_bootstrap" {
source = "terraform-google-modules/bootstrap/google"
version = "~> 2.1"
org_id = var.org_id
folder_id = google_folder.bootstrap.id
project_id = "${var.project_prefix}-b-seed"
state_bucket_name = "${var.bucket_prefix}-b-tfstate-${random_id.suffix.hex}"
billing_account = var.billing_account
group_org_admins = var.group_org_admins
group_billing_admins = var.group_billing_admins
Expand Down Expand Up @@ -103,6 +109,7 @@ module "cloudbuild_bootstrap" {
version = "~> 2.1"
org_id = var.org_id
folder_id = google_folder.bootstrap.id
project_id = "${var.project_prefix}-b-cicd"
billing_account = var.billing_account
group_org_admins = var.group_org_admins
default_region = var.default_region
Expand Down
7 changes: 7 additions & 0 deletions 0-bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ variable "folder_prefix" {
type = string
default = "fldr"
}

variable "bucket_prefix" {
description = "Name prefix to use for state bucket created."
type = string
default = "bkt"
}

variable "cloud_source_repos" {
description = "List of Cloud Source Repositories created during bootstrap project build stage for use with Cloud Build."
type = list(string)
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/bootstrap/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ module "bootstrap" {
billing_account = var.billing_account
org_project_creators = var.org_project_creators
project_prefix = var.project_prefix
bucket_prefix = var.bucket_prefix
}
7 changes: 7 additions & 0 deletions test/fixtures/bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ variable "org_project_creators" {
variable "project_prefix" {
description = "Name prefix to use for projects created."
type = string
default = "tst"
}

variable "bucket_prefix" {
description = "Name prefix to use for state bucket created."
type = string
default = "tst"
}

0 comments on commit 03bd05a

Please sign in to comment.