Skip to content

Commit 31f5333

Browse files
authored
Merge branch 'main' into ap/gke-ap-reservation
2 parents 3d41348 + 67a2337 commit 31f5333

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
In this example, we show how to provision a Cloud Storage bucket and then
2+
generate a Terraform backend configuration file.
3+
4+
To run this example, do the following:
5+
6+
1. Initialize Terraform with a local backend:
7+
8+
terraform init
9+
10+
2. Provision resources and create a Cloud Storage bucket for the Terraform
11+
remote backend:
12+
13+
terraform apply
14+
15+
3. Migrate Terraform state to the remote Cloud Storage backend:
16+
17+
terraform init -migrate-state
18+
19+
20+
21+
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
22+
## Inputs
23+
24+
No inputs.
25+
26+
## Outputs
27+
28+
No outputs.
29+
30+
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
# [START storage_remote_terraform_backend_template]
16+
# [START storage_bucket_tf_with_versioning_pap_uap_no_destroy]
17+
resource "random_id" "default" {
18+
byte_length = 8
19+
}
20+
21+
resource "google_storage_bucket" "default" {
22+
name = "${random_id.default.hex}-terraform-remote-backend"
23+
location = "US"
24+
25+
force_destroy = false
26+
public_access_prevention = "enforced"
27+
uniform_bucket_level_access = true
28+
29+
versioning {
30+
enabled = true
31+
}
32+
}
33+
# [END storage_bucket_tf_with_versioning_pap_uap_no_destroy]
34+
35+
# [START storage_remote_backend_local_file]
36+
resource "local_file" "default" {
37+
file_permission = "0644"
38+
filename = "${path.module}/backend.tf"
39+
40+
# You can store the template in a file and use the templatefile function for
41+
# more modularity, if you prefer, instead of storing the template inline as
42+
# we do here.
43+
content = <<-EOT
44+
terraform {
45+
backend "gcs" {
46+
bucket = "${google_storage_bucket.default.name}"
47+
}
48+
}
49+
EOT
50+
}
51+
# [END storage_remote_backend_local_file]
52+
# [END storage_remote_terraform_backend_template]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
apiVersion: blueprints.cloud.google.com/v1alpha1
16+
kind: BlueprintTest
17+
metadata:
18+
name: storage_remote_terraform_backend_template
19+
spec:
20+
skip: true

0 commit comments

Comments
 (0)