Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform Stack

I have created a terraform stack for all the required resources that we utilise to build out a virtual data center within AWS. VPC, subnet, security groups etc, etc.

It all works beautifully :). I am having a constant argument with network engineers that want to have a completely separate state for networking etc. As a result of this we have to manage multiple state files and it requires 10 to 15 terraform plan/apply commands to being up the data center. Not alone do we have to run the commands multiple times, we cannot reference the module output variables from when creating ec2 instances etc, so now there are "magic" variables appearing within variable files. I want to put the scripts to create the ec2 instances, els etc within the same directory as the "data center" configuration so that we manage one state file (encrypted in s3 with dynamodb lock) and that our git repo has a one to one relationship with our infrastructure. There is also the added benefit that a single terraform plan/apply will build the whole datacenter in a single command.

Question is really, is it a good idea to manage data center resources (vpc, subnets, security groups) and compute resources in a single state file? Are there any issues that I may come across? Has anybody experience in managing an AWS environment with terraform this way?

Regards, David

like image 846
DMcKenna Avatar asked Sep 20 '17 19:09

DMcKenna


People also ask

What is Terraform stack?

A stack represents a collection of infrastructure that CDK for Terraform (CDKTF) synthesizes as a dedicated Terraform configuration. Stacks allow you to separate the state management for multiple environments within an application.

Does Terraform create CloudFormation stack?

The Terraform philosophy is similar to CloudFormation, but the applied configuration is stored onto a “Terraform State” (a text file stored within a S3 bucket), instead of a CloudFormation stack.

What is the difference between CloudFormation and Terraform?

What is the difference between Terraform and CloudFormation? Terraform and CloudFormation are both infrastructure-as-code (IaC) tools. CloudFormation is developed by AWS and only manages AWS resources. Terraform is developed by HashiCorp and can manage resources across a wide range of cloud vendors.

Is Terraform good for AWS?

Terraform has helped a lot in the DevOps space, changing the way infrastructure is provisioned and managed. Can Terraform be used in AWS? Yes, Terraform can be used in AWS with the help of access and secret keys.

Is Terraform and AWS same?

Terraform by HashiCorp, an AWS Partner Network (APN) Advanced Technology Partner and member of the AWS DevOps Competency, is an “infrastructure as code” tool similar to AWS CloudFormation that allows you to create, update, and version your Amazon Web Services (AWS) infrastructure.


1 Answers

To begin with the Terraform provider let's you access output variables from other state files so you don't have to use magic variables. The rest is just a matter of your style. Do you frequently bring the whole datacenter infrastracture up? If so you may consider doing it in one project. If on the other hand you only change some things you may want to make it more modular relying on output from other projects. Keeping them separate makes the planing faster and avoids a very costly terraform destroy mistake.

like image 125
Jakub Kania Avatar answered Oct 13 '22 05:10

Jakub Kania