{"id":14984553,"url":"https://github.com/amaurybsouza/iac-practice","last_synced_at":"2025-04-10T21:20:22.614Z","repository":{"id":45682760,"uuid":"396108598","full_name":"amaurybsouza/iac-practice","owner":"amaurybsouza","description":"☸️🚀🏗️A bit automation with Terraform to provision an EC2 instance (infrastructure as Code) on AWS and using Ansible to install Docker on this instance. A excellent hands-on to practice the union of Terraform and Ansible working together.","archived":false,"fork":false,"pushed_at":"2021-12-01T01:27:44.000Z","size":77,"stargazers_count":18,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-24T18:49:35.160Z","etag":null,"topics":["ansible","ansible-playbook","ansible-roles","aws","cloud","cloud-native","containers","docker","google-cloud","iac","infrastructure-as-code","linux","shell-script","terraform","terraform-module"],"latest_commit_sha":null,"homepage":"https://amaurybsouza.medium.com/","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amaurybsouza.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"securityGroup.tf","support":null}},"created_at":"2021-08-14T19:29:40.000Z","updated_at":"2024-08-22T14:28:10.000Z","dependencies_parsed_at":"2022-08-28T16:02:57.651Z","dependency_job_id":null,"html_url":"https://github.com/amaurybsouza/iac-practice","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amaurybsouza%2Fiac-practice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amaurybsouza%2Fiac-practice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amaurybsouza%2Fiac-practice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amaurybsouza%2Fiac-practice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amaurybsouza","download_url":"https://codeload.github.com/amaurybsouza/iac-practice/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248298782,"owners_count":21080400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-playbook","ansible-roles","aws","cloud","cloud-native","containers","docker","google-cloud","iac","infrastructure-as-code","linux","shell-script","terraform","terraform-module"],"created_at":"2024-09-24T14:09:15.633Z","updated_at":"2025-04-10T21:20:22.597Z","avatar_url":"https://github.com/amaurybsouza.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform \u0026 Ansible: Deep dive into IaC\n\nMotivated by the Docker course from @LINUXtips, I did a bit automation to provision an infrastructure as Code on AWS and then use Ansible to install Docker on an EC2 instance.\nMy plan is provision new resources on the AWS Cloud and write code using Terraform and Ansible with CI/CD tools to help all professionals who are starting their DevOps journey.\n\n## Table of Contents\n- [Requirements](#requirements)\n- [How does it work?](#how-does-it-work)\n- [Setup AWS credentials](#setup-aws-credentials)\n- [Create a AWS Key pairs](#create-a-AWS-Key-pairs)\n- [Create the Terraform files](#create-the-terraform-files)\n- [Terraform CLI Usage](#terraform-cli-usage)\n- [Contributing](#contributing)\n\n## Requirements\n\n- AWS Account \n- Ansible\n- Terraform\n- AWS CLI\n- Linux CLI \n\n## How does it work?\n\nBasically, the Terraform will create some resources on AWS, such as, EC2, SG and the Ansible will be invoked via Terraform resources (local-exec) to call Ansible Roles for then to install the Docker app on EC2 instance.\n\n## Setup AWS credentials\n\nUse the AWS Documentation to setup your AWS Credentials, basically you have some ways to do this, for example via credentials file or environment variables:\n\n- In my case I used the ```~/.aws/credentials``` file to create my credentials:\n\n```\n[default]\naws_access_key_id=AKIAIOSFODNN7EXAMPLE\naws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\n```\n\n## Create a AWS Key pairs\n\nNow you can create your Key pairs on AWS following the AWS Documentation below:\n\n- [Create AWS Key pairs](https://docs.aws.amazon.com/pt_br/AWSEC2/latest/UserGuide/ec2-key-pairs.html)\n\nRemember you can create a Terraform resource to provision automatically:\n\n```\nresource \"aws_key_pair\" \"deployer\" {\n  key_name   = \"deployer-key\"\n  public_key = \"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 email@example.com\"\n}\n```\n\n## Defining the Ansible Roles\n\nIt's the time to create the Ansible Roles:\n\n```yml\n$ ansible-galaxy init docker\n```\n\n## Create the Terraform files\n\nAccording to the best practices from the Terraform documentation, is necessary create several files \".tf\" to keep the environment working fine, the Terraform will read all files \".tf\" and will provision on the AWS Cloud.\n\n- provider.tf\n- securityGroups.tf\n- ec2Intance.tf\n\n## Terraform CLI Usage\n\nMain commands:\n\n```\n  init          Prepare your working directory for other commands\n  validate      Check whether the configuration is valid\n  plan          Show changes required by the current configuration\n  apply         Create or update infrastructure\n  destroy       Destroy previously-created infrastructure\n```\n\nExecute these commands after get completed before steps:\n\n```\n$ terraform init\n$ terraform plan\n$ terraform apply\n$ terraform destroy\n```\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famaurybsouza%2Fiac-practice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famaurybsouza%2Fiac-practice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famaurybsouza%2Fiac-practice/lists"}