IaC (Terraform)

This section will introduction you to create/destroy the infrastructure of this workshop by using Terraform

1. Setup

1.1. Setup Terraform

Download terraform by this link. After that, verify your terraform cli with:

terraform --version

1.2. Setup AWS CLI and credentials

Install AWS CLI at this link. Then verify it with

aws --version

Using this document to setup AWS Credentials to our AWS CLI with this link

1.3. Setup AWS SAM CLI

Install SAM CLI for building lambda functions stage: link

sam --version

1.4. Setup NVM and NodeJS Esbuild

Install NVM at this link and run following command to install nodejs and esbuild link

# Validate nvm
nvm -v

# Install nodejs with latest version (Listing version with `nvm ls` or specified version `nvm install 20 && nvm use 20`)
nvm install node && nvm use node

# Validate nodejs is installed
node -v

# Install esbuild global
npm install -g esbuild

2. Running

Region is us-east-1.

This is our terraform source code tree, i split each service into modules for use later.

.
├── README.md
├── main.tf
├── modules
│   ├── amazon-bedrock
│   │   ├── main.tf
│   │   ├── outputs.tf
│   │   ├── providers.tf
│   │   └── variables.tf
│   ├── cloudwatch
│   │   ├── main.tf
│   │   ├── outputs.tf
│   │   └── variables.tf
│   ├── dynamodb
│   │   ├── main.tf
│   │   ├── outputs.tf
│   │   └── variables.tf
│   ├── iam-role
│   │   ├── main.tf
│   │   ├── outputs.tf
│   │   └── variables.tf
│   ├── lambdas
│   │   ├── main.tf
│   │   ├── outputs.tf
│   │   └── variables.tf
│   ├── s3
│   │   ├── main.tf
│   │   ├── outputs.tf
│   │   └── variables.tf
│   ├── ses
│   │   ├── main.tf
│   │   ├── outputs.tf
│   │   └── variables.tf
│   └── sqs
│       ├── main.tf
│       ├── outputs.tf
│       └── variables.tf
├── outputs.tf
├── providers.tf
├── terraform.tfvars.example (You must copy and edit this file to `terraform.tfvars`)
└── variables.tf

2.1. Copy resource to other directory

First, you must clone or download my source code at this link. After that you would copy folder resource to other directory and then you can start creating your infrastructure.

Next, in terraform directory we need copy the file terraform.tfvars.example to terraform.tfvars.

  • region = “us-east-1”
  • bucket_name = “ai-powered-email-auto-replies-001”
  • custom_domain = “YOUR_DOMAIN” <– Change this
  • sender_email = “YOUR_EMAIL_TEST” <– Change this
  • source_email = “support@YOUR_DOMAIN” <– Change this

2.2. Init terraform

Go to terraform directory

cd terraform

Init Provider

terraform init

Check current state and variables

terraform plan

If not errors occurs, we can go next.

2.3. Creating resources

terraform apply -auto-approve

After this, you must go to SES dashboard to setup Easy DKIM in the step 4 Setting Domain and Email identity. Now, you can go to testing your result.

2.4. Deleting resources

terraform destroy -auto-approve