Terraform: allow `-target` to accept globs

Created on 2 Jun 2015  路  29Comments  路  Source: hashicorp/terraform

Suppose one declares several concurrent environments in a single tf config.

To limit cli actions to a single environment at a time, it would be convenient if a way existed, via -target to glob-match modules, module_paths, resource_types and resource_names:

terraform apply -target=aws*.staging* # target aws* resource_types

or similarly, for all modules:

terraform apply -target=*.*.staging* # target all modules and resource_types

or similarly, for all module_paths:

terraform apply -target=**.staging* # star star = target all modules and submodules

cli core enhancement

Most helpful comment

Please do not post "+1" comments here, since it creates noise for others watching the issue and ultimately doesn't influence our prioritization because we can't actually report on these. Instead, react to the original issue comment with :+1:, which we _can_ and _do_ report on.

All 29 comments

:+1: would love to be able to use as opposed to writing CLIs to wrap Terraform

Hi,

Any plans to fix this?

Was just wondering if this is possible. Would be a very useful feature!

There are other requests I've seen for "exclude" logic, so it may be useful to have this use regex instead of glob to take care of both requests.

Where is the issue for "exclude" logic? that it'll resolve me many problems :+1:, maybe like target:
$ terraform plan -exclude=mymodule.resource_not_important

Would love this feature as well !

Just hit it today... Would love this feature times 1000s

++ This feature would be excellent to have

Wow this is a very old request for a very useful feature.
Great idea, our use case would be to use target to specify the creation of template resources to create fully populated python files for Lambdas which have interpolated their vars from terraform so that we can do local unit and lint testing before interacting with the AWS API.

I am also voting for this feature...

Would it be correct to relate with Issue #2253

The feature request is for a different option parameter, but the nature of the feature to have an "exclude" pattern instead of just "apply" could be interesting.

Considering they are both trying to achieve somewhat similar results. By supporting also the exclude and this pattern feature, it would make it that much more flexible and powerful.

++ would love to have this feature.

this feature would make things a lot better

+1

+1

+1

Please do not post "+1" comments here, since it creates noise for others watching the issue and ultimately doesn't influence our prioritization because we can't actually report on these. Instead, react to the original issue comment with :+1:, which we _can_ and _do_ report on.

Not only the option target, the "Data" ressource block as well should be able to target a ressource name="prefix-*". Ressources often needs to have dynamic name to be able to spawn in parallel to have zero downtime with lifecycle "create_before_destroy", it makes them pretty hard to target sometimes.

Any schedule on this feature? It helps on managing multiple modules. E.g. modify resources under specific module instead of all resources among modules

we are managing 700+ domains (plus records) with terraform in cloudflare. our resource naming is perfect for prefix wildcarding (if that's easier to implement than full-on globbing):

terraform apply -target=cloudflare_record.my_domain_com__*

some zones have hundreds of records so it would be incredibly tedious to list them all as targets. but all the records are prefixed with the zone name.

so definitely :+1: on this feature.

Second highest voted open issue and still no progress.

Please do not post "+1" comments here, since it creates noise for others watching the issue and ultimately doesn't influence our prioritization because we can't actually report on these. Instead, react to the original issue comment with +1, which we _can_ and _do_ report on.

Hi,

this request is almost four years old and seems to be rather important. Any progress on that?

Thanks and best regards,

Josef

Any updates for this feature? We use terraform to manage our Kafka Topics. This feature is will be really useful for us to automate manage our topics since our topics are prefixed by a common cluster name. This wildcard or RegEx match enable us to only apply to a subset of topics that need to update.

As a workaround I came up with https://github.com/schneidexe/tfp. Yet, it's a kinda low-tech solution that might not cover all cases ... ;) But maybe it's helpful...

Also ended up making a little cli app to help with this. https://github.com/phzietsman/tft/releases.

terraform plan | tft -pattern=aws_s3_bucket -mode=include

Its crude, but it works.

still waiting for this feature years later, either wildcarding or exclude would work

Returning to this after a while, would being able to "Tag" or group resources be another way to help? I'm thinking of building a canary group for deployments but to make deploying this easier you could prefix all the resources in a canary group with a common name that can then be targeted.

The same could be achieved with a grouping convention. This could help with any staged deployments as you could deploy certain artifacts in groups with manual triggers between them.

Returning to this after a while, would being able to "Tag" or group resources be another way to help? I'm thinking of building a canary group for deployments but to make deploying this easier you could prefix all the resources in a canary group with a common name that can then be targeted.

The same could be achieved with a grouping convention. This could help with any staged deployments as you could deploy certain artifacts in groups with manual triggers between them.

It would work for groupings that you define ahead of time, but we generally face this issue when something needs to be changed on some long list of production hosts but not on others. The tagging would resolve staged deployments or groupings that you know before running into issues. The regex target and exclusion would help in many more cases.

Was this page helpful?
0 / 5 - 0 ratings