Deploy fondasi Anda menggunakan Terraform yang didownload dari konsol
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Google Cloud Penyiapan membantu administrator mengonfigurasi
fondasiGoogle Cloud menggunakan alur terpandu, dan
men-deploy langsung dari konsol Google Cloud atau mendownload sebagai Terraform.
Dokumen ini membantu Anda men-deploy Google Cloud file Terraform Penyiapan.
Sebelum memulai
Tinjau Praktik terbaik penggunaan Terraform, yang mencakup pedoman untuk pengembangan yang efektif dengan Terraform di seluruh anggota tim dan alur kerja.
Jika telah men-deploy konfigurasi dasar dengan mengklik tombol Deploy di konsol, dan sekarang ingin men-deploy konfigurasi Terraform yang didownload menggunakan pipeline Anda sendiri, Anda harus melakukan hal berikut:
Download file status Terraform yang dihasilkan oleh konsol.
Sertakan file status yang didownload dalam proses pipeline Anda sendiri.
Di Cloud Shell, buat direktori dan buka direktori tersebut:
mkdir cloud-foundation-example && cd cloud-foundation-example
Upload konfigurasi Terraform yang didownload pada langkah 1.
Dari menu Cloud Shell more_vertLainnya,
pilih Upload, lalu klik Pilih File untuk memilih konfigurasi Terraform.
Tetapkan direktori tujuan ke folder yang Anda buat di langkah sebelumnya, lalu
klik Upload.
Pastikan Anda berada di direktori cloud-foundation-example.
Buat bucket Cloud Storage untuk menyimpan Status Jarak Jauh Terraform.
Dengan status jarak jauh, Terraform dapat menggunakan penyimpanan objek seperti Cloud Storage untuk menyimpan informasi
status tentang infrastruktur yang dikelola oleh Terraform. Konfigurasi ini memberikan
manfaat seperti delegasi tim dan penguncian status.
Untuk membuat bucket Cloud Storage, jalankan perintah berikut:
Tentukan konfigurasi backend Terraform dalam file backend.tf dan ganti
PROJECT_ID agar cocok dengan ID project yang Anda gunakan di langkah sebelumnya. Untuk detail selengkapnya,
tinjau cara menyimpan status Terraform di Cloud Storage.
Jalankan terraform init. Proses ini menginisialisasi direktori kerja Anda yang berisi
file konfigurasi Terraform dan backend.
Jalankan terraform plan untuk melihat resource yang dibuat Terraform. Contoh output:
...
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.
Terapkan konfigurasi dengan menjalankan terraform apply, yang men-deploy resource Anda ke
Google Cloud. Jika diminta, masukkan yes.
Jelajahi Google Cloud konsol untuk memverifikasi bahwa
resource Anda kini telah di-deploy di akun atau project Anda.
Deploy ulang Terraform dengan Cloud Shell
Terraform menyimpan informasi tentang resource yang di-deploy dalam
file status Terraform. Jika Anda telah mengikuti langkah-langkah sebelumnya untuk men-deploy
konfigurasi, sebaiknya gunakan kembali backend yang sama
agar otomatis mendeteksi, memangkas, dan memperbarui resource yang ditentukan oleh konfigurasi baru
yang diekspor.
Dari panduan penyiapan dalam konsol, klik Download sebagai Terraform dan
simpan konfigurasi.
Di Cloud Shell, buat direktori baru lalu buka direktori tersebut:
mkdir cloud-foundation-example-redeploy && cd cloud-foundation-example-redeploy
Upload konfigurasi Terraform yang didownload pada langkah 1.
Dari menu Cloud Shell more_vertLainnya, pilih
Upload, lalu klik Pilih File untuk memilih konfigurasi Terraform.
Tetapkan direktori tujuan ke folder yang Anda buat di langkah sebelumnya, lalu klik Upload.
Pastikan Anda berada di direktori cloud-foundation-example-redeploy.
Pastikan bucket backend dan file status Cloud Storage yang dibuat sebelumnya ada.
gcloud storage ls gs://tf-state-PROJECT_ID/terraform/state/
Jalankan terraform init. Proses ini menginisialisasi direktori kerja Anda yang berisi
file konfigurasi Terraform dan backend.
Jalankan terraform plan untuk melihat resource yang dibuat, diubah, atau dihancurkan oleh Terraform.
Contoh output:
...
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.
Terapkan konfigurasi dengan menjalankan terraform apply, yang men-deploy resource Anda ke
Google Cloud. Jika diminta, masukkan yes.
Men-deploy Terraform yang didownload setelah men-deploy dari konsol
Jika Anda sudah men-deploy konfigurasi dasar menggunakan tombol Deploy di konsol, file status Terraform akan dibuat. Jika sekarang ingin mendownload konfigurasi Terraform untuk men-deploy menggunakan pipeline Anda sendiri, Anda harus menyertakan file status Terraform yang dihasilkan selama deployment konsol.
Jika konfigurasi Terraform yang didownload mencoba membuat resource yang
sudah ada, Terraform akan keluar dengan
kode error 409.
Untuk mengatasi error ini, Anda dapat menghapus resource menggunakan
konsolGoogle Cloud
atau gcloud CLI, lalu menerapkan kembali konfigurasi Terraform.
Atau, jika resource ini sangat penting dan tidak dapat dihapus, Anda dapat
mengimpor resource
ke status Terraform Anda.
Mengelola infrastruktur sebagai kode dengan Terraform, Cloud Build, dan GitOps
Sebaiknya ikuti tutorial ini untuk mendapatkan petunjuk lengkap. Opsi ini ditujukan untuk admin dan operator platform yang mencari strategi agar dapat diprediksi dan berulang kali melakukan perubahan pada infrastruktur. Panduan ini mengasumsikan bahwa Anda sudah memahami Google Cloud, Linux, dan GitHub. Langkah-langkah tingkat tinggi dari opsi ini adalah sebagai berikut
Siapkan repositori GitHub Anda.
Konfigurasi Terraform untuk menyimpan status di bucket Cloud Storage.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 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."]]