# Core Infrastructure
This folder contains the Terraform code to deploy the core infratructure for an ECS Fargate workload. The AWS resources created by the script are:
* Networking
* VPC
* 3 public subnets, 1 per AZ. If a region has less than 3 AZs it will create same number of public subnets as AZs.
* 3 private subnets, 1 per AZ. If a region has less than 3 AZs it will create same number of private subnets as AZs.
* 1 NAT Gateway
* 1 Internet Gateway
* Associated Route Tables
* 1 ECS Cluster with AWS CloudWatch Container Insights enabled.
* Task execution IAM role
* CloudWatch log groups
* CloudMap service discovery namespace `default`
## Getting Started
Make sure you have all the [prerequisites](../../../README.md) for your laptop.
## Usage
* Clone the forked repository from your account (not the one from the aws-ia organization) and change the directory to the appropriate one as shown below:
```bash
cd ecs-blueprints/terraform/fargate-examples/core-infra/
```
* Run Terraform init to download the providers and install the modules
```shell
terraform init
```
* Review the terraform plan output, take a look at the changes that terraform will execute, and then apply them:
```shell
terraform plan
terraform apply --auto-approve
```
## Outputs
After the execution of the Terraform code you will get an output with needed IDs and values needed as input for the nexts Terraform applies. You can use this infrastructure to run other example blueprints, all you need is the `cluster_name`.
## Cleanup
Run the following command if you want to delete all the resources created before. If you have created other blueprints and they use these infrastructure then destroy those blueprint resources first.
```shell
terraform destroy
```
## Requirements
| Name | Version |
|------|---------|
| [terraform](#requirement\_terraform) | >= 1.1 |
| [aws](#requirement\_aws) | ~> 4.43 |
## Providers
| Name | Version |
|------|---------|
| [aws](#provider\_aws) | ~> 4.43 |
## Modules
| Name | Source | Version |
|------|--------|---------|
| [ecs](#module\_ecs) | terraform-aws-modules/ecs/aws | ~> 5.0 |
| [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
## Resources
| Name | Type |
|------|------|
| [aws_service_discovery_private_dns_namespace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/service_discovery_private_dns_namespace) | resource |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
## Inputs
No inputs.
## Outputs
| Name | Description |
|------|-------------|
| [ecs\_cluster\_id](#output\_ecs\_cluster\_id) | The ID of the ECS cluster |
| [ecs\_cluster\_name](#output\_ecs\_cluster\_name) | The name of the ECS cluster and the name of the core stack |
| [ecs\_task\_execution\_role\_arn](#output\_ecs\_task\_execution\_role\_arn) | The ARN of the task execution role |
| [ecs\_task\_execution\_role\_name](#output\_ecs\_task\_execution\_role\_name) | The ARN of the task execution role |
| [private\_subnets](#output\_private\_subnets) | A list of private subnets for the client app |
| [private\_subnets\_cidr\_blocks](#output\_private\_subnets\_cidr\_blocks) | A list of private subnets CIDRs |
| [public\_subnets](#output\_public\_subnets) | A list of public subnets |
| [service\_discovery\_namespaces](#output\_service\_discovery\_namespaces) | Service discovery namespaces already available |
| [vpc\_id](#output\_vpc\_id) | The ID of the VPC |