実現したいこと
terraformでAWS Elasticacheを作成したい
前提
terraformでAWS Elasticacheを作成中以下のエラーメッセージが発生しました。
作成されるelasticacheのvpcがdefault vpcになってしまいます。
発生している問題・エラーメッセージ
エラーメッセージ Error: creating ElastiCache Replication Group (redis-cluster): InvalidParameterCombination: Subnet group [redis] belongs to a different VPC [vpc-xxxxx(作成したsubnetのvpc id)] than [vpc-yyyyy(defaultのvpc id)]
該当のソースコード
terraform
1terraform { 2 required_providers { 3 aws = { 4 source = "hashicorp/aws" 5 version = ">= 4.1.0" 6 } 7 } 8} 9resource "aws_vpc" "this" { 10 cidr_block = "10.0.0.0/16" 11 enable_dns_hostnames = true 12 enable_dns_support = true 13 14 tags = { 15 Name = local.app_name 16 } 17} 18 19resource "aws_subnet" "redis_private_1a" { 20 vpc_id = aws_vpc.this.id 21 cidr_block = "10.0.50.0/24" 22 availability_zone = "ap-northeast-1a" 23 tags = { 24 Name = "redis-private-1a" 25 } 26} 27 28resource "aws_subnet" "redis_private_1c" { 29 vpc_id = aws_vpc.this.id 30 cidr_block = "10.0.60.0/24" 31 availability_zone = "ap-northeast-1c" 32 tags = { 33 Name = "redis-private-1c" 34 } 35} 36 37resource "aws_subnet" "redis_private_1d" { 38 vpc_id = aws_vpc.this.id 39 cidr_block = "10.0.70.0/24" 40 availability_zone = "ap-northeast-1d" 41 tags = { 42 Name = "redis-private-1d" 43 } 44} 45 46resource "aws_security_group" "redis" { 47 name = "${local.app_name}-redis" 48 49 ingress { 50 from_port = 6379 51 to_port = 6379 52 protocol = "tcp" 53 cidr_blocks = ["0.0.0.0/0"] 54 } 55 56 egress { 57 from_port = 0 58 to_port = 0 59 protocol = "-1" 60 cidr_blocks = ["0.0.0.0/0"] 61 } 62} 63 64resource "aws_elasticache_subnet_group" "redis" { 65 name = "redis" 66 description = "Subnet group for Redis cluster" 67 subnet_ids = [ 68 aws_subnet.redis_private_1a.id, 69 aws_subnet.redis_private_1c.id, 70 aws_subnet.redis_private_1d.id, 71 ] 72 73} 74 75resource "aws_cloudwatch_log_group" "redis" { 76 name = "${local.app_name}-redis" 77 retention_in_days = 1 78} 79 80resource "aws_elasticache_parameter_group" "redis" { 81 name = "redis-parameter-group" 82 family = "redis6.x" 83 84 parameter { 85 name = "cluster-enabled" 86 value = "no" 87 } 88} 89 90resource "aws_elasticache_replication_group" "redis" { 91 replication_group_id = "redis-cluster" 92 description = "Redis cluster for Websocket pub/sub" 93 engine = "redis" 94 engine_version = "6.x" 95 node_type = "cache.t3.small" 96 parameter_group_name = aws_elasticache_parameter_group.redis.name 97 subnet_group_name = aws_elasticache_subnet_group.redis.name 98 num_cache_clusters = 3 99 port = 6379 100 automatic_failover_enabled = true 101 security_group_ids = [aws_security_group.redis.id] 102 apply_immediately = false 103} 104 105
試したこと
iam userには全権限付与しています。
補足情報(FW/ツールのバージョンなど)
Terraform v1.3.3
on darwin_arm64
- provider registry.terraform.io/hashicorp/aws v4.59.0
Your version of Terraform is out of date! The latest version
is 1.4.4. You can update by downloading from https://www.terraform.io/downloads.html

回答1件
あなたの回答
tips
プレビュー