spacectl icon indicating copy to clipboard operation
spacectl copied to clipboard

[Feature Request] Implementing Target Local-Previewes

Open talqwe opened this issue 1 year ago • 4 comments

terraform plan -target=’resource’

provides a way to run plan only on specific resources

When running local-preview, the plan runs on all resources (our env has 1500 resources each) which can be very time consuming (4 envs with with 1500-2000 resources for example)

Can this be implemented with local-preview? Something like:

spacectl stack local-preview --target='resource1' --target='resource2'

talqwe avatar Sep 23 '24 14:09 talqwe

Hey, this needs investigation, however my first impression is that this is quite complicated and would require a lot of work in the backend to actually make this happen. We tend to add features to spacectl that already exist in spacelift, however this doesn't really exist, so adding this is complicated and time consuming.

tomasmik avatar Sep 23 '24 14:09 tomasmik

Hey, this needs investigation, however my first impression is that this is quite complicated and would require a lot of work in the backend to actually make this happen. We tend to add features to spacectl that already exist in spacelift, however this doesn't really exist, so adding this is complicated and time consuming.

Well, local-preview is a feature that doesn't exist in the UI of Spacelift, so adding this feature will be entirely in the spacectl scope, and won't be needed in Spacelift itself

talqwe avatar Sep 23 '24 19:09 talqwe

@talqwe that totally makes sense, however developers time is limited and the backend doesn't support picking resources before planning at least once no matter if it's a normal or a local preview run.

tomasmik avatar Sep 27 '24 11:09 tomasmik

Hey @tomasmik ! I'm also following this issue, and I'm a bit curious.. In Spacelift UI, once I trigger a run, before I confirm it, I can actually mark a subset of the resources from the plan, and then trigger a re-plan with only the selected resources (which under the hood translates to a targeted plan on terraform, I presume): image

With that in mind- is this not done via the same API that spacectl uses?

moshevayner avatar Sep 28 '24 15:09 moshevayner

With that in mind- is this not done via the same API that spacectl uses?

Hey, @moshevayner, you're correct but these runs work slightly differently. Also the request here as far as I understand is "plan specific resources only":

When running local-preview, the plan runs on all resources (our env has 1500 resources each) which can be very time consuming (4 envs with with 1500-2000 resources for example)

So using that API still forces us to plan all resources first and then replan only the selected ones (planning two times). This wouldn't save that much time. :(

tomasmik avatar Oct 11 '24 07:10 tomasmik

FWIW, a workaround that was discovered recently was to use --env-var-override the TF_CLI_ARGS_plan variable. Example:

spacectl stack local-preview --env-var-override 'TF_CLI_ARGS_plan="-target=module.some_module_name"'
# or potentially
spacectl stack local-preview --env-var-override 'TF_CLI_ARGS_plan="-target=resource.resource_name"'

jeremyhager avatar Oct 18 '24 15:10 jeremyhager

@jeremyhager Genius!! 👑

@tomasmik could we possibly add -target flag that does exactly the same? 🙏

talqwe avatar Oct 22 '24 19:10 talqwe

I'll look in to it. That's maybe a nice workaround.

tomasmik avatar Nov 11 '24 07:11 tomasmik

This is now enabled for stack local preview: https://github.com/spacelift-io/spacectl/pull/268

Please update to version 1.7.0

tomasmik avatar Nov 12 '24 13:11 tomasmik

@tomasmik

Thank you very very much, awesome work for solving a very important feature! 🔥 🥇

talqwe avatar Nov 12 '24 14:11 talqwe