実現したいこと
TerraformでエラーをなくしてRDS構築したい。
init→planまでは行きます。
発生している問題・分からないこと
Terraform applyの時にエラーがでる。
エラーメッセージ
error
1Error: creating RDS Cluster (ltar-rds-cluster): InvalidParameterCombination: Cannot find version 8.0.mysql_aurora.3.02.2 for aurora-mysql 2│ status code: 400, request id: 6ed083f4-76aa-45a9-aad6-b67934bae219 3│ 4│ with module.rds.aws_rds_cluster.learn, 5│ on rds/rds.tf line 7, in resource "aws_rds_cluster" "learn": 6│ 7: resource "aws_rds_cluster" "learn" { 7
該当のソースコード
terraform
1 2```main.tf 3terraform { 4 5 required_providers { 6 aws = { 7 source = "hashicorp/aws" 8 version = "~> 4.16" 9 } 10 } 11 12 required_version = ">= 1.2.0" 13} 14 15provider "aws" { 16 region = "ap-northeast-1" 17} 18 19# VPC 20module "vpc" { 21 source = "./vpc" 22 23 name_prefix = var.name_prefix 24 region = var.region 25 az_a = var.az_a 26 az_c = var.az_c 27 tag_name = var.tag_name 28 tag_group = var.tag_group 29} 30 31# SG 32module "sg" { 33 source = "./sg" 34 35 name_prefix = var.name_prefix 36 region = var.region 37 az_a = var.az_a 38 az_c = var.az_c 39 tag_name = var.tag_name 40 tag_group = var.tag_group 41 42 vpc_id = module.vpc.vpc_id 43} 44 45# RDS 46module "rds" { 47 source = "./rds" 48 49 name_prefix = var.name_prefix 50 region = var.region 51 az_a = var.az_a 52 az_c = var.az_c 53 tag_name = var.tag_name 54 tag_group = var.tag_group 55 56 vpc_id = module.vpc.vpc_id 57 public_a_id = module.vpc.public_a_id 58 public_c_id = module.vpc.public_c_id 59 sg_id = module.sg.sg_id 60}
variables.tf
1 2variable "region" { 3 default = "ap-northeast-1" 4} 5 6variable "az_a" { 7 default = "ap-northeast-1a" 8} 9 10variable "az_c" { 11 default = "ap-northeast-1c" 12} 13 14variable "name_prefix" { 15 default = "ltar" 16} 17 18variable "tag_name" { 19 default = "learn-terraform-aws-rds" 20} 21 22variable "tag_group" { 23 default = "learn-terraform-aws" 24}
vpc/vpc.tf
1 2resource "aws_vpc" "default" { 3 cidr_block = "10.0.0.0/16" 4 enable_dns_support = true 5 enable_dns_hostnames = true # DNSホスト名を有効化 6 tags = { 7 Name = "${var.tag_name}" 8 } 9} 10 11# Subnet 12resource "aws_subnet" "public_1a" { 13 vpc_id = aws_vpc.default.id 14 cidr_block = "10.0.0.0/20" 15 availability_zone = var.az_a 16 tags = { 17 Name = "${var.tag_name}" 18 } 19} 20 21resource "aws_subnet" "public_1c" { 22 vpc_id = aws_vpc.default.id 23 cidr_block = "10.0.16.0/20" 24 availability_zone = var.az_c 25 tags = { 26 Name = "${var.tag_name}" 27 } 28} 29 30# Internet Gateway 31resource "aws_internet_gateway" "default" { 32 vpc_id = aws_vpc.default.id 33 tags = { 34 Name = "${var.tag_name}" 35 } 36} 37 38# Route table 39resource "aws_route_table" "default" { 40 vpc_id = aws_vpc.default.id 41 tags = { 42 Name = "${var.tag_name}" 43 } 44} 45 46resource "aws_route" "default" { 47 route_table_id = aws_route_table.default.id 48 gateway_id = aws_internet_gateway.default.id 49 destination_cidr_block = "0.0.0.0/0" 50} 51 52# SubnetとRoute tableの関連付け 53resource "aws_route_table_association" "public_1a" { 54 subnet_id = aws_subnet.public_1a.id 55 route_table_id = aws_route_table.default.id 56} 57 58resource "aws_route_table_association" "public_1c" { 59 subnet_id = aws_subnet.public_1c.id 60 route_table_id = aws_route_table.default.id 61}
vpc/variables.tf
1variable "region" {default = "ap-northeast-1"} 2variable "az_a" {default = "ap-northeast-1a"} 3variable "az_c" {default = "ap-northeast-1c"} 4variable "name_prefix" {default = "ltar"} 5variable "tag_name" {default = "learn-terraform-aws-rds"} 6variable "tag_group" {default = "learn-terraform-aws"}
sg/sg.tf
1 2resource "aws_security_group" "default" { 3 vpc_id = "${var.vpc_id}" 4 tags = { 5 Name = "${var.tag_name}" 6 } 7} 8 9resource "aws_security_group_rule" "mysql" { 10 type = "ingress" 11 from_port = "3306" 12 to_port = "3306" 13 protocol = "tcp" 14 cidr_blocks = ["0.0.0.0/0"] 15 security_group_id = aws_security_group.default.id 16} 17 18resource "aws_security_group_rule" "out_all_allow" { 19 type = "egress" 20 from_port = 0 21 to_port = 0 22 protocol = "all" 23 cidr_blocks = ["0.0.0.0/0"] 24 security_group_id = aws_security_group.default.id 25}
sg/variables.tf
1 2variable "region" {default = "ap-northeast-1"} 3variable "az_a" {default = "ap-northeast-1a"} 4variable "az_c" {default = "ap-northeast-1c"} 5variable "name_prefix" {default = "ltar" } 6variable "tag_name" {default = "learn-terraform-aws-rds"} 7variable "tag_group" {default = "learn-terraform-aws"} 8 9variable "vpc_id" {default = "aws_vpc.default.id"} 10
rds/rds.tf
1locals { 2 aurora_database_name = "learn" 3 aurora_master_username = "learn_user" 4 aurora_master_password = "Passw0rd" 5} 6 7resource "aws_rds_cluster" "learn" { 8 cluster_identifier = "${var.name_prefix}-rds-cluster" 9 engine = "aurora-mysql" 10 engine_version = "8.0.mysql_aurora.3.02.2" 11 database_name = local.aurora_database_name 12 master_username = local.aurora_master_username 13 master_password = local.aurora_master_password 14 port = 3306 15 vpc_security_group_ids = ["${var.sg_id}"] 16 db_subnet_group_name = aws_db_subnet_group.learn.name 17 db_cluster_parameter_group_name = aws_rds_cluster_parameter_group.learn.name 18 19 skip_final_snapshot = true 20 apply_immediately = true 21} 22 23resource "aws_rds_cluster_parameter_group" "learn" { 24 name = "${var.name_prefix}-database-cluster-parameter-group" 25 family = "aurora-mysql8.0" 26 27 parameter { 28 name = "character_set_client" 29 value = "utf8mb4" 30 apply_method = "immediate" 31 } 32 33 parameter { 34 name = "character_set_connection" 35 value = "utf8mb4" 36 apply_method = "immediate" 37 } 38 39 parameter { 40 name = "character_set_database" 41 value = "utf8mb4" 42 apply_method = "immediate" 43 } 44 45 parameter { 46 name = "character_set_filesystem" 47 value = "utf8mb4" 48 apply_method = "immediate" 49 } 50 51 parameter { 52 name = "character_set_results" 53 value = "utf8mb4" 54 apply_method = "immediate" 55 } 56 57 parameter { 58 name = "character_set_server" 59 value = "utf8mb4" 60 apply_method = "immediate" 61 } 62 63 parameter { 64 name = "collation_connection" 65 value = "utf8mb4_general_ci" 66 apply_method = "immediate" 67 } 68 69 parameter { 70 name = "collation_server" 71 value = "utf8mb4_general_ci" 72 apply_method = "immediate" 73 } 74 75 parameter { 76 name = "time_zone" 77 value = "Asia/Tokyo" 78 apply_method = "immediate" 79 } 80} 81 82resource "aws_db_subnet_group" "learn" { 83 name = "${var.name_prefix}-db-subnet" 84 subnet_ids = ["${var.public_a_id}", "${var.public_c_id}"] 85} 86 87resource "aws_rds_cluster_instance" "learn" { 88 count = 1 89 90 cluster_identifier = aws_rds_cluster.learn.id 91 identifier = "${var.name_prefix}-rds-instance-${count.index}" 92 93 engine = aws_rds_cluster.learn.engine 94 engine_version = aws_rds_cluster.learn.engine_version 95 instance_class = "db.t3.medium" 96 db_subnet_group_name = aws_db_subnet_group.learn.name 97 db_parameter_group_name = aws_db_parameter_group.learn.name 98 99 publicly_accessible = true 100} 101 102resource "aws_rds_cluster_instance" "learn-replica" { 103 count = 2 104 105 cluster_identifier = aws_rds_cluster.learn.id 106 identifier = "${var.name_prefix}-rds-instance-${count.index}-replica" 107 108 engine = aws_rds_cluster.learn.engine 109 engine_version = aws_rds_cluster.learn.engine_version 110 instance_class = "db.t3.medium" 111 db_subnet_group_name = aws_db_subnet_group.learn.name 112 db_parameter_group_name = aws_db_parameter_group.learn.name 113 depends_on = [aws_rds_cluster_instance.learn] 114 115 publicly_accessible = true 116} 117 118resource "aws_db_parameter_group" "learn" { 119 name = "${var.name_prefix}-db-parameter-group" 120 family = "aurora-mysql8.0" 121}
rds/variables.tf
1 2variable "region" {default = "ap-northeast-1"} 3variable "az_a" {default = "ap-northeast-1a"} 4variable "az_c" {default = "ap-northeast-1c"} 5variable "name_prefix" {default = "ltar"} 6variable "tag_name" {default = "learn-terraform-aws-rds"} 7variable "tag_group" {default = "learn-terraform-aws"} 8 9variable "vpc_id" {default = "aws_vpc.default.id"} 10variable "public_a_id" {default = "aws_subnet.public_1a.id"} 11variable "public_c_id" {default = "aws_subnet.public_1c.id"} 12variable "sg_id" {default = "aws_security_group.default.id"}
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
バージョンなどを変えてみた
補足
特になし
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。