...
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.
...
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.
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[[["\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."]]