Introduction
Create an instance of Google Cloud Platform (GCP) Google Cloud Bigtable using Terraform. After creation, the procedure to change or delete the instance is also described.
If you refer to the manual of GCP together, I think that work will proceed smoothly.
(Reference information)
google_bigtable_instance – Terraform –
Google Cloud Bigtable
1. Create an instance
1.1. Create a tfvars file.
# cat config.tfvars credentials = "/var/credentials/account.json" project = "xxxxx-xxxxx-xxxxx" region = "asia-northeast1"
1.2. Create a tf file.
# cat gcp.tf variable "credentials" {} variable "project" {} variable "region" {} provider "google" { credentials = "${file("${var.credentials}")}" project = "${var.project}" region = "${var.region}" } resource "google_bigtable_instance" "instance" { name = "bigtable01" cluster_id = "bigtable01-cluster" zone = "asia-northeast1-a" num_nodes = 3 storage_type = "HDD" }
1.3. Initialize Terraform.
# terraform init Initializing provider plugins...
1.4. Plan for Terraform.
# terraform plan -out=tfplan -var-file=config.tfvars Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. ------------------------------------------------------------------------ An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: + google_bigtable_instance.instance id: cluster_id: "bigtable01-cluster" display_name: instance_type: "PRODUCTION" name: "bigtable01" num_nodes: "3" project: storage_type: "HDD" zone: "asia-northeast1-a" Plan: 1 to add, 0 to change, 0 to destroy. ------------------------------------------------------------------------ This plan was saved to: tfplan To perform exactly these actions, run the following command to apply: terraform apply "tfplan"
1.5. Create an instance.
# terraform apply "tfplan" google_bigtable_instance.instance: Creating... cluster_id: "" => "bigtable01-cluster" display_name: "" => "" instance_type: "" => "PRODUCTION" name: "" => "bigtable01" num_nodes: "" => "3" project: "" => "" storage_type: "" => "HDD" zone: "" => "asia-northeast1-a" google_bigtable_instance.instance: Creation complete after 5s (ID: bigtable01) Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
1.6. Check the state of the instance.
# terraform show google_bigtable_instance.instance: id = bigtable01 cluster_id = bigtable01-cluster display_name = bigtable01 instance_type = PRODUCTION name = bigtable01 num_nodes = 3 project = xxxxx-xxxxx-xxxxx storage_type = HDD zone = asia-northeast1-a
2. Change instances
Set bigtable 01-display as display name.
2.1. Create a tf file.
# cat gcp.tf variable "credentials" {} variable "project" {} variable "region" {} provider "google" { credentials = "${file("${var.credentials}")}" project = "${var.project}" region = "${var.region}" } resource "google_bigtable_instance" "instance" { name = "bigtable01" cluster_id = "bigtable01-cluster" zone = "asia-northeast1-a" num_nodes = 3 storage_type = "HDD" display_name = "bigtable01-display" }
2.2. Plan for Terraform.
# terraform plan -out=tfplan -var-file=config.tfvars Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. ------------------------------------------------------------------------ An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: + google_bigtable_instance.instance id: cluster_id: "bigtable01-cluster" display_name: "bigtable01-display" instance_type: "PRODUCTION" name: "bigtable01" num_nodes: "3" project: storage_type: "HDD" zone: "asia-northeast1-a" Plan: 1 to add, 0 to change, 0 to destroy. ------------------------------------------------------------------------ This plan was saved to: tfplan To perform exactly these actions, run the following command to apply: terraform apply "tfplan"
2.3. Change the instance.
# terraform apply "tfplan" google_bigtable_instance.instance: Creating... cluster_id: "" => "bigtable01-cluster" display_name: "" => "bigtable01-display" instance_type: "" => "PRODUCTION" name: "" => "bigtable01" num_nodes: "" => "3" project: "" => "" storage_type: "" => "HDD" zone: "" => "asia-northeast1-a" google_bigtable_instance.instance: Creation complete after 4s (ID: bigtable01) Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
2.4. Check the state of the instance.
# terraform show google_bigtable_instance.instance: id = bigtable01 cluster_id = bigtable01-cluster display_name = bigtable01-display instance_type = PRODUCTION name = bigtable01 num_nodes = 3 project = xxxxx-xxxxx-xxxxx storage_type = HDD zone = asia-northeast1-a
3. Delete an instance
3.1. Delete the instance.
# terraform destroy -force -var-file=config.tfvars google_bigtable_instance.instance: Refreshing state... (ID: bigtable01) google_bigtable_instance.instance: Destroying... (ID: bigtable01) google_bigtable_instance.instance: Destruction complete after 1s Destroy complete! Resources: 1 destroyed.
3.2. Confirm that the instance has been deleted.
# terraform show
Summary
In the future, articles are added to Bigtable which will add tables and reference data.
We hope to contribute to the development of Google Cloud Platform.
コメントを残す