Practice and Project to Automation Infrastructure (IAC) or (IaaS) using Terraform & Python
-
Create AWS free tire account using this link: https://signin.aws.amazon.com/signup?request_type=register
-
Install chocolatly on windows (which helps install any software on windows)
-
Install Git & VS Code Editor
-
Install Terraform
-
Install aws CLI
- To Install git
choco install -y git
- To Install VS Code Editor
choco install -y vscode
- To Install Terraform
choco install -y terraform
- To Install AWS CLI
choco install -y awscli
- First, ensure that you are using an administrativeshell - you can also install as a non-admin, check out Non-Administrative Installation.
- Install with powershell.exe
NOTE
Please inspect https://community.chocolatey.org/install.ps1 prior to running any of these scripts to ensure safety. We already know it's safe, but you should verify the security and contents of any script from the internet you are not familiar with. All of these scripts download a remote PowerShell script and execute it on your machine. We take security very seriously. Learn more about our security protocols.
With PowerShell, you must ensure Get-ExecutionPolicy
is not Restricted. We suggest using Bypass
to bypass the policy to get things installed:
- Run
Get-ExecutionPolicy
. If it returnsRestricted
, then runSet-ExecutionPolicy AllSigned
orSet-ExecutionPolicy Bypass -Scope Process
.
Now run the following command:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
- Paste the copied text into your shell and press Enter.**
- Wait a few seconds for the command to complete.
- If you don't see any errors, you are ready to use Chocolatey! Type
choco
orchoco -?
now, or see Getting Started for usage instructions.
- Create Project Folder (with you desired folder name eg. Terraform_Automation)
- Open VS editor code
- Open the Folder which you created.
- Now go to plugins and add below plugins.
- HashiCorp Terraform
- Terraform
Create some files as below. (These below file names are optional)
- provider.tf
- main.tf
- inputs.tf
- outputs.tf
Creating a Group for Administrators and Setting Up an IAM User
- Sign in to the AWS Management Console and open the IAM console at https://console.aws.amazon.com/iam/.
- In the navigation pane, choose Groups, and then choose Create New Group.
- For Group Name, enter a name for your group, such as
Administrators
, and then choose Next Step. - In the list of policies, select the check box next to the
AdministratorAccess
policy.- You can use the Filter menu and the Search box to filter the list of policies.
- Choose Next Step, and then choose Create Group.
- Your new group is listed under Group Name.
- In the navigation pane, choose Users, and then choose Add user.
- In the User name box, enter a user name.
- Choose both:
- Programmatic access
- AWS Management Console access
- Choose Next: Permissions.
- Select the check box next to the Administrators group. Then choose Next: Review.
- Choose Create user.
- Sign out of the AWS Management Console.
- Use the following URL format to sign in to the console:
https://aws_account_number.signin.aws.amazon.com/console/
Replace
aws_account_number
with your AWS account ID (without any hyphens).
For example, if your AWS account ID is1234-5678-9012
, replaceaws_account_number
with123456789012
.
For information about how to find your account number, see Your AWS Account ID and Its Alias in the IAM User Guide. - Enter the IAM user name and password that you just created.
- When you're signed in, the navigation bar displays: your_user_name @ your_aws_account_id
- Go to the AWS management console, click on your Profile name, and then click on My Security Credentials.
- Go to Access Keys and select Create New Access Key
To pass the credentials dynamically to void exposing secrate key and token to the other users
- Setup all your access key, Secret Key, Region, output format, running below command in powershell terminal.
aws configure
- HashiCorp (HCL) Also be known as DSL (Domain Specific Language)
- Terraform Block
- Provider Block
- Data Block
- Resource Block
- Module Block
- Variable Block
- Output Block
- Locals Block.
Read this for more info : Terraform_Blocks
- Please refer the file provider.tf
This provider block needs to be executed using below command to install all the plug-ins and dependencies related to aws to work on
terraform init
Create Security Group:
- Create Manually
- Create Using Terraform (Refer the same page and scroll down a bit)