I am trying to deploy an AWS ECS Autoscaling Cluster, but terraform claims there is a cycle and it cannot deploy. As best I can tell, this is configured correctly:
resource "aws_ecs_cluster" "cluster" {
name = "${var.environment}_cluster"
capacity_providers = [aws_ecs_capacity_provider.capacity_provider.name]
}
resource "aws_ecs_capacity_provider" "capacity_provider" {
name = "${var.environment}_capacity_provider"
auto_scaling_group_provider {
auto_scaling_group_arn = aws_autoscaling_group.autoscaling_group.arn
managed_termination_protection = "ENABLED"
managed_scaling {
maximum_scaling_step_size = 1
minimum_scaling_step_size = 1
status = "ENABLED"
target_capacity = 100
}
}
}
resource "aws_launch_configuration" "launch_configuration" {
name_prefix = "${var.environment}_launch_configuration-"
image_id = data.aws_ami.ecs_os.id
instance_type = var.cluster_instance_type
iam_instance_profile = var.ecs_instance_profile
security_groups = var.security_groups["ecs_tasks"]
associate_public_ip_address = true
key_name = aws_key_pair.ssh_access.key_name
user_data = data.template_file.launch_user_data.rendered
lifecycle {
create_before_destroy = true
}
}
data "template_file" "launch_user_data" {
template = "${file("${path.module}/taskdefs/user_data")}"
vars = {
ecs_cluster = aws_ecs_cluster.cluster.name
efs_id = var.efs_id
aws_region = data.aws_region.current.name
}
}
resource "aws_autoscaling_group" "autoscaling_group" {
name = "${var.environment}_asg"
max_size = 4
min_size = 1
vpc_zone_identifier = [var.public_subnet_id]
launch_configuration = aws_launch_configuration.launch_configuration.name
health_check_type = "EC2"
protect_from_scale_in = true
}
But when I terraform plan, I get the error:
Error: Cycle: module.compute.aws_ecs_cluster.cluster, module.compute.data.template_file.launch_user_data, module.compute.aws_launch_configuration.launch_configuration, module.compute.aws_autoscaling_group.autoscaling_group, module.compute.aws_ecs_capacity_provider.capacity_provider
As far as I can tell, all of the “connections” between the various resources are how they have to be. Is this a bug in terraform that it can’t work out the order these need to come up in?