Questions tagged [terraform]

For questions about Terraform, an open source tool to maintain infrastructure.

Filter by
Sorted by
Tagged with
57
votes
7answers
23k views

How can I manage secrets in .tf and .tfstate?

I would like to use the Terraform MySQL Provider to keep a list of mysql users and grants handy for creating new test environments. The .tf and .tfstate files both seem to want to store the MySQL ...
46
votes
6answers
20k views

How to test a Terraform Configuration?

If you had a Terraform configuration that had a moderate degree of complexity, how would you write tests around the configuration that could be executed as part of a Continuous Integration / ...
41
votes
4answers
44k views

Terraform: apply only one tf file

I have my security groups in a securitygroup.tf file. In the same dir there are plenty of other resource descriptions (rds, ec2 etc). Is there a way to perform a terraform apply --auto-approve only ...
28
votes
2answers
27k views

How to use cloud-init with Terraform?

I am working with Digital Ocean and Terraform and I already can automate the domain, subdomain, network preferences and the host but there is a section called User data that looks like this: The ...
14
votes
4answers
12k views

Terraform: Is there a concise syntax for specifying multiple tags for a resource?

To attach multiple tags to a resource, I currently use multiple tag blocks: resource "aws_autoscaling_group" "instance" { ... tag { key = "Name" value = "${...
14
votes
2answers
157 views

How can I keep track of my Cloud Resource use?

I am trying to automate my AWS application deployment with Jenkins. Right now if we want to update the application in any of the environments, say UAT, we build our docker images, find the current ...
11
votes
2answers
378 views

How to create a host on a DigitalOcean team with Terraform?

Teams on Digital Ocean are very recent and there is no documentation about using them with Terraform. All information I can found is how to work with them manually. I was hoping that I could say ...
9
votes
1answer
2k views

Terraform: How to support releasing new versions of the code, running in parallel with the last stable release?

I have one service in production (on AWS), which follows the immutable server pattern. Its deployment looks like this: Create a new AMI with Packer Create a new CloudFormation stack, starting with an ...
9
votes
1answer
592 views

How can I manage changes in desired capacity due to scaling policies in AutoScaling Group state?

How can I manage changes in desired capacity due to scaling policies in AutoScaling Group state in terraform? Specifically, suppose I provision an aws_autoscaling_group resource with terraform with a ...
9
votes
3answers
375 views

How should we automatically rebuild immutable infrastructure when new packages are available?

We're going to be using Terraform to automate our infrastructure deployment and Packer to create the machine images deployed by Terraform. By following immutable infrastructure design principles, we ...
8
votes
1answer
3k views

How do I detach an existing volume and attach a new volume with Terraform?

Is there a way to detach EBS volume from existing EC2 instance and attach a new EBS volume using Terraform v0.9.2 ? I prefer to replace the volume rather than trying to destroy the instance and ...
8
votes
1answer
2k views

How to organize infrastructure as code projects?

I have completed an Infrastructure-as-Code project using Terraform and Ansible. Currently, I organize my project as follows: Project1 Terraform ec2.tf rds.tf … variables....
7
votes
2answers
3k views

Does terraform support blue green deployments and roll backs out of the box

I have been trying use terraform for a while . any suggestions/tips on how I can handle blue green deployments . I see how terraform enables it with auto scale groups on aws . But I’d like run some ...
7
votes
2answers
892 views

How to add shards to a Redis cluster managed by Terraform without loosing all state?

I have set up a Redis cluster with Terraform. The setup looks like this: resource "aws_elasticache_replication_group" "instance" { replication_group_id = "test" node_type = "...
6
votes
3answers
4k views

How to use terraform import with module

Terraform v0.11.11 We have a quite big AWS setup created with Terraform. Different regions are applied separately, and that is why we have most of the things in modules which are imported like this: ...
6
votes
6answers
710 views

In the HashiCorp stack, where's the appropriate place to add users?

I'm in the process of building some custom Linux images using HashiCorp's Packer, which will later be deployed to Azure using HashiCorp's Terraform. The VMs created from these images will need to have ...
6
votes
2answers
175 views

How to reconcile Infrastructure as Code and not storing env config in code?

When developing a Web App, and trying to adhere to what is generally considered best practice, e.g. The 12 factor app methodology etc. One key concept is to keep configuration and sensitive data out ...
6
votes
3answers
19k views

How to make Terraform Modules wait for resources to be created in place of using computed values

Today I am working on building out several custom Terraform Modules. The issue that I am trying to figure out how to work around dependencies within modules. Until TF 0.12 is released we cannot ...
6
votes
2answers
661 views

Terraform AWS AZ error - manually specify AZ?

I'm fairly new to terraform and when creating AWS infrastructure I use the following to fetch the 'available' availability zones for my region (us-east-1) where I'm trying to create an EKS cluster. ...
5
votes
3answers
563 views

Baking Immutable Images

I am working on a project and we are trying to bake immutable images on containers as IaC. These images can have J2EE, .NET or Python apps on it. All OS patches should be applied to this image ...
5
votes
1answer
5k views

How to apply using Terraform to launch multiple EC2 Resource with different configs (VPC not maintained by TF)

We are planning to use Terraform for provisioning EC2 instance which will host Oracle DB. While we are able to achieve this, there are some questions for which I am searching for suggestions / ...
5
votes
1answer
517 views

Terraform: Delay the MySQL Provider

I have a Terraform project which uses the MySQL provider. Because of the way Terraform works, the MySQL provider will fail to load correctly because the AWS_RDS instance doesn't exist. Is there a ...
5
votes
0answers
83 views

How Can I create layers for a lambda using Terraform? [closed]

The docs only seem to give me the option to reference existing layers. I want to make the layer for my lambda in my terraform code rather than through the console but can't see any option to do this ...
4
votes
1answer
225 views

difference between packer and matchbox

I have this setup to standup a baremetal machine: Terraform-> Matchbox \-> Chef-> Docker My colleague has a setup to standup VMs in AWS: Terraform-> Packer-> Chef-> ...
4
votes
1answer
2k views

create resource name based on terraform.workspace

I want to have different s3 names based on different environments using terraform. If I define the name in terraform.tfvar, it won't work: s3_bucket_name = "tf-${terraform.workspace}" If I ...
4
votes
3answers
3k views

How do I run Terraform with AWS MFA?

I'm using Terraform with the terraform-provider-aws provider to manage my AWS infrastructure. I'm trying to enable mfa_delete on an S3 bucket, but when I try to apply the change I get this error: 1 ...
4
votes
2answers
273 views

How to add ECS attributes to an instance using terraform

I heavily use ECS Attributes on our containerized infrastructure. I couldn't find terraform docs to achieve this. Do I need to execute aws cli commands manually to apply those attributes after ...
4
votes
1answer
2k views

Terraform apply exit code on error [closed]

I'm using Terraform as part of a Jenkins Pipeline. When terraform apply encounters an error, it does not return a non-zero exit code. When running into a problem on Jenkins, it does not stop the ...
4
votes
1answer
52 views

Are there automated quality checking tools for Ops code

In the dev world, we have several tools available to us for automated quality checks. We have unit tests that run on each build, Sonar to check for code quality, metrics being sent to Grafana and ...
4
votes
1answer
79 views

Where do you start with hosting the infrastructure for your infrastructure?

So I'm trying to get started with the HashiCorp stack, but the question I keep asking myself, when looking at any of this DevOps infrastructure stuff, is what infrastructure should you be using to ...
4
votes
1answer
771 views

How to provide multiple configs for EC2 node using Terraform and cloud-init?

I need to use several configs on my EC2 node using Terraform. data "template_cloudinit_config" "puppetserver_config" { gzip = true base64_encode = true part { ...
4
votes
2answers
771 views

How to `terraform destroy` an `aws_instance` without also destroying its `aws_ebs_volume` (separate resource)

$ terraform -version Terraform v0.12.21 + provider.aws v2.34.0 Given a terraform configuration for one set of single aws_instance, aws_ebs_volume and aws_volume_attachment resources, each named, say,...
4
votes
2answers
2k views

Automate Helm's tiller installation with Terraform

I need to be able to generate disposable kubernetes environments using terraform. These environments should use helm for application deployment and ideally have tiller installed during the terraform ...
4
votes
1answer
867 views

Create multiple EC2 instances using python script (in loop iteration)

I Have JSON file in which email address and count of instances are specified.I'm using python script to iterate through that file and get username/count number (count number will be used as number of ...
4
votes
1answer
956 views

Unable to launch multiple EC2 instances in different availability zones using terraform

Whenever I try to launch the instances, I am getting the following error message. Please help with this. Error: Error applying plan: 3 error(s) occurred: * aws_instance.example[0]: 1 error(s) ...
3
votes
4answers
2k views

How can I get terraforms extern to execute `ssh-keygen -y -f ~/.ssh/id_rsa`?

I seem to be confused about how external works. I tried: data "external" "local_key" { program = [ "ssh-keygen", "-y", "-f ~/.ssh/id_rsa" ] } This gives me: failed to execute "ssh-keygen":...
3
votes
2answers
3k views

Terraform get list index on for_each

Terraform newbie here. I'd like to iterate a list using for_each, but it seems like the key and value are the same: provider "aws" { profile = "default" region = "us-east-1" } variable "...
3
votes
2answers
2k views

What is the difference between modules and workspaces in Terraform

I currently use Terraform workspaces to configure different environments like dev, test, prod, and my code works fine. And I believe I can use workspaces to configure different regions as well. ...
3
votes
1answer
210 views

Terraform variable Validation

is it possible to use validation of a variable type equals list(string)? My example: main.tf name = "tf-prd-sg-foo" image_id = "ami-00e788542ee66c64f" ...
3
votes
2answers
775 views

All volumes are deleted when EC2 intance is deleted via terraform

I am using a terraform template to create AWS resources. My count is 2, everything gets created as per plan, and, I am attaching a 2nd EBS volume of 1 GB to both machines, which is also happening well....
3
votes
2answers
154 views

What is the most used tool for Cloud Infrastructure deployment Ansible vs Puppet vs Terraform?

I have some time for research at work right now, and I was thinking on expanding my knowledge on my favorite subject, which is DevOps (love you all). I have some advanced experience with Ansible, as ...
3
votes
3answers
4k views

Terraform - referencing existing security group

Is there a way I can associate existing security group to RDS that is going to be created or the only way is to recreate the security group so it can be added to the state file?
3
votes
1answer
979 views

Mount Azure FileShare using terraform

What is a good way to mount an Azure File Storage automatically during provisioning on VMs? There is a Microsoft doc describing how a file share can be mounted in general. This requires that Azure ...
3
votes
1answer
24 views

Provisioning a server on behalf of a user on GCP/AWS/Azure and probably relinquish access

I'd like to build a service where I run a custom setup script on behalf of a user on an t2.micro equivalent instance but be able to probably relinquish access to the server. Any advice on the tech ...
3
votes
1answer
1k views

How does using packer and terraform in a CD pipeline compare to docker images built from git?

At work we have a Go CD pipeline for producing docker images, and scheduling docker containers with rancher. This works quite well. You can commit a change to the Docker image in Git, the pipeline ...
3
votes
1answer
130 views

Dedicated/Separate Git Repo as Terraform Remote Backend

I see that there are multiple options for Backends, however git isn’t one of them. I believe git can be used as a backend for tfstate, in the below steps: Create a dedicated git repo Commit the ...
3
votes
1answer
134 views

Creating ec2 instances and installing mongoDB using automation

I am trying to create a 3 node MongoDB replica set using automation (ansible or terraform) in AWS. I am able to do this in the management console of AWS, but I'm not sure how to approach it. ...
3
votes
1answer
2k views

How to specify specific subnet in Terraform when using for each

I am trying to create an ec2 instance that will hold my Jenkins server. I want this to be in a private subnet which I created using a for each loop. Below is my subnet for each loop and my ec2 ...
2
votes
1answer
85 views

How do you handle the huge number of possible permutations of Dockerfiles / Teraform files?

We have adopted Docker and Terraform as the foundation forour devOps. We have a basic version of it up and running today. Dockerfiles live in each projects git repository and Terraform files are more ...
2
votes
1answer
69 views

Are manual changes to an aws IAM policy detected by Terraform plan?

I know that Terraform dose some checks before the plan and can detect some changes but not others such as detecting changes to variables on a lambda but not detecting a new secret in a secret manager. ...