terraform icon indicating copy to clipboard operation
terraform copied to clipboard

allow `-target` to accept globs

Open tamsky opened this issue 9 years ago • 56 comments

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

tamsky avatar Jun 02 '15 00:06 tamsky

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

scalp42 avatar Jun 02 '15 04:06 scalp42

Hi,

Any plans to fix this?

KZachariassen avatar Feb 20 '17 11:02 KZachariassen

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

elocnatsirt avatar Feb 23 '17 13:02 elocnatsirt

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.

joshmullis avatar Mar 20 '17 20:03 joshmullis

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

mario21ic avatar Apr 20 '17 20:04 mario21ic

Would love this feature as well !

kwent avatar Jul 29 '17 02:07 kwent

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

pkieszcz avatar Sep 12 '17 09:09 pkieszcz

++ This feature would be excellent to have

ryandeivert avatar Sep 25 '17 20:09 ryandeivert

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.

ljsommer avatar Oct 03 '17 15:10 ljsommer

I am also voting for this feature...

ezalejski avatar Oct 17 '17 17:10 ezalejski

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.

idjaw avatar Nov 11 '17 12:11 idjaw

++ would love to have this feature.

chunyong-lin avatar Mar 22 '18 20:03 chunyong-lin

this feature would make things a lot better

kcighon avatar Apr 09 '18 12:04 kcighon

+1

maxblaze avatar May 03 '18 23:05 maxblaze

+1

tolgaingenc avatar Jul 24 '18 16:07 tolgaingenc

+1

cytar avatar Aug 01 '18 12:08 cytar

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.

apparentlymart avatar Aug 01 '18 17:08 apparentlymart

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.

JnMik avatar Nov 19 '18 16:11 JnMik

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

vincentkwok avatar Jan 08 '19 02:01 vincentkwok

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.

sdickhoven avatar Jun 05 '19 22:06 sdickhoven

Second highest voted open issue and still no progress.

rightaway avatar Aug 04 '19 12:08 rightaway

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.

teamterraform avatar Aug 04 '19 16:08 teamterraform

Hi,

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

Thanks and best regards,

Josef

jomeier avatar Aug 16 '19 12:08 jomeier

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.

Samlinxia avatar Oct 29 '19 21:10 Samlinxia

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...

schneidexe avatar Dec 12 '19 21:12 schneidexe

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.

phzietsman avatar May 08 '20 08:05 phzietsman

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

alexlevinta avatar Aug 06 '20 22:08 alexlevinta

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.

lmmattr avatar Sep 02 '20 09:09 lmmattr

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.

alexlevinta avatar Sep 02 '20 18:09 alexlevinta

It would appear this is still relevant years later. Did the thumbsup to the initial issue comment.
Context: Got here looking for a better way to find terraform plan -target=module.FeatureName.aws_thing_here*.* without having to specify each target. I see there are cli workarounds, those would have to be integrated with atlantis workflows, which is possible, I'll check them out. Here's hoping regex becomes a more desirable feature. Still relevant years later. Thanks for all you do.

stacybird avatar Feb 10 '21 16:02 stacybird