mkdir cloud-foundation-example && cd cloud-foundation-example
1단계에서 다운로드한 Terraform 구성을 업로드합니다.
Cloud Shell의 more_vert더보기 메뉴에서 업로드를 선택한 후 파일 선택을 클릭하여 Terraform 구성을 선택합니다.
대상 디렉터리를 이전 단계에서 만든 폴더로 설정한 후 업로드를 클릭합니다.
현재 위치가 cloud-foundation-example 디렉터리인지 확인합니다.
Terraform 원격 상태를 저장할 Cloud Storage 버킷을 만듭니다.
원격 상태를 사용하면 Terraform에서 Cloud Storage와 같은 객체 저장소를 사용하여 Terraform 관리형 인프라에 대한 상태 정보를 저장할 수 있습니다. 이 구성은 팀 위임 및 상태 잠금과 같은 이점을 제공합니다.
terraform init를 실행합니다. 이 프로세스는 Terraform 구성 파일과 백엔드가 포함된 작업 디렉터리를 초기화합니다.
terraform plan을 실행하여 Terraform에서 만드는 리소스를 확인합니다. 출력 예시:
...
Plan: 6 to add, 0 to change, 0 to destroy.
Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.
Google Cloud에 리소스를 배포하는 terraform apply를 실행하여 구성을 적용합니다. 메시지가 표시되면 yes를 입력합니다.
terraform init를 실행합니다. 이 프로세스는 Terraform 구성 파일과 백엔드가 포함된 작업 디렉터리를 초기화합니다.
terraform plan을 실행하여 Terraform에서 생성, 변경 또는 폐기하는 리소스를 확인합니다.
출력 예시:
...
Plan: 2 to add, 3 to change, 4 to destroy.
Note: You didn't use the -out option to save this plan, so Terraform can't
guarantee to take exactly these actions if you run "terraform apply" now.
Google Cloud에 리소스를 배포하는 terraform apply를 실행하여 구성을 적용합니다. 메시지가 표시되면 yes를 입력합니다.
다운로드한 Terraform 구성이 이미 존재하는 리소스를 만들려고 시도하면 Terraform이 409 오류 코드로 종료됩니다.
이러한 오류를 해결하려면Google Cloud 콘솔 또는 gcloud CLI를 사용하여 리소스를 삭제한 다음 Terraform 구성을 다시 적용할 수 있습니다.
또는 이러한 리소스가 중요하여 삭제할 수 없는 경우 Terraform 상태로 리소스를 가져올 수 있습니다.
Terraform, Cloud Build, GitOps를 사용하여 인프라를 코드로 관리
자세한 안내는 이 튜토리얼을 참조하세요. 이 옵션은 예측 가능하고 반복적으로 인프라를 변경할 전략을 찾고 있는 플랫폼 관리자 및 운영자를 위한 옵션입니다. 이 가이드에서는 사용자가 Google Cloud, Linux, GitHub에 익숙하다고 가정합니다. 위 옵션에서 설명하는 단계는 간략히 다음과 같습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eThe Google Cloud foundation setup guide allows administrators to configure and deploy an enterprise-ready Google Cloud foundation directly from the console or as a downloadable Terraform file.\u003c/p\u003e\n"],["\u003cp\u003eDeploying the downloaded Terraform configuration requires setting up a Cloud Storage bucket for Terraform Remote State and initializing Terraform in Cloud Shell.\u003c/p\u003e\n"],["\u003cp\u003eIf the foundation configuration was previously deployed using the console's Deploy button, the Terraform state file generated during that deployment must be downloaded and included when using your own pipeline.\u003c/p\u003e\n"],["\u003cp\u003eRedeploying Terraform involves reusing the previously created Cloud Storage backend and state file to detect, prune, and update existing resources.\u003c/p\u003e\n"],["\u003cp\u003eThe configuration may be managed with Terraform, Cloud Build, and GitOps by setting up a GitHub repository, storing Terraform state in a Cloud Storage bucket, and connecting Cloud Build to your repository.\u003c/p\u003e\n"]]],[],null,["# Deploy your foundation using Terraform downloaded from the console\n\n\u003cbr /\u003e\n\n[Google Cloud Setup](https://console.cloud.google.com/cloud-setup) helps administrators configure a\nGoogle Cloud foundation using a [guided flow](/docs/enterprise/cloud-setup), and\ndeploy directly from the Google Cloud console or download as Terraform.\n| **Warning:** If you plan to deploy a downloaded Terraform configuration using [your\n| own pipeline](#manage), don't click the Deploy button in the console. If you already clicked the Deploy button, see [Deploy downloaded Terraform after deploying from\n| the console](#deploy-terraform-after-console).\n\nThis document helps you deploy your Google Cloud Setup Terraform file.\n\nBefore you begin\n----------------\n\nReview [Best practices for using Terraform](/docs/terraform/best-practices-for-terraform), which includes guidelines for effective development with Terraform across team members and workstreams.\n\nIf you already deployed the foundation configuration by clicking the Deploy button in the console, and now want to deploy a downloaded Terraform configuration using [your own pipeline](#manage), you must do the following:\n\n- Download the Terraform state file that was generated by the console.\n- Include the downloaded state file in your own pipeline process.\n\nFor more information, see [Deploy downloaded Terraform after deploying from the console](#deploy-terraform-after-console).\n\nDeploy Terraform with Cloud Shell\n---------------------------------\n\n| **Note** : If you have previously deployed the downloaded Terraform configuration, proceed to the [redeploy section](#redeploy).\n\nCloud Shell comes with Terraform pre-installed and pre-authenticated, so you can get\nstarted quickly.\n\n1. From the in-console setup guide, click **Download as Terraform** and save the configuration.\n2. Open [Cloud Shell](https://shell.cloud.google.com).\n3. In Cloud Shell, create a directory and navigate to it:\n\n ```\n mkdir cloud-foundation-example && cd cloud-foundation-example\n ```\n4. Upload the Terraform configuration that you downloaded in step 1.\n\n From the Cloud Shell more_vert**More** menu,\n select **Upload** , and then click **Choose Files** to select the Terraform configuration.\n Set the destination directory to the folder that you created in the previous step, and then\n click **Upload**.\n5. Ensure that you're in the `cloud-foundation-example` directory.\n\n6. Create a Cloud Storage bucket to store [Terraform Remote State](/docs/terraform/resource-management/store-state).\n A remote state lets Terraform use object stores like Cloud Storage to store state\n information about your Terraform-managed infrastructure. This configuration provides\n benefits such as team delegation and state locking.\n\n To create the Cloud Storage bucket, run the following command: \n\n ```\n gcloud storage buckets create gs://tf-state-PROJECT_ID\n ```\n7. Define a Terraform backend configuration within a `backend.tf` file and replace\n \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e to match the project ID that you used in the previous step. For more details,\n review [storing Terraform state in Cloud Storage](/docs/terraform/resource-management/store-state#create_the_bucket).\n\n ```\n # backend.tf\n terraform {\n backend \"gcs\" {\n bucket = \"tf-state-PROJECT_ID\"\n prefix = \"terraform/state\"\n }\n }\n ```\n8. Run `terraform init`. This process initializes your working directory that contains\n the Terraform configuration files and the backend.\n\n9. Run `terraform plan` to see the resources Terraform creates. Example output:\n\n ```\n ...\n Plan: 6 to add, 0 to change, 0 to destroy.\n Note: You didn't use the -out option to save this plan, so Terraform can't\n guarantee to take exactly these actions if you run \"terraform apply\" now.\n ```\n\n \u003cbr /\u003e\n\n10. Apply the configuration by running `terraform apply`, which deploys your resources to\n Google Cloud. When prompted, enter `yes`.\n\n11. [Explore the Google Cloud console](https://console.cloud.google.com/cloud-resource-manager) to verify that\n your resources are now deployed on your account or project.\n\nRedeploy Terraform with Cloud Shell\n-----------------------------------\n\nTerraform stores information about deployed resources within the\nTerraform state file. If you have followed the previous steps to deploy\nyour configuration, we strongly recommend that you reuse the same backend\nto automatically detect, prune, and update resources defined by the new exported\nconfiguration.\n\n1. From the in-console setup guide, click **Download as Terraform** and save the configuration.\n2. Open [Cloud Shell](https://shell.cloud.google.com).\n3. In Cloud Shell, create a new directory and navigate to it: \n\n ```\n mkdir cloud-foundation-example-redeploy && cd cloud-foundation-example-redeploy\n ```\n4. Upload the Terraform configuration that you downloaded in step 1.\n\n From the Cloud Shell more_vert**More** menu, select\n **Upload** , and then click **Choose Files** to select the Terraform configuration.\n Set the destination directory to the folder that you created in the previous step, and then click **Upload**.\n5. Ensure that you're in the `cloud-foundation-example-redeploy` directory.\n\n6. Ensure that the previously created Cloud Storage backend bucket and state file exists.\n\n ```\n gcloud storage ls gs://tf-state-PROJECT_ID/terraform/state/\n ```\n Example output: \n\n ```\n gs://tf-state-PROJECT_ID/terraform/state/default.tfstate\n ```\n\n \u003cbr /\u003e\n\n7. Define a Terraform backend configuration within a `backend.tf` file by reusing\n the same bucket and prefix.\n\n ```\n # backend.tf\n terraform {\n backend \"gcs\" {\n bucket = \"tf-state-PROJECT_ID\"\n prefix = \"terraform/state\"\n }\n }\n ```\n8. Run `terraform init`. This process initializes your working directory that contains\n the Terraform configuration files and the backend.\n\n9. Run `terraform plan` to see the resources Terraform creates, changes, or destroys.\n Example output:\n\n ```\n ...\n Plan: 2 to add, 3 to change, 4 to destroy.\n Note: You didn't use the -out option to save this plan, so Terraform can't\n guarantee to take exactly these actions if you run \"terraform apply\" now.\n ```\n\n \u003cbr /\u003e\n\n10. Apply the configuration by running `terraform apply`, which deploys your resources to\n Google Cloud. When prompted, enter `yes`.\n\n11. [Explore the Google Cloud console](https://console.cloud.google.com/cloud-resource-manager) to verify\n that your resources are now deployed on your account or project.\n\nDeploy downloaded Terraform after deploying from the console\n------------------------------------------------------------\n\nIf you already deployed the foundation configuration using the Deploy button in the console, a Terraform state file was generated. If you now want to download the Terraform configuration to deploy using [your own pipeline](#manage), you must include the Terraform state file that was generated during your console deployment.\n\nTo download and use the state file:\n\n1. To download the Terraform state file, complete the following procedures in [Manage the Terraform state file](/infrastructure-manager/docs/state-file):\n\n 1. [Lock the deployment](/infrastructure-manager/docs/state-file#lock_the_deployment).\n 2. [Download the state file](/infrastructure-manager/docs/state-file#download_the_state_file).\n 3. [Unlock the deployment](/infrastructure-manager/docs/state-file#unlock_the_deployment).\n2. To move the state file you downloaded to a Cloud Storage bucket, see [Store Terraform state in a Cloud Storage bucket](https://cloud.google.com/docs/terraform/resource-management/store-state).\n\n3. To redeploy the Terraform configuration, see [Redeploy Terraform with Cloud Shell](#redeploy).\n\nTroubleshooting Terraform deployments\n-------------------------------------\n\n### Deploy Terraform with existing resources\n\nIf the downloaded Terraform configuration attempts to create resources that\nalready exist, Terraform exits with a\n[`409` error code](/resource-manager/docs/core_errors#CONFLICT).\nTo resolve these errors, you can delete the resource by using the\nGoogle Cloud console\nor gcloud CLI, and then re-apply the Terraform configuration.\nAlternatively, if these resources are critical and cannot be deleted, you can\n[import resources](/docs/terraform/resource-management/import#manually_importing_resources)\ninto your Terraform state.\n\nManage infrastructure as code with Terraform, Cloud Build, and GitOps\n---------------------------------------------------------------------\n\nWe recommend following this [tutorial](/architecture/managing-infrastructure-as-code) for complete instructions. This option is for platform admins and operators who are looking for a strategy to predictably and repeatedly make changes to infrastructure. The guide assumes that you are familiar with Google Cloud, Linux, and GitHub. The high-level steps of this option are as follows:\n\n1. Set up your GitHub repository.\n2. Configure Terraform to store state in a Cloud Storage bucket.\n3. Grant permissions to your Cloud Build service account.\n4. Connect Cloud Build to your GitHub repository.\n5. Change your environment configuration in a feature branch.\n6. Promote changes to the development environment.\n7. Promote changes to the production environment."]]