60
votes
Accepted
Terraform: apply only one tf file
Not really. The standard way to work around this though is to use eg:
terraform apply -target=aws_security_group.my_sg
but that's only going to apply one security group at a time, so will get tedious ...
50
votes
How to use terraform import with module
The terraform import command uses the "Resource Address" syntax, which is a way to talk about objects in a configuration from outside of that configuration. (This is as opposed to references ...
30
votes
Accepted
How can I manage secrets in .tf and .tfstate?
Terraform supports adding an additional file with variables during invocation.
documentation: https://www.terraform.io/intro/getting-started/variables.html#from-a-file
We are using that feature to ...
26
votes
Accepted
Terraform apply output only
Running terraform apply -refresh-only should take care of any new outputs. It will read the latest data from each resource and then update all of the outputs in terms of those updates, which includes ...
25
votes
Accepted
How to use cloud-init with Terraform?
Cloud-init files are essentially bootstrap codes, that run before each startup, and can - among others - modify files, set up services, create users, etc.
Not all types of droplets support all ...
24
votes
Accepted
How to test a Terraform Configuration?
There is currently no full solution to this integrated into Terraform, but there are some building blocks that could be useful to assist in writing tests in a separate programming language.
Terraform ...
19
votes
Accepted
How to support releasing new versions of the code, running in parallel with the last stable release?
There are a few different ways to achieve goals of this sort, each with some different tradeoffs. I'm going to describe the most common ones below.
The simplest approach is to use Terraform's ...
17
votes
How to test a Terraform Configuration?
We recently open sourced Terratest, our swiss army knife for testing infrastructure code.
Today, you're probably testing all your infrastructure code manually by deploying, validating, and ...
15
votes
Terraform: apply only one tf file
If you organize your code by modules, you could apply terraform only on a module, eg :
# securitygroup.tf
module "securitygroup" {
source = "[email protected]:user/securitygroup-terraform-module.git?...
13
votes
How to test a Terraform Configuration?
As an update to this question, there is now Kitchen-Terraform which allows the testing of Terraform Configuration files without breaking production environments. The repository also includes a few ...
13
votes
Is there a way to lint Terraform?
terraform fmt
The terraform fmt command is used to rewrite Terraform configuration files to a canonical format and style.
11
votes
How can I manage secrets in .tf and .tfstate?
If you're on AWS, then have a look at "The Right Way to Manage Secrets" by Segment.io on the AWS Blog. We advocate using chamber to all of our customers for managing secrets. It works by leveraging ...
10
votes
Accepted
How can I manage changes in desired capacity due to scaling policies in AutoScaling Group state?
The desired_capacity in Terraform is marked in the documentation as optional. So with a proper min_size value, Terraform can wait until the minimum capacity is reached before continuing.
The above, ...
10
votes
Accepted
How do I detach an existing volume and attach a new volume with Terraform?
The old volume is never detached because skip_destroy = true. From the terraform docs:
skip_destroy - (Optional, Boolean) Set this to true if you do not wish to detach the volume from the instance ...
10
votes
Accepted
Get private key from terraform state?
If you need to use a value like this private key for later steps, the common answer is to return it as a root module output value. Since the private key is sensitive, you can mark it as such to ...
9
votes
Accepted
Terraform: Is there a concise syntax for specifying multiple tags for a resource?
For an auto-scaling-group this is the most concise syntax available.
For most other resources you use the tags syntax which looks like:
tags {
Key1 = "value1"
Key2 = "value2"
}
9
votes
Accepted
How can I keep track of my Cloud Resource use?
A judicious usage of one of the cloud "orchestration" tools, such as Terraform or possibly Fugue seems to be the best way.
You can start small, pick a less important and not very extensive ...
9
votes
Accepted
Getting "(sensitive value)" from `terraform state show`, how can I uncensor the value?
Unfortunately you can not. There is already a filed issue on this #32439.
Workaround
Until that's resolved you'll have to use
terraform show -json | jq QUERY
And learn how to query with jq to get ...
8
votes
How can I manage secrets in .tf and .tfstate?
We avoid terraform handle our secrets. Even if you manage to inject secrets by a var file "secrtes.tfvars" as pointed out above, these secrets will be stored in your terraform (remote-)state.
You can ...
8
votes
Does terraform support blue green deployments and roll backs out of the box
It all depends on how you are deploying your code.
(First, IMHO, I don't think that Terraform is the right hammer for this operation. Terraform responsibility is to build the necessary infrastructure ...
8
votes
How to use terraform import with module
Run terraform plan first and use the names in the output.
Goal here is to import in the resources that are listed in the plan output so next time you run plan they won't be listed for add.
So ...
7
votes
How to test a Terraform Configuration?
In addition to all the other options mentioned, I would like to mention that InSpec 2.0 added support for cloud provider APIs. Basically, you can continue writing the IaC with Terraform, then write ...
7
votes
How to make Terraform Modules wait for resources to be created in place of using computed values
Update: As of TF 0.13x, depends_on is supported to create dependencies between modules. Using depends_on should be preferable over using the method detailed below.
The previous most popular answer is ...
7
votes
Are multiline lists valid in Terraform?
Yes. According to Types and Values: Lists/Tuples
List literals can be split into multiple lines for readability, but always require a comma between values. A comma after the final value is allowed, ...
6
votes
How to use cloud-init with Terraform?
When you create an Auto Scaling group with Terraform, you can specify the user_data to be used by instances created by this ASG. Documented here - https://www.terraform.io/docs/providers/aws/r/...
6
votes
Baking Immutable Images
An idea key to your question is that of immutable infrastructure, which is the idea that an image is built once, deployed many times, and never changed at runtime. If the contents of the image need to ...
6
votes
Terraform: Is there a concise syntax for specifying multiple tags for a resource?
Terraform v0.12 added support for Dynamic Nested Blocks. The following example is derived from their blog post about the new features (see section Dynamic Nested Blocks):
locals {
standard_tags = {
...
6
votes
Accepted
How to apply using Terraform to launch multiple EC2 Resource with different configs (VPC not maintained by TF)
You can use a remote backend as a data source. That is working well for us thus far but this project is not very mature and we will likely refactor a time or ten.
data "terraform_remote_state" "...
6
votes
Accepted
How should we automatically rebuild immutable infrastructure when new packages are available?
Part of adopting the Immutable Infrastructure Pattern is decomposing your system into small manageable pieces that can move through CI/CD Pipeline very quickly, this means that OS patches can be done ...
6
votes
How can I get terraforms extern to execute `ssh-keygen -y -f ~/.ssh/id_rsa`?
So what happens in first case is, as Dan's already said, there's no shell used and as such nothing to expand the ~. Quoting the documentation about program:
Terraform does not execute the program ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
terraform × 309amazon-web-services × 87
terraform-module × 31
azure × 24
amazon-ec2 × 22
kubernetes × 17
ansible × 15
infrastructure-as-code × 14
cloud-init × 14
docker × 13
openstack × 10
terraform-workspace × 10
amazon-s3 × 8
google-cloud-platform × 7
packer × 7
aws-vpc × 7
spacelift × 7
gitlab × 6
automation × 6
eks × 6
jenkins × 5
continuous-integration × 5
azure-devops × 5
helm × 5
aws-lambda × 5