Terraform Notes – Day 3 – 20 Sept 2023
Limited Time Offer!
For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!
Terraform Slides
https://devopsschool.com/slides/terraform/index.html
How to set Condition in terraform?
Dependency mgmt
- implicit - Set by Providers
- explicit - deponds_on
deponds_on
explicit
How to loop or iterate in terraform?
Workspace
How to pass diff values to diff env using diff workspace?
Step 1 - Create terrafrom.tfvars [ Default Workspace ]
tagsvalue = "this-is-default"
numofecc2 = 20
cpu = 2
dbcpu = 6
appcpu =4
azs = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
Step 2 - Create qa.tfvars
tagsvalue = "this-is-qa"
numofecc2 = 5
dbcpu = 4
appcpu = 2
azs = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
Step 3 - Go to default workspace
$ terraform workspace select default
$ terraform apply --auto-approve [ Loading - terrafrom.tfvars and This would store state file in terraform.tfstate ]
Step 4 - Go to qa workspace
$ terraform workspace select qa
$ terraform apply --auto-approve -var-file="qa.tfvars" [ This would store state file in terraform.tfstate.d/qa.terraform.tfstate ]
qa.tfvars [ HIGH PRE]
terrafrom.tfvars [ LOW PRE]
Terraform Meta Aruguments
connection {
type = "winrm"
host = aws_instance.example.private_ip
user = "Administrator"
password = "your_password"
https = true # Enable HTTPS
insecure = true # Ignore SSL certificate validation (for testing purposes, not recommended in production)
port = 5986 # Use the default HTTPS port for WinRM
cacert = "/path/to/ca.crt" # Optional path to a CA certificate file (if required)
cert = "/path/to/client.crt" # Optional path to a client certificate file (if required)
key = "/path/to/client.key" # Optional path to the client certificate's private key file (if required)
timeout = "5m" # Set a timeout for the WinRM connection
max_retries = 3 # Maximum number of connection retries
}