File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ terraform {
2+ required_version = " >= 1.0.0"
3+
4+ required_providers {
5+ google = {
6+ source = " hashicorp/google"
7+ version = " ~> 4.0"
8+ }
9+ }
10+ }
11+
12+ provider "google" {
13+ # You can also specify credentials if needed, e.g.:
14+ # credentials = file("path/to/service_account_key.json")
15+
16+ # Replace these with your actual project/region or pass them via variables
17+ project = var. project_id
18+ region = var. region
19+ }
20+
21+ # Ensure the Cloud Storage API is enabled
22+ resource "google_project_service" "storage_api" {
23+ project = var. project_id
24+ service = " storage.googleapis.com"
25+ }
26+
27+ resource "google_storage_bucket" "terraform_state" {
28+ name = var. bucket_name
29+ location = var. region
30+ uniform_bucket_level_access = true
31+
32+ versioning {
33+ enabled = true
34+ }
35+
36+ # If you want Terraform to be able to delete a non-empty bucket,
37+ # set force_destroy to true. Otherwise, it must be empty before deletion.
38+ force_destroy = false
39+ }
40+
41+ output "bucket_name" {
42+ description = " Name of the GCS bucket for Terraform remote state."
43+ value = google_storage_bucket. terraform_state . name
44+ }
Original file line number Diff line number Diff line change 1+ variable "project_id" {
2+ type = string
3+ description = " The GCP project ID where resources will be created."
4+ }
5+
6+ variable "region" {
7+ type = string
8+ description = " The region in which to create the bucket (e.g., 'us-central1')."
9+ default = " us-central1"
10+ }
11+
12+ variable "bucket_name" {
13+ type = string
14+ description = " Name of the GCS bucket to store Terraform state."
15+ }
You can’t perform that action at this time.
0 commit comments