Terraform Setup
- Install Terraform:
- Windows:
choco install terraform -y
- Other:
- Install Visual Studio Code
- Add Terraform Extension to Visual Studio Code
Basics of Terraform DSL
- Input for terraform is folder/directory
- Terraform will pick all the files in the input folder with *.tf
- Provider Syntax
provider "<provider name>" {
arg1 = value1
...
...
argn = valuen
}
####### Example ###########
provider "aws" {
region = "us-west-2"
secret_key = "jkdsahfkjadsfhkjasdfhdkjahfdakj"
access_key = "kjsdhfkjsdfkjhdsf"
}
resource "<resource type>" "<your name for this resource>" {
arg1 = value1
...
...
argn = valuen
}
############### Example ###############
resource "aws_instance" "mywebserver" {
ami = "<ami id>"
instance_type = "t2.micro"
}
Execution Steps
- Create a directory with name "hello-aws"
- create a file inside directory "hello-aws" named "main.tf" with above contents
terraform init <dirpath of hello-aws>
terraform validate <dirpath of hello-aws>
terraform apply <dirpath of hello-aws>
Like this:
Like Loading...