Halaman ini menjelaskan langkah-langkah untuk menginstal dan mengonfigurasi Terraform untuk Google Cloud di Cloud Shell dan di shell lokal. Cloud Shell adalah lingkungan shell interaktif untuk Google Cloud yang memungkinkan Anda mempelajari dan bereksperimen dengan Google Cloud serta mengelola project dan resource dari browser web.
Cloud Shell
Untuk menggunakan terminal online dengan gcloud CLI dan Terraform yang sudah disiapkan, aktifkan Cloud Shell:
Di bagian bawah halaman ini, sesi Cloud Shell akan dimulai dan menampilkan perintah command line. Perlu waktu beberapa detik hingga sesi dimulai.
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
Untuk menyediakan resource Google Cloud menggunakan Terraform, Anda harus mengaktifkan API yang sesuai:
gcloud services enable "API"
Ganti API dengan API yang ingin Anda aktifkan.
Untuk menyediakan resource Google Cloud menggunakan Terraform, Anda memerlukan peran Identity and Access Management yang khusus untuk resource ini.
- Dari halaman referensi peran IAM, tentukan peran yang diperlukan.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
Jalankan perintah berikut untuk memverifikasi bahwa Terraform tersedia:
terraform
Outputnya akan mirip dengan berikut ini:
Usage: terraform [global options] <subcommand> [args] The available commands for execution are listed below. The primary workflow commands are given first, followed by less common or more advanced commands. Main commands: init Prepare your working directory for other commands validate Check whether the configuration is valid plan Show changes required by the current configuration apply Create or update infrastructure destroy Destroy previously-created infrastructure
Shell lokal
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
Aktifkan API yang diperlukan:
gcloud services enable "API"
Dengan API adalah API yang ingin Anda aktifkan.
Untuk menyediakan resource Google Cloud menggunakan Terraform, Anda memerlukan peran Identity and Access Management yang khusus untuk resource ini.
- Dari halaman referensi peran IAM, tentukan peran yang diperlukan.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
- Replace
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
Instal Terraform.
Jalankan perintah berikut untuk memverifikasi bahwa Terraform tersedia:
terraform
Outputnya akan mirip dengan berikut ini:
Usage: terraform [global options] <subcommand> [args] The available commands for execution are listed below. The primary workflow commands are given first, followed by less common or more advanced commands. Main commands: init Prepare your working directory for other commands validate Check whether the configuration is valid plan Show changes required by the current configuration apply Create or update infrastructure destroy Destroy previously-created infrastructure
Langkah selanjutnya
- Ikuti panduan memulai Terraform untuk Google Cloud
- Pelajari perintah Terraform dasar.