Terraform Tips

This is just a brain dump to myself 🙂

I’m moving some functions from Ansible to Terraform and this is some basic commands:

How to find the CentOS 7 official AMI Image

aws ec2 describe-images \
    --owners 'aws-marketplace' \
    --filters 'Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce' \
    --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \
    --region 'eu-central-1' \
    --output 'text'

How to find the Ubuntu official Image

Ubuntu AWS ami Locator: https://cloud-images.ubuntu.com/locator/ec2/

AWS Marketplace (Filtered by SO and Free): https://aws.amazon.com/marketplace/

instance.tf

terraform apply # Will create all machines on instance.tf
terraform destroy # Destroy managed infrastructure
terraform plan # Will show but not apply
terraform plan -out exampletest.out #
terraform appy exampletest.out #

terraform import aws_instance.example i-abcd1234

This command locates the AWS instance with ID i-abcd1234 and attaches its existing settings, as described by the EC2 API, to the name aws_instance.example in the Terraform state.

Variables how it works