Skip to content

Commit 06b47d7

Browse files
gtsorboapeabody
andauthored
feat: bootstrap phase (#8)
Co-authored-by: Andrew Peabody <[email protected]>
1 parent 646dc9f commit 06b47d7

29 files changed

+187
-230
lines changed

.github/conventional-commit-lint.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022-2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

.github/release-please.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2021 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

.github/trusted-contribution.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

.github/workflows/lint.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2023 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

.github/workflows/stale.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2022-2024 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

1-bootstrap/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# EAB: Bootstrap phase
2+
3+
The bootstrap phase establishes the 3 initial pipelines of the Enterprise Application blueprint. These pipelines are:
4+
- the Multitenant Infrastructure pipeline
5+
- the Application Factory
6+
- the Fleet-Scope pipeline
7+
8+
Each pipeline has the following associated resources:
9+
- 2 Cloud Build triggers
10+
- 1 trigger to run Terraform Plan commands upon changes to a non-main git branch
11+
- 1 trigger to run Terraform Apply commands upon changes to the main git branch
12+
- 3 Cloud Storage buckets
13+
- Terraform State bucket, to store the current state
14+
- Build Artifacts bucket, to store any artifacts generated during the build process, such as `.tfplan` files
15+
- Build Logs bucket, to store the logs from the build process
16+
- 1 service account for executing the Cloud Build build process
17+
18+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
19+
## Inputs
20+
21+
| Name | Description | Type | Default | Required |
22+
|------|-------------|------|---------|:--------:|
23+
| project\_id | Project ID for initial resources | `any` | n/a | yes |
24+
25+
## Outputs
26+
27+
| Name | Description |
28+
|------|-------------|
29+
| state\_buckets | n/a |
30+
31+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

1-bootstrap/main.tf

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
locals {
18+
cb_config = {
19+
"multitenant" = {
20+
repo_name = "eab-multitenant",
21+
bucket_prefix = "mt"
22+
roles = [
23+
"roles/container.admin"
24+
]
25+
}
26+
"applicationfactory" = {
27+
repo_name = "eab-applicationfactory",
28+
bucket_prefix = "af"
29+
roles = [
30+
]
31+
}
32+
"fleetscope" = {
33+
repo_name = "eab-fleetscope",
34+
bucket_prefix = "fs"
35+
roles = [
36+
]
37+
}
38+
}
39+
}
40+
41+
resource "google_sourcerepo_repository" "gcp_repo" {
42+
for_each = local.cb_config
43+
44+
project = var.project_id
45+
name = each.value.repo_name
46+
}
47+
48+
module "tf_cloudbuild_workspace" {
49+
for_each = local.cb_config
50+
source = "terraform-google-modules/bootstrap/google//modules/tf_cloudbuild_workspace"
51+
version = "~> 7.0"
52+
53+
project_id = var.project_id
54+
tf_repo_uri = google_sourcerepo_repository.gcp_repo[each.key].url
55+
tf_repo_type = "CLOUD_SOURCE_REPOSITORIES"
56+
artifacts_bucket_name = "${each.value.bucket_prefix}-build-${var.project_id}"
57+
create_state_bucket_name = "${each.value.bucket_prefix}-state-${var.project_id}"
58+
log_bucket_name = "${each.value.bucket_prefix}-logs-${var.project_id}"
59+
60+
cloudbuild_plan_filename = "cloudbuild-tf-plan.yaml"
61+
cloudbuild_apply_filename = "cloudbuild-tf-apply.yaml"
62+
}

outputs.tf renamed to 1-bootstrap/outputs.tf

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2021 Google LLC
2+
* Copyright 2024 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
output "bucket_name" {
18-
description = "Name of the bucket"
19-
value = google_storage_bucket.main.name
17+
output "state_buckets" {
18+
value = { for key, value in module.tf_cloudbuild_workspace : key => value.state_bucket }
2019
}

examples/simple_example/variables.tf renamed to 1-bootstrap/variables.tf

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2021 Google LLC
2+
* Copyright 2024 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,6 +15,5 @@
1515
*/
1616

1717
variable "project_id" {
18-
description = "The ID of the project in which to provision resources."
19-
type = string
18+
description = "Project ID for initial resources"
2019
}

versions.tf renamed to 1-bootstrap/versions.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2021 Google LLC
2+
* Copyright 2024 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,6 @@ terraform {
2424
}
2525

2626
provider_meta "google" {
27-
module_name = "blueprints/terraform/terraform-google-enterprise-application/v0.0.1"
27+
module_name = "blueprints/terraform/terraform-google-enterprise-application:bootstrap/v0.0.1"
2828
}
2929
}

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

README.md

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# terraform-google-enterprise-application
1+
# Enterprise Application blueprint
22

33
## Description
44
### Tagline
@@ -48,18 +48,6 @@ Functional examples are included in the
4848
[examples](./examples/) directory.
4949

5050
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
51-
## Inputs
52-
53-
| Name | Description | Type | Default | Required |
54-
|------|-------------|------|---------|:--------:|
55-
| bucket\_name | The name of the bucket to create | `string` | n/a | yes |
56-
| project\_id | The project ID to deploy to | `string` | n/a | yes |
57-
58-
## Outputs
59-
60-
| Name | Description |
61-
|------|-------------|
62-
| bucket\_name | Name of the bucket |
6351

6452
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6553

build/int.cloudbuild.yaml

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019 Google LLC
1+
# Copyright 2024 Google LLC
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -21,18 +21,20 @@ steps:
2121
- 'TF_VAR_org_id=$_ORG_ID'
2222
- 'TF_VAR_folder_id=$_FOLDER_ID'
2323
- 'TF_VAR_billing_account=$_BILLING_ACCOUNT'
24-
- id: simple-example-init
24+
25+
# Bootstrap
26+
- id: bootstrap-init
2527
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
26-
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage init --verbose']
27-
- id: simple-example-apply
28+
args: ['/bin/bash', '-c', 'cft test run TestBootstrap --stage init --verbose']
29+
- id: bootstrap-apply
2830
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
29-
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage apply --verbose']
30-
- id: simple-example-verify
31+
args: ['/bin/bash', '-c', 'cft test run TestBootstrap --stage apply --verbose']
32+
- id: bootstrap-verify
3133
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
32-
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage verify --verbose']
33-
- id: simple-example-teardown
34+
args: ['/bin/bash', '-c', 'cft test run TestBootstrap --stage verify --verbose']
35+
- id: bootstrap-teardown
3436
name: 'gcr.io/cloud-foundation-cicd/$_DOCKER_IMAGE_DEVELOPER_TOOLS:$_DOCKER_TAG_VERSION_DEVELOPER_TOOLS'
35-
args: ['/bin/bash', '-c', 'cft test run TestSimpleExample --stage teardown --verbose']
37+
args: ['/bin/bash', '-c', 'cft test run TestBootstrap --stage teardown --verbose']
3638
tags:
3739
- 'ci'
3840
- 'integration'

examples/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Usage Examples

examples/simple_example/README.md

-25
This file was deleted.

examples/simple_example/main.tf

-22
This file was deleted.

examples/simple_example/outputs.tf

-25
This file was deleted.

examples/simple_example/versions.tf

-24
This file was deleted.

main.tf

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package bootstrap
16+
17+
import (
18+
"testing"
19+
20+
"github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
21+
"github.com/stretchr/testify/assert"
22+
)
23+
24+
func TestBootstrap(t *testing.T) {
25+
bootstrap := tft.NewTFBlueprintTest(t,
26+
tft.WithTFDir("../../../1-bootstrap"),
27+
)
28+
29+
bootstrap.DefineVerify(func(assert *assert.Assertions) {
30+
bootstrap.DefaultVerify(assert)
31+
32+
})
33+
bootstrap.Test()
34+
}

0 commit comments

Comments
 (0)