SlideShare a Scribd company logo
NORDICS
DGI Byen’s CPH Conference
2024
NORDICS
The three problems of Terraform
Andrey Devyatkin | 2024-05-07
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
https://www.grc.com/sn/sn-923-notes.pdf
www.fivexl.io | hello@fivexl.io
Do it.
Do it better.
Do it right.
Alex Lindsay
www.fivexl.io | hello@fivexl.io
Andrey Devyatkin
Co-Host @ DevSecOps Talks
podcast
Principal AWS Consultant
AWS Community Builder
Security and Identity
Co-Founder @ FivexL
AWS User Group Leader
UG Las Palmas de GC
www.fivexl.io | hello@fivexl.io
https://www.istockphoto.com/es/foto/mano-de-gato-levantada-gm914509428-251700990
AWS Community Day CPH 2024 - Three problems of Terraform
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
three
conceptual
problems
Dynamic state location
Deploying the same configuration to multiple
environments
Environment specific parameters
A way to address differences between environments
Cross-state resources lookup
A need to reference resources from different states
www.fivexl.io | hello@fivexl.io
Assumptions
AWS
www.fivexl.io | hello@fivexl.io
https://www.primevideo.com/detail/Silicon-Valley/0PHZ6LOP10TB423SCOM0BMCFMM
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
$ ls
README.md
.terraform
main.tf
terraform.tfstate
www.fivexl.io | hello@fivexl.io
terraform {
backend "s3" {
bucket = "my-cool-startup-infra-state"
key = "terraform/main.tfstate"
region = "us-east-1"
}
}
www.fivexl.io | hello@fivexl.io
Assumptions
AWS
S3 backend
www.fivexl.io | hello@fivexl.io
So far so good
No need for the wrapper
www.fivexl.io | hello@fivexl.io
https://www.amazon.co.uk/Silicon-Valley-Season-2-DVD/dp/B018I8RFZS
www.fivexl.io | hello@fivexl.io
We need to deploy the app to
the second environment
www.fivexl.io | hello@fivexl.io
Assumptions
AWS
dev/production
S3 backend
www.fivexl.io | hello@fivexl.io
We need to change
backend configuration
depending on env
www.fivexl.io | hello@fivexl.io
terraform {
backend "s3" {
bucket = "my-cool-startup-infra-state"
key = "terraform/main.tfstate"
region = "us-east-1"
}
}
www.fivexl.io | hello@fivexl.io
https://github.com/hashicorp/terraform/issues/17288
https://github.com/opentofu/opentofu/issues/1042
www.fivexl.io | hello@fivexl.io
Can we use Terraform
workspaces?
www.fivexl.io | hello@fivexl.io
https://developer.hashicorp.com/terraform/cli/workspaces
As of 2023-05-18
www.fivexl.io | hello@fivexl.io
https://developer.hashicorp.com/terraform/cli/workspaces#when-not-to-use-multiple-workspaces
As of 2023-05-18
Okay, what is the real life use case then?
🤔
www.fivexl.io | hello@fivexl.io
https://developer.hashicorp.com/terraform/cli/workspaces#alternatives-to-workspaces
As of 2023-05-18
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
https://terragrunt.gruntwork.io/docs/features/keep-your-terragrunt-architecture-dry/
www.fivexl.io | hello@fivexl.io
But why so many
directories? Can’t we just
use the same directory
somehow? 🤔
www.fivexl.io | hello@fivexl.io
https://developer.hashicorp.com/terraform/language/settings/backends/configuration#partial-configuration
As of 2023-05-18
www.fivexl.io | hello@fivexl.io
terraform {
backend "s3" {
bucket = "my-cool-startup-infra-state"
key = "terraform/main.tfstate"
region = "us-east-1"
}
}
www.fivexl.io | hello@fivexl.io
terraform {
backend "s3" {}
}
terraform init 
-backend-config "bucket=my-cool-startup-infra-state" 
-backend-config "key=terraform/main.tfstate" 
-backend-config "region=us-east-1"
www.fivexl.io | hello@fivexl.io
Do we share S3 bucket
between environments?
www.fivexl.io | hello@fivexl.io
Assumptions
AWS
dev/production
S3 backend
bucket/state per env with
predefined name
www.fivexl.io | hello@fivexl.io
terraform {
backend "s3" {}
}
terraform init 
-backend-config "infra-state-7YYYYYYYYY62" 
-backend-config "key=terraform/main.tfstate" 
-backend-config "region=us-east-1"
www.fivexl.io | hello@fivexl.io
Why did we name s3
bucket this way? 🤔
www.fivexl.io | hello@fivexl.io
format("infra-state-%s",
data.aws_caller_identity.current.account_id)
www.fivexl.io | hello@fivexl.io
Would exposing the account
id get us into trouble? 🤔
www.fivexl.io | hello@fivexl.io
As of 2024-05-07
https://medium.com/@maciej.pocwierz/how-an-empty-s3-bucket-can-make-your-aws-bill-explode-934a383cb8b1
www.fivexl.io | hello@fivexl.io
https://www.lastweekinaws.com/blog/are-aws-account-ids-sensitive-information/
www.fivexl.io | hello@fivexl.io
Control Tower naming convention
www.fivexl.io | hello@fivexl.io
# debatable
format("infra-state-%s-%s",
data.aws_caller_identity.current.account_id,
data.aws_region.r.name)
# paranoid edition
format("infra-state-%s", sha1(
format(
"%s-%s",data.aws_caller_identity.current.account_id
data.aws_region.r.name)))
www.fivexl.io | hello@fivexl.io
Why not just use env
suffix like -prod or -dev?
🤔
www.fivexl.io | hello@fivexl.io
If we are using the same dir
then how to be with .terraform?
🤔
www.fivexl.io | hello@fivexl.io
https://developer.hashicorp.com/terraform/cli/config/environment-variables#tf_data_dir
As of 2023-05-18
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
AWS_DEFAULT_REGION
env variable?
Use aws-vault for env setup
www.fivexl.io | hello@fivexl.io
$ ls
README.md
.terraform.7YYYYYYYYY62
.terraform.8XXXXXXXXX28
main.tf
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
How do we specify different
parameters for different
environments?
www.fivexl.io | hello@fivexl.io
https://developer.hashicorp.com/terraform/language/values/variables#assigning-values-to-root-module-variables
As of 2023-05-18
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
$ ls
README.md
7YYYYYYYYY62.tfvars
8XXXXXXXXX28.tfvars
.terraform.7YYYYYYYYY62
.terraform.8XXXXXXXXX28
main.tf
$ cat 7YYYYYYYYY62.tfvars
# dev
instance_type = "t4g.micro"
$ cat 8XXXXXXXXX28.tfvars
# prod
instance_type = "t4g.large"
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
Do we really need a
wrapper for this?
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
What if we add more
applications?
www.fivexl.io | hello@fivexl.io
https://infrastructure-as-code.com/book/2018/03/28/defining-stacks.html
www.fivexl.io | hello@fivexl.io
https://www.youtube.com/watch?v=wgzgVm7Sqlk
www.fivexl.io | hello@fivexl.io
How do I get VPC id from network
stack to my application stack?
www.fivexl.io | hello@fivexl.io
https://developer.hashicorp.com/terraform/language/state/remote-state-data
www.fivexl.io | hello@fivexl.io
Terragrunt remote state resoltion
www.fivexl.io | hello@fivexl.io
AWS SSM
Parameters
AWS S3
Self-containing
modules
Are the other ways?
Tooling
www.fivexl.io | hello@fivexl.io
Self-contained
modules? 🤔
Create resources
Look up resources
Provide policies
…
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
two
more
problems
Licensing
Are you competing with HashiCorp?
Team work
How do you work together with the same state?
www.fivexl.io | hello@fivexl.io
OpenTofu
Not a big gap at the
moment
Unclear longevity
Community
requested features
Has a momentum
www.fivexl.io | hello@fivexl.io
Terraform is a cli tool
That operates on a shared resources
www.fivexl.io | hello@fivexl.io
Conventional CI/CD
vs
TACOS
Terraform Automation and Collobaration Systems
www.fivexl.io | hello@fivexl.io
Commit
UnitTest
Lint
Build
Deploy Test Promote
CI/CD Server
TACOS
Server
www.fivexl.io | hello@fivexl.io
Benefits of using
TACOS
Lock down access to
the state
Better visibility
Less shoulders
bumping
Extra features
https://www.reddit.com/r/Terraform/comments/lkylzk/scalr_vs_spacelift_vs_atlantis_vs_env0_bake_off/
www.fivexl.io | hello@fivexl.io
Conclusion and
recap
www.fivexl.io | hello@fivexl.io
three
conceptual
problems
Dynamic state location
Deploying the same configuration to multiple
environments
Environment specific parameters
A way to address differences between environments
Cross-state resources lookup
A need to reference resources from different states
www.fivexl.io | hello@fivexl.io
two
more
problems
Licensing
Are you competing with HashiCorp?
Team work
How do you work together with the same state?
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
Tools like Terragrunt offer nice extra
features
Which are making going back harder
www.fivexl.io | hello@fivexl.io
conventions vs wrappers
www.fivexl.io | hello@fivexl.io
www.fivexl.io | hello@fivexl.io
https://www.youtube.com/channel/UCiJjTS8EiCKlbT85It_0e6g
Thank you
https://github.com/Andrey9kin/3-terraform-problems
https://twitter.com/andrey9kin
https://www.linkedin.com/in/andreydevyatkin/
andrey.devyatkin@fivexl.io
https://devsecops.fm/
NORDICS
Thank you!

More Related Content

PDF
2023-05-24 - Three problems of Terraform DevOps Pro EU.pdf
PDF
Terraform -- Infrastructure as Code
PDF
Managing AWS Using Terraform AWS Atlanta 2018-07-18
PDF
Managing AWS Using Terraform AWS Chicago-Suburbs 2018-01-18
PDF
Terraform introduction
PPTX
"Continuously delivering infrastructure using Terraform and Packer" training ...
PPTX
Terraform Abstractions for Safety and Power
PDF
Terraform – Infrastructure as Code (Kielux'18)
2023-05-24 - Three problems of Terraform DevOps Pro EU.pdf
Terraform -- Infrastructure as Code
Managing AWS Using Terraform AWS Atlanta 2018-07-18
Managing AWS Using Terraform AWS Chicago-Suburbs 2018-01-18
Terraform introduction
"Continuously delivering infrastructure using Terraform and Packer" training ...
Terraform Abstractions for Safety and Power
Terraform – Infrastructure as Code (Kielux'18)

Similar to AWS Community Day CPH 2024 - Three problems of Terraform (20)

PDF
Infrastructure as Code - Terraform - Devfest 2018
PDF
Terraform - Taming Modern Clouds
PDF
Building infrastructure with Terraform (Google)
PDF
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
PDF
Infrastructure as Code with Terraform
PDF
Terraform at Scale - All Day DevOps 2017
PDF
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
PDF
Terraform-2.pdf
PDF
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
PPTX
Terraform - The Road to Self-Service
PDF
Devops Columbia October 2020 - Gabriel Alix: A Discussion on Terraform
PDF
Devops Columbia October 2020 - Gabriel Alix: A Discussion on Terraform
PPTX
Hashicorp-Certified-Terraform-Associate-v3-edited.pptx
PDF
Building infrastructure as code using Terraform - DevOps Krakow
PPTX
AWS Security best practices Terraform AWS security
PPTX
Terraform
PPTX
Terraform: Taming the Machines Through Continuous Integration
PDF
Terraform Q&A - HashiCorp User Group Oslo
PDF
Terraform modules and best-practices - September 2018
PDF
Microservices with Terraform, Docker and the Cloud. Chicago Coders Conference...
Infrastructure as Code - Terraform - Devfest 2018
Terraform - Taming Modern Clouds
Building infrastructure with Terraform (Google)
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Infrastructure as Code with Terraform
Terraform at Scale - All Day DevOps 2017
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Terraform-2.pdf
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
Terraform - The Road to Self-Service
Devops Columbia October 2020 - Gabriel Alix: A Discussion on Terraform
Devops Columbia October 2020 - Gabriel Alix: A Discussion on Terraform
Hashicorp-Certified-Terraform-Associate-v3-edited.pptx
Building infrastructure as code using Terraform - DevOps Krakow
AWS Security best practices Terraform AWS security
Terraform
Terraform: Taming the Machines Through Continuous Integration
Terraform Q&A - HashiCorp User Group Oslo
Terraform modules and best-practices - September 2018
Microservices with Terraform, Docker and the Cloud. Chicago Coders Conference...
Ad

More from Andrey Devyatkin (16)

PDF
AWS Summit AMS 2025 - Beyond 3: Scaling to 50 AWS Accounts Without Losing Con...
PDF
AWS Summit AMS 2024 - From Complexity to Clarity
PDF
2023-11-23-AWS-UG-Las-Palmas-Increase-your-security-posture-with-temporary-el...
PDF
2023-09-28-AWS Las Palmas UG - Dynamic Anti-Frigile Systems.pdf
PDF
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
PDF
2020-02-20 - HashiCorpUserGroup Madring - Integrating HashiCorp Vault and Kub...
PDF
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
PDF
HashiCorp Vault configuration as code via HashiCorp Terraform- stories from t...
PDF
2019 03-21 - cloud native computing las palmas meetup #1
PDF
Cloud Native Computing Las Palmas. Meetup #0
PDF
The state of Jenkins pipelines or do I still need freestyle jobs
PDF
Running jenkins in a public cloud - common issues and some solutions
PDF
Stockholm JAM September 2018
PDF
Getting Git Right @ Git Merge 2018
PDF
Stockholm Jenkins Area Meetup, March 2017
PDF
Synchronizing parallel delivery flows in jenkins using groovy, build flow and...
AWS Summit AMS 2025 - Beyond 3: Scaling to 50 AWS Accounts Without Losing Con...
AWS Summit AMS 2024 - From Complexity to Clarity
2023-11-23-AWS-UG-Las-Palmas-Increase-your-security-posture-with-temporary-el...
2023-09-28-AWS Las Palmas UG - Dynamic Anti-Frigile Systems.pdf
HashiConf Digital 2020: HashiCorp Vault configuration as code via HashiCorp T...
2020-02-20 - HashiCorpUserGroup Madring - Integrating HashiCorp Vault and Kub...
2020-02-20 - HashiTalks 2020 - HashiCorp Vault configuration as code via Hash...
HashiCorp Vault configuration as code via HashiCorp Terraform- stories from t...
2019 03-21 - cloud native computing las palmas meetup #1
Cloud Native Computing Las Palmas. Meetup #0
The state of Jenkins pipelines or do I still need freestyle jobs
Running jenkins in a public cloud - common issues and some solutions
Stockholm JAM September 2018
Getting Git Right @ Git Merge 2018
Stockholm Jenkins Area Meetup, March 2017
Synchronizing parallel delivery flows in jenkins using groovy, build flow and...
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
KodekX | Application Modernization Development
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Approach and Philosophy of On baking technology
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
KodekX | Application Modernization Development
Network Security Unit 5.pdf for BCA BBA.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
A Presentation on Artificial Intelligence
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
Per capita expenditure prediction using model stacking based on satellite ima...
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Approach and Philosophy of On baking technology
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars

AWS Community Day CPH 2024 - Three problems of Terraform