Skip to content

elaynelemos/terralearning

Repository files navigation

Learning Terraform

This is an unstable Terraform infrastructure. Used only to keep track of what I'm learning. Structure based on cookiecutter infra template.

Modules structure

# Name Description Path Based on
0. Hello World Creating a starting EC2 instance hello-world An Introduction to Terraform
1. Autoscaling Group Example Setting up the basics of an ASG asg-example An Introduction to Terraform
2. Stage Storage Managing remote state storages and environments state-storage How to manage Terraform state
2.1. Workspace Isolation Fast testing small infrastructure changes through environment workspaces state-storage/workspace-isolation How to manage Terraform state
2.2. File Layout Isolation Separating environments through file layout convention and authentication state-storage/file-layout-isolation How to manage Terraform state
2.3. Terraform Remote State as Datasource Isolating infrastructures and accessing its attributes with datasource state-storage/tf-remote-state-datasource How to manage Terraform state
3. Modules Defining and using terraform modules modules and modules-usage-example How to create reusable infrastructure with Terraform modules

CI/CD Requirements

Terraform s3 state bucket has to be already created.

GitHub Actions requires GitHub Secrets for the project:

  • GITHUB_TOKEN - registered token at GitHub
  • AWS_ACCESS_KEY_ID - service user key id
  • AWS_SECRET_ACCESS_KEY - service user access key

Continuous Integration (currently not working)

After Push or PR to main branch GitHub Action will run Terraform CI with Linting, Init, Validate and Plan.

Deploy

  • Option 1: You can apply the infrastructure by manually triggering Terraform Deploy at Actions. (currently not working)
  • Option 2: Or you can clone this repo and deploy it locally from your command line with terraform from the desired infrastructure directory:
  export AWS_ACCESS_KEY_ID='<INSERT_YOUR_KEY_HERE>'
  export AWS_SECRET_ACCESS_KEY='<INSERT_YOUR_SECRET_HERE>'
terraform init
terraform plan -out infra.tfplan
terraform apply infra.tfplan

Note: the commands above will, respectively, make your credentials temporarily available for scripts, initialize terraform at the project, structure the resources to be created and then create the structure itself. Use the plan command to understand what's going to be done.

Destroy

To destroy the infrastructure created, go to its directory and run:

terraform destroy

License

License: MIT

About

Finding out what terraform is made of.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages