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

`tfctl import` command

Open chanwit opened this issue 2 years ago • 1 comments

There are many scenarios when we want to import the current tfstate of a Terraform object. Currently, importing can be done using the terraform import command together with many manual steps.

Implementing tfctl import command would simplify those steps.

Workflow:

A user issue the following command against an existing Terraform object, in this case my-aws-s3-bucket.

tfctl import -n flux-system my-aws-s3-bucket

Behavior:

  1. the command would examine tf/my-aws-s3-bucket and look for its identifier. The object's identifier is vary from resource to resource.
  2. then, the command would create a temp dir, generate a provider block, a resource block,
  3. the command would call terraform init and terraform import <resource>.this <identifyier> to import the tfstate.
  4. next, the command would gzip the terraform.tfstate file
  5. finally, the command would call kubectl to create a Secret from the gzipped tfstate file, and apply it to the cluster.

chanwit avatar Oct 16 '22 13:10 chanwit

@chanwit, is there any preferred workaround to perform import until this feature is unavailable? I appreciate any help you can provide.

gberenice avatar Sep 11 '23 14:09 gberenice