{"id":19289643,"url":"https://github.com/yingding/iac-gcp-example","last_synced_at":"2026-03-01T15:34:56.655Z","repository":{"id":232021865,"uuid":"783227889","full_name":"yingding/IaC-gcp-example","owner":"yingding","description":"this is an IaC example of deploying resources on GCP with terraform ","archived":false,"fork":false,"pushed_at":"2024-04-25T10:48:03.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-23T23:43:15.196Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yingding.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}},"created_at":"2024-04-07T09:46:49.000Z","updated_at":"2024-04-25T10:48:07.000Z","dependencies_parsed_at":"2024-04-25T11:46:39.259Z","dependency_job_id":null,"html_url":"https://github.com/yingding/IaC-gcp-example","commit_stats":null,"previous_names":["yingding/iac-gcp-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yingding/IaC-gcp-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingding%2FIaC-gcp-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingding%2FIaC-gcp-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingding%2FIaC-gcp-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingding%2FIaC-gcp-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yingding","download_url":"https://codeload.github.com/yingding/IaC-gcp-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingding%2FIaC-gcp-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29973329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T15:29:09.406Z","status":"ssl_error","status_checked_at":"2026-03-01T15:28:28.558Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-09T22:16:34.084Z","updated_at":"2026-03-01T15:34:56.615Z","avatar_url":"https://github.com/yingding.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IaC-gcp-example\nthis is an IaC example of deploying resources on GCP with terraform \n\n## Install google cloud sdk (python cli) on MacOSX\n```shell\nbrew install --cask google-cloud-sdk\n```\n\nReference:\n* https://developer.hashicorp.com/terraform/tutorials/kubernetes/gke\n\n## Authenticating GCP project in Terraform\nInit the project for gcp cli to use\n```shell\ngcloud init\n```\n\nCreate an Application Default Credential (ADC) for terraform to sue\n```shell\ngcloud auth application-default login\n```\n\n(Optional) remove the ADC:\n```shell\ngcloud auth application-default revoke\n```\n\nReference:\n* https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference\n* GCP ADC https://cloud.google.com/sdk/gcloud/reference/auth/application-default\n\n## Config CLI\nList the active gcp account name:\n```shell\ngcloud auth list\n```\n\nList the active gcp projects with associated gcp account:\n```shell\ngcloud projects list --filter='lifecycleState:ACTIVE'\n```\n\nList the project ID:\n```shell\ngcloud config list project\n```\n\nList the current cli project's active config\n```shell\ngcloud config configurations list\n```\n\n## Create service account\n```shell\nPROJECT_ID=$(gcloud config list --format 'value(core.project)')\n```\n\n```shell\nSERVICE_ACCOUNT_NAME=\u003csa-name\u003e\necho ${SERVICE_ACCOUNT_NAME}\ngcloud iam service-accounts create ${SERVICE_ACCOUNT_NAME} \\\n  --description=\"service account to access gcp project from remote terraform\" \\\n  --display-name=${SERVICE_ACCOUNT_NAME}\n```\n\n```shell\nROLE=roles/aiplatform.admin\ngcloud projects add-iam-policy-binding ${PROJECT_ID} \\\n    --member=\"serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com\" \\\n    --role=${ROLE}\n```\n* https://cloud.google.com/vertex-ai/docs/general/access-control\n* https://cloud.google.com/iam/docs/service-accounts-create#gcloud\n\n```shell\nROLE=roles/editor\ngcloud projects add-iam-policy-binding ${PROJECT_ID} \\\n    --member=\"serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com\" \\\n    --role=${ROLE}\n```\n\n```shell\nROLE=roles/storage.admin\ngcloud projects add-iam-policy-binding ${PROJECT_ID} \\\n    --member=\"serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com\" \\\n    --role=${ROLE}\n```\n\nCreate a service account key file and save it to your remote workstation\n```shell\nmakedir -p ~/.gcp/\nKEY_FILE=~/.gcp/sa-private-key.json\ngcloud iam service-accounts keys create ${KEY_FILE} \\\n--iam-account=${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com\n```\nNotice:\n* You are using user authentication at this point\n* after the service-acccounts key generation, you can remove the user authentication.\n\nAdding the env variable in your shell\n```shell\n# google credentials\n# location of the service account key file\nexport GOOGLE_CREDENTIALS=\"~/.gcp/sa-private-key.json\"\n```\n\n* https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#authentication-configuration\n\n## init terraform\n```shell\n# init terraform state\nterraform init\n# plan the change shall be made to your cloud resources\nterraform plan\n# executed planed changes defined by HCL \nterraform apply\n```\n\n(Optional) upgrade the provider version\n```shell\nterraform init --upgrade\n```\n\n## Apply terraform\nterraform will take the variables from either `terraform.tfvars` or `.auto.tfvars`\n\nOtherwise, we need to define the .tfvars file during the terraform apply.\n```shell\nterraform apply -var-file=\"const.tfvars\"\n```\n\n## Visualize your terraform plan\n```shell\nterraform graph -type=plan | dot -Tpng -o graph.png\n```\n\n## Learning Source\n* Get started with Azure: https://developer.hashicorp.com/terraform/tutorials/azure-get-started\n* Get started with GCP: https://developer.hashicorp.com/terraform/tutorials/gcp-get-started\n* Visualize your terraform plan: https://medium.com/vmacwrites/tools-to-visualize-your-terraform-plan-d421c6255f9f\n\n## Resources\n* https://developer.hashicorp.com/terraform/tutorials/gcp-get-started/google-cloud-platform-build\n* Authentication GCP - https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference\n* gcp template module - https://github.com/terraform-google-modules/terraform-google-project-factory\n* https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/version_5_upgrade\n* https://stackoverflow.com/questions/57453468/google-cloud-credentials-with-terraform\n\n## GCP pricing\n* Region picker - https://googlecloudplatform.github.io/region-picker/\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyingding%2Fiac-gcp-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyingding%2Fiac-gcp-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyingding%2Fiac-gcp-example/lists"}