Hi,
I am trying to launch two EC2 instances across two subnets which are in individual AZ’s. For various reasons, among them Oracle licenses and Ansible provisioning by EC2 name, I can not use an autoscale group (at least I’m pretty sure I cant).
I have got this far
resource "aws_instance" "instance" {
count = length(split(",", var.vpc_public_subnets))
ami = data.aws_ami.rhel7.id
instance_type = "t2.micro"
subnet_id = element(split(",", local.public_subnets), count.index)
vpc_security_group_ids = ["${module.security_group.security_group_id}"]
tags = merge(var.tags, { Name = "${var.shortcode}-${var.env_namespace}-web${count.index + 1}" }, )
}
This plans correctly but I know it will fail on creation as the subnet_id’s contain extra characters
+ subnet_id = "[\"subnet-06c77c67a83fe1156\""
+ subnet_id = "\"subnet-004a5ade7bfe062ac\"]"
my vpc public outputs is in the format
private_subnets = [
"subnet-0144c36cfdacde2b5",
"subnet-032c92874a0bd532e",
]
I have tried changing the subnet_id line to
subnet_id = trim("${element(split(",", var.vpc_public_subnets, ), count.index)}", "\"")
and get
+ subnet_id = "[\"subnet-06c77c67a83fe1156"
+ subnet_id = "subnet-004a5ade7bfe062ac\"]"
I feel I am close but just can not get it right, could anyone help please?