tofu-controller icon indicating copy to clipboard operation
tofu-controller copied to clipboard

Add support for terraform targets

Open wpbeckwith opened this issue 1 year ago • 4 comments

I would like to see support for adding terraform targets. I imagine something like

apiVersion: infra.contrib.fluxcd.io/v1alpha1
kind: Terraform
metadata:
  name: vpc
  namespace: flux-system
spec:
  ...
  path: ./terraform/test/us-west-2/dev/vpc
  targets:
  - module.dev_vpc
  varsFrom:
  - kind: Secret
    name: aws-credentials
  ...

When initially creating the infrastructure we would have the targets section commented out. But afterwards we would want to restrict terraform to a set of targets. This will allows us to do creates and deletes of VPCs and clusters without losing the EIPs in the original tf config. While we can add lifecycle blocks to the EIPs, this prevents the entire tf config from being destroyed as terraform will error out about the EIPs and their prevent deletion lifecycles.

wpbeckwith avatar Jul 21 '22 20:07 wpbeckwith

Thank you @wpbeckwith This is a great feature request!

I'll be looking at the tfexec library we're using to see if it supports passing this target set.

chanwit avatar Jul 22 '22 14:07 chanwit

It does, https://github.com/hashicorp/terraform-exec/blob/495b9eb3d2cd9daebea6191f5329430ea0a72867/tfexec/plan.go#L21

wpbeckwith avatar Jul 22 '22 17:07 wpbeckwith

@chanwit if help is wanted, I can create a PR for this feature.

akselleirv avatar Aug 15 '22 12:08 akselleirv

@akselleirv that would be fantastic. thank you so much!

chanwit avatar Aug 15 '22 12:08 chanwit