├── .gitignore
├── assets
└── architecture.png
├── .github
├── renovate.json
├── release-please.yml
├── conventional-commit-lint.yaml
├── trusted-contribution.yml
└── workflows
│ ├── stale.yml
│ ├── lint.yaml
│ └── periodic-reporter.yaml
├── SECURITY.md
├── infra
├── modules
│ ├── firestore
│ │ ├── README.md
│ │ ├── outputs.tf
│ │ ├── versions.tf
│ │ ├── variables.tf
│ │ ├── main.tf
│ │ ├── metadata.display.yaml
│ │ └── metadata.yaml
│ ├── storage
│ │ ├── README.md
│ │ ├── outputs.tf
│ │ ├── versions.tf
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ ├── metadata.display.yaml
│ │ └── metadata.yaml
│ ├── networking
│ │ ├── README.md
│ │ ├── versions.tf
│ │ ├── variables.tf
│ │ ├── outputs.tf
│ │ ├── metadata.display.yaml
│ │ ├── main.tf
│ │ └── metadata.yaml
│ ├── cloudrun
│ │ ├── outputs.tf
│ │ ├── versions.tf
│ │ ├── README.md
│ │ ├── metadata.display.yaml
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── metadata.yaml
│ └── load-balancer
│ │ ├── versions.tf
│ │ ├── README.md
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ ├── metadata.display.yaml
│ │ ├── main.tf
│ │ └── metadata.yaml
├── examples
│ └── simple_example
│ │ ├── README.md
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── outputs.tf
├── test
│ ├── setup
│ │ ├── versions.tf
│ │ ├── outputs.tf
│ │ ├── variables.tf
│ │ ├── main.tf
│ │ └── iam.tf
│ └── integration
│ │ ├── discover_test.go
│ │ ├── go.mod
│ │ └── simple_example
│ │ └── simple_example_test.go
├── provider.tf
├── outputs.tf
├── metadata.display.yaml
├── Makefile
├── variables.tf
├── README.md
├── postdeployment.tf
├── metadata.yaml
├── main.tf
└── files
│ ├── lds_cdn_dashboard.tftpl
│ └── lds_cloudrun_dashboard.tftpl
├── CODEOWNERS
├── tools
└── prepare_services.sh
├── CONTRIBUTING.md
├── README.md
├── CHANGELOG.md
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | **/terraform.tfstate*
2 | **/.terraform*
3 | **/backend.tf
4 | **/terraform.tfplan
5 | **/values-*.yaml
6 | credentials.json
7 |
--------------------------------------------------------------------------------
/assets/architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GoogleCloudPlatform/terraform-large-data-sharing-golang-webapp/HEAD/assets/architecture.png
--------------------------------------------------------------------------------
/.github/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": ["github>GoogleCloudPlatform/cloud-foundation-toolkit//infra/terraform/test-org/github/resources/renovate"]
4 | }
5 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | To report a security issue, please use [https://g.co/vulnz](https://g.co/vulnz).
2 | We use g.co/vulnz for our intake, and do coordination and disclosure here on
3 | GitHub (including using GitHub Security Advisory). The Google Security Team will
4 | respond within 5 working days of your report on g.co/vulnz.
5 |
--------------------------------------------------------------------------------
/infra/modules/firestore/README.md:
--------------------------------------------------------------------------------
1 | # firestore module
2 |
3 |
4 | ## Inputs
5 |
6 | | Name | Description | Type | Default | Required |
7 | |------|-------------|------|---------|:--------:|
8 | | collection\_fields | collection id with respect to its fields | `map(any)` | n/a | yes |
9 | | firestore\_db\_name | firestore database name | `string` | n/a | yes |
10 | | project\_id | GCP project ID. | `string` | n/a | yes |
11 |
12 | ## Outputs
13 |
14 | | Name | Description |
15 | |------|-------------|
16 | | db\_name | Firestore database name |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/infra/modules/storage/README.md:
--------------------------------------------------------------------------------
1 | # storage module
2 |
3 |
4 | ## Inputs
5 |
6 | | Name | Description | Type | Default | Required |
7 | |------|-------------|------|---------|:--------:|
8 | | labels | A map of key/value label pairs to assign to the bucket. | `map(string)` | `{}` | no |
9 | | location | Bucket location | `string` | n/a | yes |
10 | | name | Bucket name | `string` | n/a | yes |
11 | | project\_id | GCP project ID. | `string` | n/a | yes |
12 |
13 | ## Outputs
14 |
15 | | Name | Description |
16 | |------|-------------|
17 | | bucket\_name | Bucket name |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/infra/modules/networking/README.md:
--------------------------------------------------------------------------------
1 | # networking module
2 |
3 |
4 | ## Inputs
5 |
6 | | Name | Description | Type | Default | Required |
7 | |------|-------------|------|---------|:--------:|
8 | | project\_id | GCP project ID. | `string` | n/a | yes |
9 | | region | Google cloud region where the resource will be created. | `string` | n/a | yes |
10 |
11 | ## Outputs
12 |
13 | | Name | Description |
14 | |------|-------------|
15 | | netowrk\_self\_link | Network self link |
16 | | subnet\_netowrk\_self\_link | Subnet netowrk self link |
17 | | vpc\_access\_connector\_id | VPC access connector id |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/infra/examples/simple_example/README.md:
--------------------------------------------------------------------------------
1 | # Simple Example
2 |
3 |
4 | ## Inputs
5 |
6 | | Name | Description | Type | Default | Required |
7 | |------|-------------|------|---------|:--------:|
8 | | project\_id | GCP project for provisioning cloud resources. | `any` | n/a | yes |
9 |
10 | ## Outputs
11 |
12 | | Name | Description |
13 | |------|-------------|
14 | | backend\_bucket\_name | The name of the backend bucket used for Cloud CDN |
15 | | cdn\_bucket\_name | The bucket name for cdn |
16 | | db\_name | The Firestore database name |
17 | | lb\_global\_ip | Frontend IP address of the load balancer |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.github/release-please.yml:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | releaseType: terraform-module
16 | handleGHRelease: true
17 | primaryBranch: main
18 | bumpMinorPreMajor: true
19 |
--------------------------------------------------------------------------------
/infra/examples/simple_example/main.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | module "simple" {
18 | source = "../../"
19 | project_id = var.project_id
20 | }
21 |
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # NOTE: This file is automatically generated from values at:
2 | # https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/blob/master/infra/terraform/test-org/org/locals.tf
3 |
4 | * @GoogleCloudPlatform/blueprint-solutions @GoogleCloudPlatform/torus-dpe @GoogleCloudPlatform/dee-platform-ops @GoogleCloudPlatform/dee-data-ai @GoogleCloudPlatform/jump-start-solutions-admins
5 |
6 | # NOTE: GitHub CODEOWNERS locations:
7 | # https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-and-branch-protection
8 |
9 | CODEOWNERS @GoogleCloudPlatform/blueprint-solutions
10 | .github/CODEOWNERS @GoogleCloudPlatform/blueprint-solutions
11 | docs/CODEOWNERS @GoogleCloudPlatform/blueprint-solutions
12 |
13 |
--------------------------------------------------------------------------------
/infra/examples/simple_example/variables.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | variable "project_id" {
18 | description = "GCP project for provisioning cloud resources."
19 | }
20 |
--------------------------------------------------------------------------------
/infra/modules/storage/outputs.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | output "bucket_name" {
18 | description = "Bucket name"
19 | value = google_storage_bucket.main.name
20 | }
21 |
--------------------------------------------------------------------------------
/infra/modules/cloudrun/outputs.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | output "cloud_run" {
18 | description = "Cloud Run service"
19 | value = google_cloud_run_v2_service.main
20 | }
21 |
--------------------------------------------------------------------------------
/infra/modules/firestore/outputs.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | output "db_name" {
18 | description = "Firestore database name"
19 | value = google_firestore_database.default.name
20 | }
21 |
--------------------------------------------------------------------------------
/tools/prepare_services.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # Copyright 2023 Google LLC
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 |
17 | PROJECT_ID=$(gcloud config get-value project)
18 |
19 | gcloud config set project "$PROJECT_ID"
20 |
21 | gcloud services enable cloudresourcemanager.googleapis.com
22 |
--------------------------------------------------------------------------------
/infra/test/setup/versions.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | terraform {
18 | required_version = ">= 0.13"
19 | required_providers {
20 | google = {
21 | source = "hashicorp/google"
22 | version = "~> 4.57"
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/infra/modules/cloudrun/versions.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | terraform {
18 | required_version = ">= 0.13"
19 | required_providers {
20 | google = {
21 | source = "hashicorp/google"
22 | version = "~> 4.57"
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/infra/modules/networking/versions.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | terraform {
18 | required_version = ">= 0.13"
19 | required_providers {
20 | google = {
21 | source = "hashicorp/google"
22 | version = "~> 4.57"
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/infra/modules/storage/versions.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | terraform {
18 | required_version = ">= 0.13"
19 | required_providers {
20 | google = {
21 | source = "hashicorp/google"
22 | version = "~> 4.57"
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/.github/conventional-commit-lint.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2022-2023 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 | # NOTE: This file is automatically generated from:
16 | # https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/blob/master/infra/terraform/test-org/github
17 |
18 | enabled: true
19 | always_check_pr_title: true
20 |
--------------------------------------------------------------------------------
/infra/modules/load-balancer/versions.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | terraform {
18 | required_version = ">= 0.13"
19 | required_providers {
20 | google = {
21 | source = "hashicorp/google"
22 | version = "~> 4.57"
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/infra/modules/firestore/versions.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | terraform {
18 | required_version = ">= 0.13"
19 | required_providers {
20 | google = {
21 | source = "hashicorp/google"
22 | version = ">= 4.57, <= 4.84, != 4.75.0"
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/infra/test/integration/discover_test.go:
--------------------------------------------------------------------------------
1 | // Copyright 2022 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 test
16 |
17 | import (
18 | "testing"
19 |
20 | "github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-test/pkg/tft"
21 | )
22 |
23 | func TestAll(t *testing.T) {
24 | tft.AutoDiscoverAndTest(t)
25 | }
26 |
--------------------------------------------------------------------------------
/infra/modules/networking/variables.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | variable "project_id" {
18 | description = "GCP project ID."
19 | type = string
20 | }
21 |
22 | variable "region" {
23 | description = "Google cloud region where the resource will be created."
24 | type = string
25 | }
26 |
--------------------------------------------------------------------------------
/infra/test/setup/outputs.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | output "project_id" {
18 | value = module.project.project_id
19 | }
20 |
21 | output "sa_key" {
22 | value = google_service_account_key.int_test.private_key
23 | sensitive = true
24 | }
25 |
26 | output "delete_contents_on_destroy" {
27 | value = true
28 | }
29 |
--------------------------------------------------------------------------------
/infra/modules/load-balancer/README.md:
--------------------------------------------------------------------------------
1 | # load-balancer module
2 |
3 |
4 | ## Inputs
5 |
6 | | Name | Description | Type | Default | Required |
7 | |------|-------------|------|---------|:--------:|
8 | | bucket\_name | Bucket name | `string` | n/a | yes |
9 | | client\_service\_name | Frontend service name | `string` | n/a | yes |
10 | | labels | A map of key/value label pairs to assign to the bucket. | `map(string)` | n/a | yes |
11 | | project\_id | GCP project ID. | `string` | n/a | yes |
12 | | region | Google cloud region where the resource will be created. | `string` | n/a | yes |
13 | | resource\_path | Resource folder path | `string` | n/a | yes |
14 |
15 | ## Outputs
16 |
17 | | Name | Description |
18 | |------|-------------|
19 | | backend\_bucket\_name | The name of the backend bucket used for Cloud CDN |
20 | | lb\_external\_ip | Frontend IP address of the load balancer |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/infra/test/setup/variables.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | variable "org_id" {
18 | description = "The numeric organization id"
19 | }
20 |
21 | variable "folder_id" {
22 | description = "The folder to deploy in"
23 | }
24 |
25 | variable "billing_account" {
26 | description = "The billing account id associated with the project, e.g. XXXXXX-YYYYYY-ZZZZZZ"
27 | }
28 |
--------------------------------------------------------------------------------
/.github/trusted-contribution.yml:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | # NOTE: This file is automatically generated from:
16 | # https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/blob/master/infra/terraform/test-org/github
17 |
18 | annotations:
19 | - type: comment
20 | text: "/gcbrun"
21 | trustedContributors:
22 | - release-please[bot]
23 | - renovate[bot]
24 | - renovate-bot
25 | - forking-renovate[bot]
26 | - dependabot[bot]
27 |
--------------------------------------------------------------------------------
/infra/modules/load-balancer/outputs.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | output "lb_external_ip" {
18 | description = "Frontend IP address of the load balancer"
19 | value = google_compute_global_forwarding_rule.lds.ip_address
20 | }
21 |
22 | output "backend_bucket_name" {
23 | description = "The name of the backend bucket used for Cloud CDN"
24 | value = google_compute_backend_bucket.cdn.name
25 | }
26 |
--------------------------------------------------------------------------------
/infra/modules/firestore/variables.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | variable "project_id" {
18 | description = "GCP project ID."
19 | type = string
20 | }
21 |
22 | variable "collection_fields" {
23 | description = "collection id with respect to its fields"
24 | type = map(any)
25 | }
26 |
27 | variable "firestore_db_name" {
28 | description = "firestore database name"
29 | type = string
30 | }
31 |
--------------------------------------------------------------------------------
/infra/provider.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | terraform {
18 | required_version = ">= 0.13"
19 | required_providers {
20 | google = {
21 | source = "hashicorp/google"
22 | version = "<= 4.84, != 4.75.0"
23 | }
24 | random = {
25 | source = "hashicorp/random"
26 | version = "~> 3.4"
27 | }
28 | }
29 | }
30 |
31 | provider "google" {
32 | project = var.project_id
33 | region = var.region
34 | }
35 |
--------------------------------------------------------------------------------
/infra/modules/storage/main.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | resource "google_storage_bucket" "main" {
18 | project = var.project_id
19 | name = var.name
20 | location = var.location
21 | labels = var.labels
22 | force_destroy = true
23 | }
24 |
25 | resource "google_storage_default_object_acl" "policy" {
26 | bucket = google_storage_bucket.main.name
27 | role_entity = [
28 | "READER:allUsers",
29 | ]
30 | }
31 |
--------------------------------------------------------------------------------
/infra/modules/networking/outputs.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | output "netowrk_self_link" {
18 | description = "Network self link"
19 | value = google_compute_network.main.self_link
20 | }
21 |
22 | output "subnet_netowrk_self_link" {
23 | description = "Subnet netowrk self link"
24 | value = google_compute_subnetwork.main.self_link
25 | }
26 |
27 | output "vpc_access_connector_id" {
28 | description = "VPC access connector id"
29 | value = google_vpc_access_connector.main.id
30 | }
31 |
--------------------------------------------------------------------------------
/infra/modules/storage/variables.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | variable "project_id" {
18 | description = "GCP project ID."
19 | type = string
20 | }
21 |
22 | variable "name" {
23 | description = "Bucket name"
24 | type = string
25 | }
26 |
27 | variable "location" {
28 | description = "Bucket location"
29 | type = string
30 | }
31 |
32 | variable "labels" {
33 | type = map(string)
34 | description = "A map of key/value label pairs to assign to the bucket."
35 | default = {}
36 | }
37 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project.
4 |
5 | ## Before you begin
6 |
7 | ### Sign our Contributor License Agreement
8 |
9 | Contributions to this project must be accompanied by a
10 | [Contributor License Agreement](https://cla.developers.google.com/about) (CLA).
11 | You (or your employer) retain the copyright to your contribution; this simply
12 | gives us permission to use and redistribute your contributions as part of the
13 | project.
14 |
15 | If you or your current employer have already signed the Google CLA (even if it
16 | was for a different project), you probably don't need to do it again.
17 |
18 | Visit
list(object({
value = string
name = string
})) | `[]` | no |
12 | | ingress | Ingress of Cloud Run | `string` | n/a | yes |
13 | | labels | A map of key/value label pairs to assign to the bucket | `map(string)` | n/a | yes |
14 | | limits | Resource limits to the container | `map(string)` | n/a | yes |
15 | | liveness\_probe | helth check | object(|
{
initial_delay_seconds = number,
timeout_seconds = number,
period_seconds = number,
failure_threshold = number,
http_get = object(
{
path = string
}
)
}
)
{
"failure_threshold": 3,
"http_get": {
"path": "/"
},
"initial_delay_seconds": 600,
"period_seconds": 300,
"timeout_seconds": 60
} | no |
16 | | location | Google cloud location where the resource will be created | `string` | n/a | yes |
17 | | project\_id | GCP project ID | `string` | n/a | yes |
18 | | service\_account\_email | cloud run service account email | `string` | n/a | yes |
19 | | vpc\_access\_connector\_id | VPC access connector id | `string` | n/a | yes |
20 | | vpc\_egress | VPC access egress | `string` | n/a | yes |
21 |
22 | ## Outputs
23 |
24 | | Name | Description |
25 | |------|-------------|
26 | | cloud\_run | Cloud Run service |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.github/workflows/lint.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | # NOTE: This file is automatically generated from values at:
16 | # https://github.com/GoogleCloudPlatform/cloud-foundation-toolkit/blob/master/infra/terraform/test-org/org/locals.tf
17 |
18 | name: 'lint'
19 |
20 | on:
21 | workflow_dispatch:
22 | pull_request:
23 | branches:
24 | - main
25 |
26 | concurrency:
27 | group: '${{ github.workflow }}-${{ github.head_ref || github.ref }}'
28 | cancel-in-progress: true
29 |
30 | jobs:
31 | lint:
32 | name: 'lint'
33 | runs-on: 'ubuntu-latest'
34 | steps:
35 | - uses: 'actions/checkout@v4'
36 | - id: variables
37 | run: |
38 | MAKEFILE=$(find . -name Makefile -print -quit)
39 | if [ -z "$MAKEFILE" ]; then
40 | echo dev-tools=gcr.io/cloud-foundation-cicd/cft/developer-tools:1 >> "$GITHUB_OUTPUT"
41 | else
42 | VERSION=$(grep "DOCKER_TAG_VERSION_DEVELOPER_TOOLS := " $MAKEFILE | cut -d\ -f3)
43 | IMAGE=$(grep "DOCKER_IMAGE_DEVELOPER_TOOLS := " $MAKEFILE | cut -d\ -f3)
44 | REGISTRY=$(grep "REGISTRY_URL := " $MAKEFILE | cut -d\ -f3)
45 | echo dev-tools=${REGISTRY}/${IMAGE}:${VERSION} >> "$GITHUB_OUTPUT"
46 | fi
47 | - run: docker run --rm -e ENABLE_BPMETADATA -v ${{ github.workspace }}:/workspace ${{ steps.variables.outputs.dev-tools }} module-swapper
48 | env:
49 | ENABLE_BPMETADATA: 1
50 |
51 | - run: docker run --rm -e ENABLE_BPMETADATA -v ${{ github.workspace }}:/workspace ${{ steps.variables.outputs.dev-tools }} /usr/local/bin/test_lint.sh
52 | env:
53 | ENABLE_BPMETADATA: 1
54 |
55 |
--------------------------------------------------------------------------------
/infra/modules/cloudrun/metadata.display.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | apiVersion: blueprints.cloud.google.com/v1alpha1
16 | kind: BlueprintMetadata
17 | metadata:
18 | name: terraform-large-data-sharing-golang-webapp-cloudrun-display
19 | annotations:
20 | config.kubernetes.io/local-config: "true"
21 | spec:
22 | info:
23 | title: cloudrun module
24 | source:
25 | repo: https://github.com/GoogleCloudPlatform/terraform-large-data-sharing-golang-webapp.git
26 | sourceType: git
27 | dir: /infra/modules/cloudrun
28 | ui:
29 | input:
30 | variables:
31 | cloud_run_image:
32 | name: cloud_run_image
33 | title: Cloud Run Image
34 | cloud_run_name:
35 | name: cloud_run_name
36 | title: Cloud Run Name
37 | container_port:
38 | name: container_port
39 | title: Container Port
40 | env_vars:
41 | name: env_vars
42 | title: Env Vars
43 | ingress:
44 | name: ingress
45 | title: Ingress
46 | labels:
47 | name: labels
48 | title: Labels
49 | limits:
50 | name: limits
51 | title: Limits
52 | liveness_probe:
53 | name: liveness_probe
54 | title: Liveness Probe
55 | location:
56 | name: location
57 | title: Location
58 | project_id:
59 | name: project_id
60 | title: Project Id
61 | service_account_email:
62 | name: service_account_email
63 | title: Service Account Email
64 | vpc_access_connector_id:
65 | name: vpc_access_connector_id
66 | title: Vpc Access Connector Id
67 | vpc_egress:
68 | name: vpc_egress
69 | title: Vpc Egress
70 |
--------------------------------------------------------------------------------
/infra/modules/cloudrun/main.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | resource "google_cloud_run_v2_service" "main" {
18 | name = var.cloud_run_name
19 | location = var.location
20 | ingress = var.ingress
21 | template {
22 | service_account = var.service_account_email
23 | scaling {
24 | max_instance_count = 4
25 | }
26 | containers {
27 | image = var.cloud_run_image
28 | liveness_probe {
29 | initial_delay_seconds = lookup(var.liveness_probe, "initial_delay_seconds", null)
30 | timeout_seconds = lookup(var.liveness_probe, "timeout_seconds", null)
31 | period_seconds = lookup(var.liveness_probe, "period_seconds", null)
32 | failure_threshold = lookup(var.liveness_probe, "failure_threshold", null)
33 | http_get {
34 | path = lookup(var.liveness_probe.http_get, "path", null)
35 | }
36 | }
37 | resources {
38 | limits = var.limits
39 | cpu_idle = true
40 | }
41 | dynamic "env" {
42 | for_each = var.env_vars
43 | content {
44 | name = env.value["name"]
45 | value = env.value["value"]
46 | }
47 | }
48 | ports {
49 | container_port = var.container_port
50 | }
51 | }
52 | vpc_access {
53 | connector = var.vpc_access_connector_id
54 | egress = var.vpc_egress
55 | }
56 | }
57 | labels = var.labels
58 | }
59 |
60 | resource "google_cloud_run_service_iam_policy" "policy" {
61 | project = var.project_id
62 | location = var.location
63 | service = google_cloud_run_v2_service.main.name
64 | policy_data = data.google_iam_policy.cloud_run.policy_data
65 | }
66 |
67 | data "google_iam_policy" "cloud_run" {
68 | binding {
69 | role = "roles/run.invoker"
70 | members = [
71 | "allUsers"
72 | ]
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/infra/modules/firestore/metadata.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | apiVersion: blueprints.cloud.google.com/v1alpha1
16 | kind: BlueprintMetadata
17 | metadata:
18 | name: terraform-large-data-sharing-golang-webapp-firestore
19 | annotations:
20 | config.kubernetes.io/local-config: "true"
21 | spec:
22 | info:
23 | title: firestore module
24 | source:
25 | repo: https://github.com/GoogleCloudPlatform/terraform-large-data-sharing-golang-webapp.git
26 | sourceType: git
27 | dir: /infra/modules/firestore
28 | actuationTool:
29 | flavor: Terraform
30 | version: '>= 0.13'
31 | description: {}
32 | content:
33 | examples:
34 | - name: simple_example
35 | location: examples/simple_example
36 | interfaces:
37 | variables:
38 | - name: collection_fields
39 | description: collection id with respect to its fields
40 | varType: map(any)
41 | required: true
42 | - name: init
43 | description: Initialize resource or not
44 | varType: bool
45 | required: true
46 | - name: project_id
47 | description: GCP project ID.
48 | varType: string
49 | required: true
50 | requirements:
51 | roles:
52 | - level: Project
53 | roles:
54 | - roles/storage.admin
55 | - roles/datastore.owner
56 | - roles/appengine.appAdmin
57 | - roles/compute.admin
58 | - roles/compute.networkAdmin
59 | - roles/cloudtrace.admin
60 | - roles/iam.serviceAccountAdmin
61 | - roles/iam.serviceAccountUser
62 | - roles/resourcemanager.projectIamAdmin
63 | - roles/run.admin
64 | - roles/monitoring.admin
65 | - roles/vpcaccess.admin
66 | services:
67 | - cloudresourcemanager.googleapis.com
68 | - compute.googleapis.com
69 | - run.googleapis.com
70 | - iam.googleapis.com
71 | - firestore.googleapis.com
72 | - vpcaccess.googleapis.com
73 | - serviceusage.googleapis.com
74 | - monitoring.googleapis.com
75 | - cloudtrace.googleapis.com
76 |
--------------------------------------------------------------------------------
/infra/modules/networking/metadata.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | apiVersion: blueprints.cloud.google.com/v1alpha1
16 | kind: BlueprintMetadata
17 | metadata:
18 | name: terraform-large-data-sharing-golang-webapp-networking
19 | annotations:
20 | config.kubernetes.io/local-config: "true"
21 | spec:
22 | info:
23 | title: networking module
24 | source:
25 | repo: https://github.com/GoogleCloudPlatform/terraform-large-data-sharing-golang-webapp.git
26 | sourceType: git
27 | dir: /infra/modules/networking
28 | actuationTool:
29 | flavor: Terraform
30 | version: '>= 0.13'
31 | description: {}
32 | content:
33 | examples:
34 | - name: simple_example
35 | location: examples/simple_example
36 | interfaces:
37 | variables:
38 | - name: project_id
39 | description: GCP project ID.
40 | varType: string
41 | required: true
42 | - name: region
43 | description: Google cloud region where the resource will be created.
44 | varType: string
45 | required: true
46 | outputs:
47 | - name: netowrk_self_link
48 | description: Network self link
49 | - name: subnet_netowrk_self_link
50 | description: Subnet netowrk self link
51 | - name: vpc_access_connector_id
52 | description: VPC access connector id
53 | requirements:
54 | roles:
55 | - level: Project
56 | roles:
57 | - roles/storage.admin
58 | - roles/datastore.owner
59 | - roles/appengine.appAdmin
60 | - roles/compute.admin
61 | - roles/compute.networkAdmin
62 | - roles/cloudtrace.admin
63 | - roles/iam.serviceAccountAdmin
64 | - roles/iam.serviceAccountUser
65 | - roles/resourcemanager.projectIamAdmin
66 | - roles/run.admin
67 | - roles/monitoring.admin
68 | - roles/vpcaccess.admin
69 | services:
70 | - cloudresourcemanager.googleapis.com
71 | - compute.googleapis.com
72 | - run.googleapis.com
73 | - iam.googleapis.com
74 | - firestore.googleapis.com
75 | - vpcaccess.googleapis.com
76 | - serviceusage.googleapis.com
77 | - monitoring.googleapis.com
78 | - cloudtrace.googleapis.com
79 |
--------------------------------------------------------------------------------
/infra/modules/storage/metadata.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | apiVersion: blueprints.cloud.google.com/v1alpha1
16 | kind: BlueprintMetadata
17 | metadata:
18 | name: terraform-large-data-sharing-golang-webapp-storage
19 | annotations:
20 | config.kubernetes.io/local-config: "true"
21 | spec:
22 | info:
23 | title: storage module
24 | source:
25 | repo: https://github.com/GoogleCloudPlatform/terraform-large-data-sharing-golang-webapp.git
26 | sourceType: git
27 | dir: /infra/modules/storage
28 | actuationTool:
29 | flavor: Terraform
30 | version: '>= 0.13'
31 | description: {}
32 | content:
33 | examples:
34 | - name: simple_example
35 | location: examples/simple_example
36 | interfaces:
37 | variables:
38 | - name: labels
39 | description: A map of key/value label pairs to assign to the bucket.
40 | varType: map(string)
41 | defaultValue: {}
42 | - name: location
43 | description: Bucket location
44 | varType: string
45 | required: true
46 | - name: name
47 | description: Bucket name
48 | varType: string
49 | required: true
50 | - name: project_id
51 | description: GCP project ID.
52 | varType: string
53 | required: true
54 | outputs:
55 | - name: bucket_name
56 | description: Bucket name
57 | requirements:
58 | roles:
59 | - level: Project
60 | roles:
61 | - roles/storage.admin
62 | - roles/datastore.owner
63 | - roles/appengine.appAdmin
64 | - roles/compute.admin
65 | - roles/compute.networkAdmin
66 | - roles/cloudtrace.admin
67 | - roles/iam.serviceAccountAdmin
68 | - roles/iam.serviceAccountUser
69 | - roles/resourcemanager.projectIamAdmin
70 | - roles/run.admin
71 | - roles/monitoring.admin
72 | - roles/vpcaccess.admin
73 | services:
74 | - cloudresourcemanager.googleapis.com
75 | - compute.googleapis.com
76 | - run.googleapis.com
77 | - iam.googleapis.com
78 | - firestore.googleapis.com
79 | - vpcaccess.googleapis.com
80 | - serviceusage.googleapis.com
81 | - monitoring.googleapis.com
82 | - cloudtrace.googleapis.com
83 |
--------------------------------------------------------------------------------
/infra/metadata.display.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | apiVersion: blueprints.cloud.google.com/v1alpha1
16 | kind: BlueprintMetadata
17 | metadata:
18 | name: terraform-large-data-sharing-golang-webapp-display
19 | annotations:
20 | config.kubernetes.io/local-config: "true"
21 | spec:
22 | info:
23 | title: Large Data Sharing Golang Web App
24 | source:
25 | repo: https://github.com/GoogleCloudPlatform/terraform-large-data-sharing-golang-webapp.git
26 | sourceType: git
27 | dir: /infra
28 | ui:
29 | input:
30 | variables:
31 | bucket_location:
32 | name: bucket_location
33 | title: Bucket Location
34 | disable_services_on_destroy:
35 | name: disable_services_on_destroy
36 | title: Disable Services On Destroy
37 | init:
38 | name: init
39 | title: Init
40 | labels:
41 | name: labels
42 | title: Labels
43 | lds_client_image:
44 | name: lds_client_image
45 | title: Lds Client Image
46 | lds_firestore:
47 | name: lds_firestore
48 | title: Lds Firestore
49 | lds_firestore_field_name:
50 | name: lds_firestore_field_name
51 | title: Lds Firestore Field Name
52 | lds_firestore_field_orderNo:
53 | name: lds_firestore_field_orderNo
54 | title: Lds Firestore Field OrderNo
55 | lds_firestore_field_path:
56 | name: lds_firestore_field_path
57 | title: Lds Firestore Field Path
58 | lds_firestore_field_size:
59 | name: lds_firestore_field_size
60 | title: Lds Firestore Field Size
61 | lds_firestore_field_tags:
62 | name: lds_firestore_field_tags
63 | title: Lds Firestore Field Tags
64 | lds_initialization_archive_file_name:
65 | name: lds_initialization_archive_file_name
66 | title: Lds Initialization Archive File Name
67 | lds_initialization_bucket_name:
68 | name: lds_initialization_bucket_name
69 | title: Lds Initialization Bucket Name
70 | lds_server_image:
71 | name: lds_server_image
72 | title: Lds Server Image
73 | project_id:
74 | name: project_id
75 | title: Project Id
76 | region:
77 | name: region
78 | title: Region
79 |
--------------------------------------------------------------------------------
/infra/modules/cloudrun/variables.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | variable "project_id" {
18 | description = "GCP project ID"
19 | type = string
20 | }
21 |
22 | variable "location" {
23 | description = "Google cloud location where the resource will be created"
24 | type = string
25 | }
26 |
27 | variable "cloud_run_name" {
28 | description = "Name of Cloud Run"
29 | type = string
30 | }
31 |
32 | variable "cloud_run_image" {
33 | description = "Docker image for Cloud Run"
34 | type = string
35 | }
36 |
37 | # cpu = (core count * 1000)m
38 | # memory = (size) Mi/Gi
39 | variable "limits" {
40 | type = map(string)
41 | description = "Resource limits to the container"
42 | }
43 |
44 | variable "container_port" {
45 | description = "Container port"
46 | type = string
47 | }
48 |
49 | variable "env_vars" {
50 | description = "Environment variables"
51 | type = list(object({
52 | value = string
53 | name = string
54 | }))
55 | default = []
56 | }
57 |
58 | variable "ingress" {
59 | description = "Ingress of Cloud Run"
60 | type = string
61 | }
62 |
63 | variable "vpc_access_connector_id" {
64 | description = "VPC access connector id"
65 | type = string
66 | }
67 |
68 | variable "vpc_egress" {
69 | description = "VPC access egress"
70 | type = string
71 | }
72 |
73 | variable "service_account_email" {
74 | description = "cloud run service account email"
75 | type = string
76 | }
77 |
78 | variable "liveness_probe" {
79 | description = "helth check"
80 | type = object(
81 | {
82 | initial_delay_seconds = number,
83 | timeout_seconds = number,
84 | period_seconds = number,
85 | failure_threshold = number,
86 | http_get = object(
87 | {
88 | path = string
89 | }
90 | )
91 | }
92 | )
93 | default = {
94 | initial_delay_seconds = 600,
95 | timeout_seconds = 60,
96 | period_seconds = 300,
97 | failure_threshold = 3,
98 | http_get = {
99 | path = "/"
100 | }
101 | }
102 | }
103 |
104 | variable "labels" {
105 | description = "A map of key/value label pairs to assign to the bucket"
106 | type = map(string)
107 | }
108 |
--------------------------------------------------------------------------------
/infra/modules/load-balancer/main.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | resource "google_compute_backend_bucket" "cdn" {
18 | project = var.project_id
19 | name = "lds-cdn-golang"
20 | bucket_name = var.bucket_name
21 | enable_cdn = true
22 | cdn_policy {
23 | cache_mode = "CACHE_ALL_STATIC"
24 | client_ttl = 3600
25 | default_ttl = 3600
26 | max_ttl = 86400
27 | negative_caching = true
28 | serve_while_stale = 86400
29 | }
30 | custom_response_headers = [
31 | "X-Cache-ID: {cdn_cache_id}",
32 | "X-Cache-Hit: {cdn_cache_status}",
33 | "X-Client-Location: {client_region_subdivision}, {client_city}",
34 | "X-Client-IP-Address: {client_ip_address}"
35 | ]
36 | }
37 |
38 | resource "google_compute_region_network_endpoint_group" "client" {
39 | name = "lds-client-golang"
40 | network_endpoint_type = "SERVERLESS"
41 | region = var.region
42 | cloud_run {
43 | service = var.client_service_name
44 | }
45 | }
46 |
47 | resource "google_compute_backend_service" "lds" {
48 | name = "lds-golang"
49 | load_balancing_scheme = "EXTERNAL"
50 | backend {
51 | group = google_compute_region_network_endpoint_group.client.id
52 | }
53 | }
54 |
55 | resource "google_compute_url_map" "lds" {
56 | project = var.project_id
57 | name = "lds-lb-golang"
58 | default_service = google_compute_backend_bucket.cdn.id
59 | host_rule {
60 | path_matcher = "client"
61 | hosts = [
62 | "*",
63 | ]
64 | }
65 | path_matcher {
66 | name = "client"
67 | default_service = google_compute_backend_service.lds.id
68 | path_rule {
69 | paths = [
70 | "/${var.resource_path}/*",
71 | ]
72 | service = google_compute_backend_bucket.cdn.id
73 | }
74 | }
75 | }
76 |
77 | resource "google_compute_target_http_proxy" "lds" {
78 | project = var.project_id
79 | name = "lds-proxy-golang"
80 | url_map = google_compute_url_map.lds.self_link
81 | }
82 |
83 | resource "google_compute_global_forwarding_rule" "lds" {
84 | project = var.project_id
85 | labels = var.labels
86 | name = "lds-frontend-golang"
87 | target = google_compute_target_http_proxy.lds.self_link
88 | ip_address = google_compute_global_address.lds.address
89 | port_range = "80"
90 | }
91 |
92 | resource "google_compute_global_address" "lds" {
93 | project = var.project_id
94 | name = "lds-external-ip-golang"
95 | ip_version = "IPV4"
96 | address_type = "EXTERNAL"
97 | }
98 |
--------------------------------------------------------------------------------
/infra/modules/load-balancer/metadata.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | apiVersion: blueprints.cloud.google.com/v1alpha1
16 | kind: BlueprintMetadata
17 | metadata:
18 | name: terraform-large-data-sharing-golang-webapp-load-balancer
19 | annotations:
20 | config.kubernetes.io/local-config: "true"
21 | spec:
22 | info:
23 | title: load-balancer module
24 | source:
25 | repo: https://github.com/GoogleCloudPlatform/terraform-large-data-sharing-golang-webapp.git
26 | sourceType: git
27 | dir: /infra/modules/load-balancer
28 | actuationTool:
29 | flavor: Terraform
30 | version: '>= 0.13'
31 | description: {}
32 | content:
33 | examples:
34 | - name: simple_example
35 | location: examples/simple_example
36 | interfaces:
37 | variables:
38 | - name: bucket_name
39 | description: Bucket name
40 | varType: string
41 | required: true
42 | - name: client_service_name
43 | description: Frontend service name
44 | varType: string
45 | required: true
46 | - name: labels
47 | description: A map of key/value label pairs to assign to the bucket.
48 | varType: map(string)
49 | required: true
50 | - name: project_id
51 | description: GCP project ID.
52 | varType: string
53 | required: true
54 | - name: region
55 | description: Google cloud region where the resource will be created.
56 | varType: string
57 | required: true
58 | - name: resource_path
59 | description: Resource folder path
60 | varType: string
61 | required: true
62 | outputs:
63 | - name: backend_bucket_name
64 | description: The name of the backend bucket used for Cloud CDN
65 | - name: lb_external_ip
66 | description: Frontend IP address of the load balancer
67 | requirements:
68 | roles:
69 | - level: Project
70 | roles:
71 | - roles/storage.admin
72 | - roles/datastore.owner
73 | - roles/appengine.appAdmin
74 | - roles/compute.admin
75 | - roles/compute.networkAdmin
76 | - roles/cloudtrace.admin
77 | - roles/iam.serviceAccountAdmin
78 | - roles/iam.serviceAccountUser
79 | - roles/resourcemanager.projectIamAdmin
80 | - roles/run.admin
81 | - roles/monitoring.admin
82 | - roles/vpcaccess.admin
83 | services:
84 | - cloudresourcemanager.googleapis.com
85 | - compute.googleapis.com
86 | - run.googleapis.com
87 | - iam.googleapis.com
88 | - firestore.googleapis.com
89 | - vpcaccess.googleapis.com
90 | - serviceusage.googleapis.com
91 | - monitoring.googleapis.com
92 | - cloudtrace.googleapis.com
93 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Large data sharing Go web app
2 |
3 | ## Description
4 |
5 | ### Tagline
6 |
7 | Create a web app to share large quantities of files to users across the globe
8 |
9 | ### Detailed
10 |
11 | This solution quickly and securely deploys a three-tiered web app with a Javascript front end, a Go back end, and a Firestore database on GCP. The goal of this solution is to utilize Google's Cloud CDN to serve large quantities of files (e.g., images, videos, documents) to users across the globe.
12 |
13 | The resources/services/activations/deletions that this module will create/trigger are:
14 |
15 | - Cloud Load Balancing
16 | - Cloud Storage
17 | - Cloud CDN
18 | - Cloud Run
19 | - Firestore
20 |
21 |
22 | ## Inputs
23 |
24 | | Name | Description | Type | Default | Required |
25 | |------|-------------|------|---------|:--------:|
26 | | bucket\_location | Bucket location. https://cloud.google.com/storage/docs/locations | `string` | `"US"` | no |
27 | | disable\_services\_on\_destroy | Whether project services will be disabled when the resources are destroyed. | `bool` | `false` | no |
28 | | init | Initialize resource or not | `bool` | `true` | no |
29 | | labels | A map of key/value label pairs to assign to the resources. | `map(string)` | {
"app": "large-data-sharing"
} | no |
30 | | lds\_client\_image | Docker image for frontend | `string` | `"gcr.io/hsa-resources-public/hsa-lds-golang-frontend:latest"` | no |
31 | | lds\_initialization\_archive\_file\_name | Archive file's name in lds-initialization bucket | `string` | `"initialization.tar.gz"` | no |
32 | | lds\_initialization\_bucket\_name | Bucket for cloud run job | `string` | `"jss-resources"` | no |
33 | | lds\_server\_image | Docker image for backend | `string` | `"gcr.io/hsa-resources-public/hsa-lds-golang-backend:latest"` | no |
34 | | project\_id | GCP project ID. | `string` | n/a | yes |
35 | | region | Google cloud region where the resource will be created. | `string` | `"us-west1"` | no |
36 | | firestore_collection_id | Firestore collection id. | `string` | `"fileMetadata"` | no |
37 |
38 | ## Outputs
39 |
40 | | Name | Description |
41 | |------|-------------|
42 | | bucket\_name | Bucket name |
43 | | lb\_external\_ip | Frontend IP address of the load balancer |
44 | | neos\_walkthrough\_url | Neos Tutorial URL |
45 |
46 |
47 |
48 | ## Requirements
49 |
50 | These sections describe requirements for using this module.
51 |
52 | ### Software
53 |
54 | The following dependencies must be available:
55 |
56 | - [Terraform](https://developer.hashicorp.com/terraform/downloads) v0.13
57 | - [Terraform Provider for GCP](https://registry.terraform.io/providers/hashicorp/google/latest/docs) plugin v4.57
58 |
59 | ### Service Account
60 |
61 | - roles/storage.objectAdmin
62 | - roles/datastore.user
63 | - roles/compute.networkUser
64 |
65 | A service account with the following roles must be used to provision
66 | the resources of this module:
67 |
68 | ### APIs
69 |
70 | A project with the following APIs enabled must be used to host the
71 | resources of this module:
72 |
73 | - compute.googleapis.com
74 | - run.googleapis.com
75 | - iam.googleapis.com
76 | - firestore.googleapis.com
77 | - vpcaccess.googleapis.com
78 | - monitoring.googleapis.com
79 | - cloudtrace.googleapis.com
80 |
--------------------------------------------------------------------------------
/infra/Makefile:
--------------------------------------------------------------------------------
1 | # Copyright 2023 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 | # https://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 | # Please note that this file was generated from [terraform-google-module-template](https://github.com/terraform-google-modules/terraform-google-module-template).
16 | # Please make sure to contribute relevant changes upstream!
17 |
18 | # Make will use bash instead of sh
19 | SHELL := /usr/bin/env bash
20 |
21 | DOCKER_TAG_VERSION_DEVELOPER_TOOLS := 1
22 | DOCKER_IMAGE_DEVELOPER_TOOLS := cft/developer-tools
23 | REGISTRY_URL := gcr.io/cloud-foundation-cicd
24 | ENABLE_BPMETADATA := 1
25 | export ENABLE_BPMETADATA
26 |
27 | # Enter docker container for local development
28 | .PHONY: docker_run
29 | docker_run:
30 | docker run --rm -it \
31 | -e SERVICE_ACCOUNT_JSON \
32 | -v "$(CURDIR)":/workspace \
33 | $(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
34 | /bin/bash
35 |
36 | # Execute prepare tests within the docker container
37 | .PHONY: docker_test_prepare
38 | docker_test_prepare:
39 | docker run --rm -it \
40 | -e SERVICE_ACCOUNT_JSON \
41 | -e TF_VAR_org_id \
42 | -e TF_VAR_folder_id \
43 | -e TF_VAR_billing_account \
44 | -v "$(CURDIR)":/workspace \
45 | $(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
46 | /usr/local/bin/execute_with_credentials.sh prepare_environment
47 |
48 | # Clean up test environment within the docker container
49 | .PHONY: docker_test_cleanup
50 | docker_test_cleanup:
51 | docker run --rm -it \
52 | -e SERVICE_ACCOUNT_JSON \
53 | -e TF_VAR_org_id \
54 | -e TF_VAR_folder_id \
55 | -e TF_VAR_billing_account \
56 | -v "$(CURDIR)":/workspace \
57 | $(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
58 | /usr/local/bin/execute_with_credentials.sh cleanup_environment
59 |
60 | # Execute lint tests within the docker container
61 | .PHONY: docker_test_lint
62 | docker_test_lint:
63 | docker run --rm -it \
64 | -e ENABLE_BPMETADATA \
65 | -e EXCLUDE_LINT_DIRS \
66 | -v "$(CURDIR)":/workspace \
67 | $(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
68 | /usr/local/bin/test_lint.sh
69 |
70 | # Execute lint tests non tty within the docker container
71 | .PHONY: docker_test_lint_gha
72 | docker_test_lint_gha:
73 | docker run --rm \
74 | -e EXCLUDE_LINT_DIRS \
75 | -v "$(CURDIR)":/workspace \
76 | $(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
77 | /usr/local/bin/test_lint.sh
78 |
79 | # Generate documentation
80 | .PHONY: docker_generate_docs
81 | docker_generate_docs:
82 | docker run --rm -it \
83 | -e ENABLE_BPMETADATA \
84 | -v "$(dir ${CURDIR})":/workspace \
85 | $(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
86 | /bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate_docs "-d -p infra"'
87 |
88 | # Alias for backwards compatibility
89 | .PHONY: generate_docs
90 | generate_docs: docker_generate_docs
91 |
--------------------------------------------------------------------------------
/infra/variables.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | variable "project_id" {
18 | description = "GCP project ID."
19 | type = string
20 | validation {
21 | condition = var.project_id != ""
22 | error_message = "Error: project_id is required"
23 | }
24 | }
25 |
26 | variable "region" {
27 | description = "Google cloud region where the resource will be created."
28 | type = string
29 | default = "us-west1"
30 | }
31 |
32 | variable "disable_services_on_destroy" {
33 | description = "Whether project services will be disabled when the resources are destroyed."
34 | type = bool
35 | default = false
36 | }
37 |
38 | variable "bucket_location" {
39 | description = "Bucket location. https://cloud.google.com/storage/docs/locations"
40 | type = string
41 | default = "US"
42 |
43 | validation {
44 | condition = contains(["ASIA", "EU", "US"], var.bucket_location)
45 | error_message = "Allowed values for type are \"ASIA\", \"EU\", \"US\"."
46 | }
47 | }
48 |
49 | variable "lds_server_image" {
50 | description = "Docker image for backend"
51 | type = string
52 | default = "gcr.io/hsa-public/hsa-lds-golang-backend:firestore-db"
53 | }
54 |
55 | variable "lds_client_image" {
56 | description = "Docker image for frontend"
57 | type = string
58 | default = "gcr.io/hsa-resources-public/hsa-lds-golang-frontend:latest"
59 | }
60 |
61 | variable "lds_initialization_bucket_name" {
62 | description = "Bucket for cloud run job"
63 | type = string
64 | default = "jss-resources"
65 | }
66 |
67 | variable "lds_initialization_archive_file_name" {
68 | description = "Archive file's name in lds-initialization bucket"
69 | type = string
70 | default = "initialization.tar.gz"
71 | }
72 |
73 | variable "labels" {
74 | type = map(string)
75 | description = "A map of key/value label pairs to assign to the resources."
76 | default = {
77 | app = "large-data-sharing-golang"
78 | }
79 | }
80 |
81 | variable "lds_firestore" {
82 | description = "Firestore collection id"
83 | type = string
84 | default = "fileMetadata-cdn"
85 | }
86 |
87 | variable "lds_firestore_field_path" {
88 | description = "Firestore field: path"
89 | type = string
90 | default = "path"
91 | }
92 |
93 | variable "lds_firestore_field_name" {
94 | description = "Firestore field: name"
95 | type = string
96 | default = "name"
97 | }
98 |
99 | variable "lds_firestore_field_size" {
100 | description = "Firestore field: size"
101 | type = string
102 | default = "size"
103 | }
104 |
105 | variable "lds_firestore_field_tags" {
106 | description = "Firestore field: tags"
107 | type = string
108 | default = "tags"
109 | }
110 |
111 | variable "lds_firestore_field_orderNo" {
112 | description = "Firestore field: orderNo"
113 | type = string
114 | default = "orderNo"
115 | }
116 |
--------------------------------------------------------------------------------
/infra/README.md:
--------------------------------------------------------------------------------
1 | # Large Data Sharing Golang Web App
2 |
3 | ## Description
4 |
5 | ### Tagline
6 |
7 | Create a web app to share large quantities of files to users across the globe
8 |
9 | ### Detailed
10 |
11 | This solution provides an end-to-end demonstration on how a developer would architect an application that can handle large quantities of files operations on GCP. The goal of this solution is to utilize Google Cloud CDN to serve large quantities of files.
12 |
13 | The resources/services/activations/deletions that this module will create/trigger are:
14 |
15 | - Cloud Load Balancing
16 | - Cloud Storage
17 | - Cloud CDN
18 | - Cloud Run
19 | - Firestore
20 |
21 |
22 | ## Inputs
23 |
24 | | Name | Description | Type | Default | Required |
25 | |------|-------------|------|---------|:--------:|
26 | | bucket\_location | Bucket location. https://cloud.google.com/storage/docs/locations | `string` | `"US"` | no |
27 | | disable\_services\_on\_destroy | Whether project services will be disabled when the resources are destroyed. | `bool` | `false` | no |
28 | | labels | A map of key/value label pairs to assign to the resources. | `map(string)` | {
"app": "large-data-sharing-golang"
} | no |
29 | | lds\_client\_image | Docker image for frontend | `string` | `"gcr.io/hsa-resources-public/hsa-lds-golang-frontend:latest"` | no |
30 | | lds\_firestore | Firestore collection id | `string` | `"fileMetadata-cdn"` | no |
31 | | lds\_firestore\_field\_name | Firestore field: name | `string` | `"name"` | no |
32 | | lds\_firestore\_field\_orderNo | Firestore field: orderNo | `string` | `"orderNo"` | no |
33 | | lds\_firestore\_field\_path | Firestore field: path | `string` | `"path"` | no |
34 | | lds\_firestore\_field\_size | Firestore field: size | `string` | `"size"` | no |
35 | | lds\_firestore\_field\_tags | Firestore field: tags | `string` | `"tags"` | no |
36 | | lds\_initialization\_archive\_file\_name | Archive file's name in lds-initialization bucket | `string` | `"initialization.tar.gz"` | no |
37 | | lds\_initialization\_bucket\_name | Bucket for cloud run job | `string` | `"jss-resources"` | no |
38 | | lds\_server\_image | Docker image for backend | `string` | `"gcr.io/hsa-public/hsa-lds-golang-backend:firestore-db"` | no |
39 | | project\_id | GCP project ID. | `string` | n/a | yes |
40 | | region | Google cloud region where the resource will be created. | `string` | `"us-west1"` | no |
41 |
42 | ## Outputs
43 |
44 | | Name | Description |
45 | |------|-------------|
46 | | backend\_bucket\_name | The name of the backend bucket used for Cloud CDN |
47 | | bucket\_name | Bucket name |
48 | | db\_name | Firestore database name |
49 | | lb\_external\_ip | Frontend IP address of the load balancer |
50 | | neos\_walkthrough\_url | Neos Tutorial URL |
51 |
52 |
53 |
54 | ## Requirements
55 |
56 | These sections describe requirements for using this module.
57 |
58 | ### Software
59 |
60 | The following dependencies must be available:
61 |
62 | - [Terraform](https://developer.hashicorp.com/terraform/downloads) v0.13
63 | - [Terraform Provider for GCP](https://registry.terraform.io/providers/hashicorp/google/latest/docs) plugin v4.57
64 |
65 | ### Service Account
66 |
67 | - roles/storage.objectAdmin
68 | - roles/datastore.user
69 | - roles/compute.networkUser
70 |
71 | A service account with the following roles must be used to provision
72 | the resources of this module:
73 |
74 | ### APIs
75 |
76 | A project with the following APIs enabled must be used to host the
77 | resources of this module:
78 |
79 | - compute.googleapis.com
80 | - run.googleapis.com
81 | - iam.googleapis.com
82 | - firestore.googleapis.com
83 | - vpcaccess.googleapis.com
84 | - monitoring.googleapis.com
85 |
--------------------------------------------------------------------------------
/infra/postdeployment.tf:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2023 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 | migrate_data_commands = [
19 | "gsutil cp gs://${var.lds_initialization_bucket_name}/execution.sh .",
20 | "gsutil cp gs://${var.lds_initialization_bucket_name}/upload.sh .",
21 | "bash execution.sh ${var.lds_initialization_bucket_name} ${var.lds_initialization_archive_file_name} ${module.cloud_run_client.cloud_run.uri}",
22 | ]
23 | }
24 |
25 | resource "google_cloud_run_v2_job" "migrate_data" {
26 | depends_on = [
27 | module.project_services,
28 | ]
29 | name = "migration-data-job-golang"
30 | location = var.region
31 | launch_stage = "BETA"
32 | template {
33 | template {
34 | service_account = google_service_account.cloudrun.email
35 | containers {
36 | image = "gcr.io/google.com/cloudsdktool/cloud-sdk"
37 | command = ["/bin/bash"]
38 | args = [
39 | "-c",
40 | join(" && ", local.migrate_data_commands)
41 | ]
42 | }
43 | vpc_access {
44 | connector = module.networking.vpc_access_connector_id
45 | egress = "ALL_TRAFFIC"
46 | }
47 | }
48 | }
49 | labels = var.labels
50 | }
51 |
52 | resource "google_cloud_run_v2_job" "reset_data" {
53 | depends_on = [
54 | module.project_services,
55 | ]
56 | name = "reset-data-job-golang"
57 | location = var.region
58 | launch_stage = "BETA"
59 | template {
60 | template {
61 | service_account = google_service_account.cloudrun.email
62 | containers {
63 | image = "curlimages/curl"
64 | command = ["/bin/sh"]
65 | args = [
66 | "-c",
67 | "curl -X DELETE ${module.cloud_run_server.cloud_run.uri}/api/reset"
68 | ]
69 | }
70 | vpc_access {
71 | connector = module.networking.vpc_access_connector_id
72 | egress = "ALL_TRAFFIC"
73 | }
74 | }
75 | }
76 | labels = var.labels
77 | }
78 |
79 | data "google_compute_zones" "available" {
80 | depends_on = [
81 | module.project_services,
82 | ]
83 | project = var.project_id
84 | region = var.region
85 | }
86 |
87 | resource "google_compute_instance" "initialization" {
88 | depends_on = [
89 | module.project_services,
90 | module.cloud_run_server,
91 | module.cloud_run_client,
92 | ]
93 |
94 | name = "lds-initialization-golang"
95 | machine_type = "n1-standard-1"
96 | zone = data.google_compute_zones.available.names[0]
97 |
98 | boot_disk {
99 | initialize_params {
100 | image = "debian-cloud/debian-11"
101 | }
102 | }
103 |
104 | network_interface {
105 | network = module.networking.netowrk_self_link
106 | subnetwork = module.networking.subnet_netowrk_self_link
107 | }
108 |
109 | service_account {
110 | email = "${data.google_project.project.number}-compute@developer.gserviceaccount.com"
111 | scopes = [
112 | "cloud-platform"
113 | ]
114 | }
115 |
116 | metadata_startup_script = <