# AWS Terraform deployment

Information specific to CiviForm Terraform deploy scripts for AWS.

For general information, see [Terraform deploy system](https://docs.civiform.us/it-manual/sre-playbook/initial-deployment/terraform-deploy-system).

## Infrastructure

![AWS System Diagram](https://user-images.githubusercontent.com/1741747/184951252-1a33c8c8-8a86-44ea-b39a-cebea71e7495.png)

Created for CiviForm app:

* VPC
* Load balancer
* Internet Gateway
* NAT Gateway
* Fargate ECS cluster
* RDS with Postgres
* S3 bucket

Connected services

* SES
* Secrets Manager

Supporting Infrastructure:

* S3 bucket for Terraform backend state
* Cloudwatch export for logs

## Code and examples (AWS)

The code that manages deployment can be found [here](https://github.com/civiform/cloud-deploy-infra/tree/main/cloud/aws).

Our staging environment is at [staging-aws.civiform.dev](https://staging-aws.civiform.dev).

Config for the staging environment is [here](https://github.com/civiform/civiform-staging-deploy/blob/main/aws_staging_civiform_config.sh).

## Troubleshooting

After running the `setup` or `deploy` script, you can login to the [AWS ECS console](https://console.aws.amazon.com/ecs/v2/clusters) to check the status of CiviForm. Make sure to select correct region in the top right corner.

You should see Cluster with app\_preffix-civiform name. Click on it and go to Tasks tab. If everything is going well you should see a task in the Running state.

![Screen Shot 2022-08-15 at 5 18 55 PM](https://user-images.githubusercontent.com/1741747/184758808-c1081316-7baf-45dc-9c76-a64594a9de5e.png)

### Inspecting task config

You can see the task configuration by clicking on the Task definition tab, finding the latest revision, and opening the JSON tab.

![Screen Shot 2022-08-15 at 5 21 53 PM](https://user-images.githubusercontent.com/1741747/184758833-fce81bec-9f2c-49be-a102-2d5b38aa58dd.png)

### Inspecting logs

You can see the logs on the task page by clicking into the specific task and selecting Logs.

![Screen Shot 2022-08-15 at 5 23 27 PM](https://user-images.githubusercontent.com/1741747/184758931-a8374a7a-d1dc-4308-8676-7617d4237d7a.png)

Logs are also available in Cloudwatch. Search for app\_prefix-civiformlogs group.

![Screen Shot 2022-08-15 at 5 26 42 PM](https://user-images.githubusercontent.com/1741747/184758880-f92b064b-658c-401e-ad71-175f64fde305.png)
