[A-00151]TerraformでMemorystore for Redisを作成する

Google Cloud上に、Terraformを使ってRedisを作成したいと思います。

・Architecture

・APIの有効化

下記のURLより、Redisを有効化します。

https://console.developers.google.com/apis/api/redis.googleapis.com/overview

・Terraformの作成/実行

terraform {
  required_providers {
    google = {
        source = "hashicorp/google"
        version = "4.80.0"
    }
  }
}

provider "google" {
    project = var.project_id
    region = var.region
}
variable "project_id" {
    default = <input_your_project_id>
}

variable "region" {
    default = "asia-northeast1"
}

variable "redis_ver" {
    default = "REDIS_6_X"
}
resource "google_redis_instance" "default" {
    name = "redis-instance"
    tier = "BASIC"
    memory_size_gb = 1
    region = var.region
    redis_version = var.redis_ver
}
output "host" {
    value = "${google_redis_instance.default.host}"
}

上記を作成して下記のコマンドを実行します。

terraform init
terraform plan
terraform apply

上記が完了すると下記のようにRedisインスタンスが作成されます。

Terraformにて作成したoutputs.tfでapplyコマンド実行後下記のようにhostのurlが出力されます。

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

host = "X.X.X.X"

上記のURLにtelnetで接続してredisにコマンドを実行できます。詳しくは公式ドキュメントをご確認ください。

確認が完了したら下記のコマンドで後片付けします。

terraform destroy

・Appendix

公式ドキュメント

https://cloud.google.com/memorystore/docs/redis/create-instance-terraform?hl=ja

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

*