Initialize terraform repository:
terraform init
Show what tf files will do:
terraform plan
Terraform used the selected providers to generate the following execution plan. Resource actions are
indicated with the following symbols:
+ create
Terraform will perform the following actions:
# aws_vpc.myvpc will be created
+ resource "aws_vpc" "myvpc" {
+ arn = (known after apply)
+ assign_generated_ipv6_cidr_block = false
+ cidr_block = "10.0.0.0/16"
+ default_network_acl_id = (known after apply)
+ default_route_table_id = (known after apply)
+ default_security_group_id = (known after apply)
+ dhcp_options_id = (known after apply)
+ enable_classiclink = (known after apply)
+ enable_classiclink_dns_support = (known after apply)
+ enable_dns_hostnames = (known after apply)
+ enable_dns_support = true
+ id = (known after apply)
+ instance_tenancy = "default"
+ ipv6_association_id = (known after apply)
+ ipv6_cidr_block = (known after apply)
+ main_route_table_id = (known after apply)
+ owner_id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
──────────────────────────────────────────────────────────────────────────────────────────────────────
Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly
these actions if you run "terraform apply" now.
Apply plan with:
terraform apply
It asks for confirmation - in build scripts we have to auto apply.
In order to destroy:
terraform destroy
Cloudformation maintains a state of your stack on AWS. Terraform uses state file to maintain the state.
If two people execute terraform apply at the same time this can lead to drift. State drift can make terraform break. In order to fix the drift - we import the AWS configuration to the state.
➜ first-resource git:(main) tflint
Failed to load configurations; main.tf:12,18-25: Invalid type specification; The keyword "stringy" is not a valid type specification.:
Error: Invalid type specification
on main.tf line 12, in variable "mylist":
12: type = list(stringy)
The keyword "stringy" is not a valid type specification.
- terraform works by folder
- terraform can also use modules
https://developer.hashicorp.com/terraform/docs
https://registry.terraform.io/browse/modules
- What is terraform
- create, init, plan, apply
- variables
- Outputs
- Tuples and Objects
- Homework challenge: Create a VPC using terraform, print the vpc id by using outputs
- Create EC2, how to check what are the required attributes using the terraform documentation.
- Create Elastic IP and associating with ec2 instance
Terraform aws modules: https://registry.terraform.io/modules/terraform-aws-modules/ec2-instance/aws/latest