Upgrade Terraform version

If you use Homebrew on MacOS already, you can install Terraform simply by $ brew install terraform and upgrade by $ brew upgrade terraform In fact, you might be interested in letting Homebrew also control other tools: $ brew install awscli $ brew install packer $ brew cask install docker $ brew cask install virtualbox … Read more

Different environments for Terraform (Hashicorp)

I suggest you take a look at the hashicorp best-practices repo, which has quite a nice setup for dealing with different environments (similar to what James Woolfenden suggested). We’re using a similar setup, and it works quite nicely. However, this best-practices repo assumes you’re using Atlas, which we’re not. We’ve created quite an elaborate Rakefile, … Read more

Terraform – refactoring modules: Error: Provider configuration not present

As the error message explains, Terraform has detected that there are resource objects still present in the state whose provider configurations are not available, and so it doesn’t have enough information to destroy those resources. In this particular case, that seems to be occurring because there is a provider configuration block in one of your … Read more

I would like to run terraform only for a specific resource

You can use -target=resource like this: terraform plan -target=module.mymodule.aws_instance.myinstance terraform apply -target=module.mymodule.aws_instance.myinstance or terraform plan -target=aws_instance.myinstance terraform apply -target=aws_instance.myinstance Disclaimer: Before downvoting the answer, please note that he actually asked to either “exclude” or “run only ec2 resource”. And after all this time the exclude feature request is still open in the terraform repo.

Terraform: Conditional creation of a resource based on a variable in .tfvars

Add a count parameter with a ternary conditional using the variable declared in .tfvars like this: resource “cloudflare_record” “record” { count = var.cloudflare ? 1 : 0 zone_id = “${data.cloudflare_zones.domain.zones[0].id}” name = “${var.subdomain}” value = “${var.origin_server}” type = “CNAME” ttl = 1 proxied = true } In this example var.cloudflare is a boolean declared in … Read more

Should .terraform.lock.hcl be included in the .gitignore file?

Per the Terraform documentation on the Dependency Lock File: Terraform automatically creates or updates the dependency lock file each time you run the terraform init command. You should include this file in your version control repository so that you can discuss potential changes to your external dependencies via code review, just as you would discuss … Read more