1

I have deployed a project within Terraform. I need to add a 4th application module to my existing plan. How do I update my plan to include this 4th module and deploy the missing module without starting over? I thought terraform import might be an option, but I'm not understanding how it would be done.

5
  • Could you please provide more detail, what is your existing code state or how the code ( TF modules are ) is structured currently? Commented Jan 22, 2021 at 4:12
  • Why is adding a new module any different than adding a resource to an existing module? In my view, there is no difference.
    – CryptoFool
    Commented Jan 22, 2021 at 6:44
  • 1
    @KamlendraSharma I have about 8 different applications (modules) I check out from Gitlab and I'm deploying different sets of them and I want to know how do I add to my existing plan if I do a terraform plan -target=module.nifi -target=module.kafka --out test1 - After it's deployed, how do I add another module to my plan and deploy just the new module?
    – DemiSheep
    Commented Jan 24, 2021 at 21:01
  • Terraform should handle this by default as it keeps track of deployments in a state file which is stored locally or in a configured backend so all you should need to do is run terraform plan -target=module.nifi -target=module.kafka -target=module.other --out test1 and it should calculate the changes required based on the current state. Have you tried this? If so were there any specific errors? Commented Feb 3, 2021 at 11:24
  • You might want to include these modules in a top level module as using -target=module is not recommended as stated in the docs terraform.io/docs/cli/commands/plan.html#resource-targeting Commented Feb 3, 2021 at 11:43

1 Answer 1

2

Terraform is idempotent so will only change what needs to be changed.

So after applying your existing plan, if you add more modules or resources and run another plan and apply, it will add the new resources not the whole infrastructure.

Terraform import is used when you want to start managing a resource created outside your Terraform code for example created in the AWS console, AWS CLI).

It basically associates and existing resource with your new Terraform code, so that Terraform doesn't try to recreate it when you run the plan/ apply.

1
  • 1
    this should be accepted Commented Jul 13, 2021 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.