{"id":21820582,"url":"https://github.com/sue445/terraform-gcp-template","last_synced_at":"2025-06-24T13:32:34.407Z","repository":{"id":37255370,"uuid":"327021483","full_name":"sue445/terraform-gcp-template","owner":"sue445","description":"Terraform template for Google Cloud (GCP)","archived":false,"fork":false,"pushed_at":"2025-06-13T12:56:55.000Z","size":672,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-13T13:52:05.441Z","etag":null,"topics":["gcp","google-cloud","template","template-project","terraform"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sue445.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-01-05T14:21:12.000Z","updated_at":"2025-06-13T12:56:58.000Z","dependencies_parsed_at":"2024-07-26T11:46:12.114Z","dependency_job_id":"d1d3aef8-8740-4142-ab13-8c6ad1e76955","html_url":"https://github.com/sue445/terraform-gcp-template","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/sue445/terraform-gcp-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sue445%2Fterraform-gcp-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sue445%2Fterraform-gcp-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sue445%2Fterraform-gcp-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sue445%2Fterraform-gcp-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sue445","download_url":"https://codeload.github.com/sue445/terraform-gcp-template/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sue445%2Fterraform-gcp-template/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261685632,"owners_count":23194139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gcp","google-cloud","template","template-project","terraform"],"created_at":"2024-11-27T16:37:47.933Z","updated_at":"2025-06-24T13:32:34.398Z","avatar_url":"https://github.com/sue445.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# terraform-gcp-template\n[Terraform](https://www.terraform.io/) template for [Google Cloud (GCP)](https://cloud.google.com/)\n\n## [Workflow](.github/workflows/terraform.yml) features\n* Authenticating via [Workload Identity Federation](https://cloud.google.com/iam/docs/configuring-workload-identity-federation#github-actions)\n* Run `terraform apply`\n  * Automatically running on `main` branch\n  * Manual running on any branch\n* Run `terraform plan`, `terraform fmt` and [tflint](https://github.com/terraform-linters/tflint)\n* Post `terraform plan` report to PullRequest comment and Job Summaries\n* Slack notification\n\n## Requirements\n* GitHub Actions\n* Terraform v1.0+\n\n## Usage of this template\n### 1. Install tools\n* [tfenv](https://github.com/tfutils/tfenv)\n* [Cloud SDK](https://cloud.google.com/sdk/docs/install)\n  * You can also use the Cloud SDK already installed in [Cloud Shell](https://cloud.google.com/shell)\n\n### 2. Create a repository using this template\n\n### 3. Setup Cloud SDK\n```bash\ngcloud auth login\n# or\ngcloud auth application-default login\n```\n\n### 4. Run setup-terraform.sh\nDownload [scripts/setup-terraform.sh](scripts/setup-terraform.sh) and run\n\ne.g.\n\n```bash\n# Download and add permission\nwget https://raw.githubusercontent.com/sue445/terraform-gcp-template/refs/heads/main/scripts/setup-terraform.sh\nchmod 755 setup-terraform.sh\n\n# Run as dry run mode\n./setup-terraform.sh --project your-gcp-project-id --github-username octocat --github-repository your-gcp-project-terraform --dry-run\n\n# Actually create resources\n./setup-terraform.sh --project your-gcp-project-id --github-username octocat --github-repository your-gcp-project-terraform\n```\n\n`setup-terraform.sh` will perform following\n\n* Enable APIs\n* Create Service Account for Terraform\n* Grant minimum IAM roles to Service Account\n* Create GCS bucket for backend\n* Create Workload Identity Pool and Provider for GitHub Actions\n\n#### Parameters\n* `--project` **(Required)**\n  * Google Project ID\n* `--backend` \n  * Bucket name used as the backend of Terraform\n  * c.f. https://www.terraform.io/language/settings/backends/gcs\n  * default: `${PROJECT_ID}-terraform`\n* `--location`\n  * Location of backend bucket (e.g. `us`, `us-central1`)\n  * c.f. https://cloud.google.com/storage/docs/locations\n  * default: `us`\n* `--github-username` **(Required)**\n  * GitHub user name (e.g. `octocat`)\n* `--github-repository` **(Required)**\n  * GitHub repository name (e.g. `your-gcp-project-terraform`)\n* `--dry-run`\n  * Run as dry run mode\n* `-help`, `-h`\n  * Show usage\n\n### 5. Register secrets to GitHub repository\n* `SLACK_WEBHOOK` (optional)\n  * Create from https://slack.com/apps/A0F7XDUAZ\n\n### 6. Edit files\n#### [.terraform-version](.terraform-version)\n* Upgrade to the latest version if necessary\n\n#### [terraform.tfvars](terraform.tfvars)\nEdit followings\n\n* `gcp_project_id`\n  * GCP project ID\n* `provider_region`\n  * Provider region\n  * see. https://cloud.google.com/compute/docs/regions-zones\n\n#### [backend.tf](backend.tf)\nEdit followings\n\n* `terraform.backend.bucket`\n  * Same to `--backend`\n\n#### [versions.tf](versions.tf)\nUpgrade to the latest version if necessary\n\n* `terraform.required_providers.google.version`\n* `terraform.required_providers.google-beta.version`\n* `terraform.required_version`\n\n### 8. Run Terraform from local\n```bash\ntfenv install\n\nterraform init\n\n# Run followings if you upgraded providers\nterraform init -upgrade\ngit add .terraform.lock.hcl\ngit commit -m \"terraform init -upgrade\"\n\nterraform plan\n```\n\n### 9. Edit file for GitHub Actions\n#### [.github/workflows/terraform.yml](.github/workflows/terraform.yml)\nEdit followings\n\n* `WORKLOAD_IDENTITY_PROVIDER`\n  * This is created by [scripts/setup-terraform.sh](scripts/setup-terraform.sh)\n  * See. https://console.cloud.google.com/iam-admin/workload-identity-pools\n* `SERVICE_ACCOUNT_EMAIL`\n  * This is created by [scripts/setup-terraform.sh](scripts/setup-terraform.sh)\n  * See. https://console.cloud.google.com/iam-admin/serviceaccounts\n\n### 10. Check if GitHub Actions build is executed\n`git push` and check your repository\n\n## Maintenance for Terraform repository\n### Upgrade Terraform core\n1. Check latest version\n    * https://github.com/hashicorp/terraform/blob/main/CHANGELOG.md\n2. Edit [.terraform-version](.terraform-version)\n3. Run `tfenv install`\n\n### Upgrade Terraform providers (automatically)\n1. Edit [.github/dependabot.yml](.github/dependabot.yml)\n2. Wait for Dependabot to create a PullRequests\n\n### Upgrade Terraform providers (manually)\n1. Check latest versions\n    * https://github.com/hashicorp/terraform-provider-google/blob/main/CHANGELOG.md\n    * https://github.com/hashicorp/terraform-provider-google-beta/blob/main/CHANGELOG.md\n2. Edit `terraform.required_providers.google.version` and `terraform.required_providers.google-beta.version` in [versions.tf](versions.tf)\n3. Run `terraform init -upgrade`\n\n## Other solution\n* https://github.com/sue445/terraform-aws-template\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsue445%2Fterraform-gcp-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsue445%2Fterraform-gcp-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsue445%2Fterraform-gcp-template/lists"}