hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.87k stars 9.21k forks source link

aws_ecs_cluster: Networking configuration missing (VPC+Subnets) #24288

Open matei-dragu opened 2 years ago

matei-dragu commented 2 years ago

Community Note

Description

When creating a aws_ecs_cluster resource you cannot specify the VPC/Subnets to use.

This behavious is happening in version 4.10.0 of the AWS provider.

New or Affected Resource(s)

Potential Terraform Configuration

resource "aws_ecs_cluster" "one_of_the_clusters_in_my_aws_account" {
  name = "one_of_the_clusters_in_my_aws_account"

  # here we should have the option to explicitly specify:
  # 1. The VPC inside which the cluster will be created
  # 2. The subnet(s) inside that VPC that the cluster will use
}

References

Basically the config options in the Networking section are missing:

Screenshot 2022-04-17 at 12 50 49

trevorrea commented 2 years ago

Hi @ceresdarkmatter

I don't use ECS + EC2 but the Networking settings only apply for that and not Fargate. With Fargate this option is not available.

I guess with ECS + EC2 the wizard asks for those options so it can create an autoscaling group with the right settings whereas in Terraform these are all separate resources and you have to create all the supporting resources yourself.

Screenshot 2022-05-13 at 09 20 25

In Terraform this would be done like this:-

aws_ecs_cluster - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster aws_ecs_capacity_provider - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_capacity_provider aws_ecs_cluster_capacity_providers - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster_capacity_providers aws_autoscaling_group - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group - it is here where you would specify the network settings not on the ECS cluster resource.

There may be some more resources required, as I said above I don't use ECS + EC2 as I use Fargate (it's really cool :) ) but hope this helps.

epomatti commented 2 years ago

Perhaps @trevorrea explanation could be added to the documentation to avoid confusion?

trevorrea commented 2 years ago

Feel free to open an MR :) though it's all in the AWS docs.

To make it slightly clearer an autoscaling group with vpc_zone_identifier could be added to the example at https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_cluster#example-with-capacity-providers