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

How to for_each through a list(objects) in Terraform 0.12

Seem’s like I found what to do. If you pass not the maps of maps but the list of maps you can use such code resource “google_compute_instance” “node” { for_each = {for vm in var.vms: vm.hostname => vm} name = “${each.value.hostname}” machine_type = “custom-${each.value.cpu}-${each.value.ram*1024}” zone = “${var.gcp_zone}” boot_disk { initialize_params { image = “${var.image_name}” size … Read more