Ubuntu20.04でterraformを動かしてみる

hashicorpにインストール手順が記載
https://www.terraform.io/downloads

$ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add –
$ sudo apt-add-repository “deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main”
$ sudo apt-get update && sudo apt-get install terraform
$ terraform –version
Terraform v1.1.8
on linux_amd64

mysql.tf

terraform {
  required_providers {
    mysql = {
      source = "terraform-providers/mysql"
    }
  }
}

provider "mysql" {
	endpoint = "localhost:3306"
	username = "root"
	password = "password"
}

resource "mysql_database" "app" {
	name = "my_database"
}

$ terraform init
$ terraform plan
$ terraform apply

mysql> show databases;

### リソースを変更

resource "mysql_database" "app" {
	name = "my_database"
	default_character_set = "utf8mb4"
  	default_collation = "utf8mb4_ja_0900_as_cs_ks"
}

$ terraform plan
$ terraform apply

### 破棄
$ terraform destroy

なるほどー