Basic-Terraform-Setup
Basic Terraform Setup
Docs and Source
Explanation and Notes
The setup is fairly simple process.
- Create a
main.tffile for everything we need. - Fill out the config file like the code example below.
- Run
terraform initto download the providers and setup the directory. - Run
terraform fmtso that Terraform formats the file to make it all pretty. - Run
terraform validateto confirm that the file has the right syntax and is formatted correctly - Run
terraform planto have Terraform look through the file and give you a print out of what the configuration you wrote will do. - Run
terraform applyto apply the plan. Type inyeswhen you've confirmed that Terraform will do what you want it to. - Once you get the OK from Terraform, you can type in
terraform showto see the state of Terraform. Which shows what is recorded in the Terraform state file. Which is what Terraform uses to keep track of what is set up. - You can see a more detailed view of each of the deployed resources using
terraform state list.
Code Example
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.16"
}
}
required_version = ">= 1.2.0"
}
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "app_server" {
ami = "ami-830c94e3"
instance_type = "t2.micro"
tags = {
Name = "ExampleAppServerInstance"
}
}
#GeneralTools
#Terraform