|
| 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] |
0 commit comments