This section will introduction you to create/destroy the infrastructure of this workshop by using Terraform
Download terraform by this link. After that, verify your terraform cli with:
terraform --version
Go to github account settings with this link. Then create Fine-grained personal access tokens with full permissions. After that copy the token to somewhere we can paste it in next step.
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
This is our terraform source code tree, i split each service into modules for use later.
.
├── main.tf
├── modules
│ ├── cloudfront
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── github
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ ├── iam-role
│ │ ├── main.tf
│ │ ├── outputs.tf
│ │ └── variables.tf
│ └── s3
│ ├── main.tf
│ ├── outputs.tf
│ └── variables.tf
├── outputs.tf
├── providers.tf
├── terraform.tfvars.example (You must copy and rename this file to "terraform.tfvars")
└── variables.tf
First, you must clone or download my source code at this link. After that you would copy 2 folders terraform
and next-app
to other directory (2 of them must be same directory).
any-directory
├── terraform/
├── next-app/
Next, in terraform
directory we need copy the file terraform.tfvars.example
to terraform.tfvars
, lets check about 2 variables: github_token
is the token we create in the step 1.2
and github_owner
is your github username (case sensitive).
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.
terraform apply -auto-approve
If this command runs well, we can see the final Cloudfront URL output at terminal and successfully create the infrastructure!
terraform destroy -auto-approve