Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building infrastructure as code using Terraform - DevOps Krakow


Published on

AWS/Terraform - Questions and problems

Published in: Technology

Building infrastructure as code using Terraform - DevOps Krakow

  1. 1. Building infrastructure as code using Terraform (Q&P) DevOps Krakow meetup 17.1.2018
  2. 2. Agenda 1. Terraform basics 2. Frequent Terraform Questions 3. Frequent Terraform Problems 4. Your turn Any questions? I read all emails - Follow me on twitter and github - @antonbabenko
  3. 3. Anton Babenko I enjoy: ● DevOps, AWS, Terraform (since 2015) ● Open-source: ○ ○ (work in progress) ○ - more projects ● Organise events (AWS User Group Norway, HashiCorp User Group Oslo, DevOpsDays Oslo) ● Solving problems PS: I am looking for Terraform companions to join me!
  4. 4. Some facts about terraform-aws-modules ● Terraform AWS modules have 450K+ downloads per month (Dec 2017) from the Terraform Registry ● Terraform AWS security group module was mostly written offline
  5. 5. Featuring... Write, Plan, and Create Infrastructure as Code
  6. 6. Terraform 101 ( provider "aws" { region = "eu-west-1" } resource "random_pet" "bucket" {} resource "aws_s3_bucket" "app" { bucket = "hi-${random_pet .bucket. id}" website { index_document = "index.html" } } data "template_file" "index" { template = "${file("index.html")}" vars { BUCKET = "${aws_s3_bucket .app.website_endpoint }" } } resource "aws_s3_bucket_object" "object" { bucket = "${aws_s3_bucket}" key = "index.html" content = "${data. template_file .index.rendered }" etag = "${md5(data. template_file .index.rendered )}" content_type = "text/html" acl = "public-read" } output "app_website_endpoint" { value = "${aws_s3_bucket .app.website_endpoint }" } index.html can access: ${BUCKET} $ terraform init $ terraform plan $ terraform apply Apply complete! Resources: 3 added, 0 changed, 0 destroyed. Outputs: app_website_endpoint = hi-feasible-basilisk.s3-website-eu-west-1.a
  7. 7. Terraform training material rm-and-packer-training-material
  8. 8. Frequent Terraform Questions (FTQ)
  9. 9. So, how to get started with Terraform? 1. 2. Get infrastructure modules from Terraform Registry. For example, AWS modules - 3. Follow instructions in, check examples, open issues and pull requests 4. Read a book (Getting Started with Terraform or Terraform Up & Running)
  10. 10. Why Terraform and not AWS CloudFormation/Azure ARM templates/Google Cloud Deployment Manager? Terraform manages 70+ providers, has easier syntax (HCL), has native support for modules and remote states, has teamwork related features. Terraform is an open-source project (670 stars on AWS provider, 10K stars on Terraform core). rm-and-packer-training-material
  11. 11. What is the point of using Terraform if you’re running AWS only? Isn’t Terraform just an unnecessary abstraction, why not stick to CloudFormation? ● Terraform has easier syntax (HCL) ● Native support for modules and remote states ● Teamwork related features (eg, lock, plan to file) ● Abstractions (primitives and modules) are necessary for anything good ● Terraform Registry (check verified modules) ● Terraform is an open-source project!
  12. 12. What are the tools/solutions out there? ● Terraform Registry ( - collection of public Terraform modules for common infrastructure configurations for any provider. I maintain verified AWS modules there. ● Thin wrapper for Terraform that provides extra tools for working with multiple Terraform modules - ● Terraform linter to detect errors that can not be detected by `terraform plan` - ● Terraform version manager - ● A web dashboard to inspect Terraform States - ● Jsonnet - The data templating language - ● A unified workflow for collaborating on Terraform through GitHub and GitLab - This list is much longer, really…
  13. 13. How to handle secrets in Terraform? 1. Can you accept secrets to be saved in state file in plaintext? Probably not. a. AWS IAM password & access secret keys - use PGP as b. AWS RDS - set dummy password and change after DB is created c. AWS RDS - use iam_database_authentication_enabled = true d. EC2 instance user-data + AWS KMS e. EC2 instance user-data + AWS System Manager’s Parameter Store 2. Other options: a. Secure remote state location (S3 bucket policy, KMS key)
  14. 14. How to integrate Terraform with ...? ● Use outputs (human-friendly) ● Use null_resource + local-provisioner for WAF associations resource "null_resource" "auto_instructions" { triggers = { waf_acl_id = "${aws_waf_web_acl}" } provisioner "local-exec" { command = "aws waf-regional associate-web-acl --web-acl-id ${ aws_waf_web_acl} --resource-arn ${data. terraform_remote_state .alb_public.this_alb_arn }" } }
  15. 15. Frequent Terraform Problems (FTP)
  16. 16. Upgraded Terraform version, and there is a breaking bug, so I want to rollback, but I can’t because state file has been upgraded already. ● State file should be versioned (!), download previous version of state file, run “terraform state push old_version.tfstate” ● Lock terraform version, lock module and providers version (available in Terraform 0.11) ● Read upgrade guides and files: ○ ○ ○
  17. 17. What is your Terraform question or problem? Hints: Testing? Versioning? Code structure? Working as a team? CI/CD? Automation? Integration with other tools? ? Code generation? Missing tools/features? Syntax sugar (features and types of variables)? How to contribute?
  18. 18. Thanks! Any questions?