Infrastructure is defined as code, but it is both human and machine readable.
for eg:
resource "aws_s3_bucket" "s3_bucket" {
acl = "private"
bucket_prefix = "testbucket"
region = "us-east-1"
}
Moving from physical to cloud based technology
Physical:
- Physical servers purchased and racked
- virtual machine created on host servers
-Redundant power and storage provisions
Cloud
- Instances spun up in cloud and paid per unit of time
- No more hosts
- Redundancy is built in when cloud services are configured properly
IaC Examples:
-Terraform
- CloudFormation
-Azure Resource Manager
- Google Deployment Manager
What IaC is not:
(Configuration tools)
-Chef
- Puppet
- Ansible
Makes sure it stays and complies with the configuration after provisioning
Why Terraform ?
- Build infrastructure
- Change infrasture
- Version infrastructure
- You can do all 3 of the above while keeping a much tigher grip on compliance using modules
-Cloud agnostic- can work in aws, gcp or azure
Terraform state file:
--- terraform state is stored in a file called terraform.tfstate
-- stores state information from a terraform apply
-- doesn'tr track changes in your cloud environment not made by Terraform . For eg: changes made in the console
How to make changes to state:
- Configuration file
- Terraform state command
- Terraform import commands
The Workflow:
Example Terraform state list
terraform state list
-- module.my_logs_bucket.aws_s3_bucket.s3_bucket
example output of a terraform.tfstate file
- defines individual resources that have been provisioned
- excludes resources that did not provision
examples:
high level examples
making changes to state without configuration file
terraform import
terraform import aws_instance.example <instance-id>
Terraform taint
-marks resoures as tainted . will recreate the resource at the run of the next terraform apply
Terraform untaint:
- talk to the terraform.tfstate file to untaint the specific item
-prevents the recreation of resources during terraform apply
terrform untaint aws_security_group.allow_all
Terrform destroy
--looks at the state file and will say let's burn it all down
-destroys all resources in the terraform.tfstate file
terraform destroy
No comments:
Post a Comment