Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Terraform: run code after resources is created using using remote-exec provisioners

The chef, file, local-exec, puppet, remote-exec, provisioner invokes a script on a remote resource only after it is created. Thus, if you add provisioner code after “terraform apply”, it would not considers as a changes and terraform would flag no resources addition and change.

Thus, How to apply a provisioners changes in resources created. There are 2 method to apply provisioners even after “terraform apply”.

Adding provisioner sections to an existing (already provisioned) aws_instance is not something that terraform notices as a ‘change’, so the provisioner is not run during the next apply. The only way to run the provisioner is to destroy the instance and let terraform create it again.

Method 1 – Destroy and Recreate

Adding provisioner sections to an existing (already provisioned) aws_instance is not something that terraform notices as a ‘change’, so the provisioner is not run during the next apply. The only way to run the provisioner is to destroy the instance and let terraform create it again.

Method 2 – Using null_resource

The solution is to create a resource “null_resource” “nameYouWant” { } and then run your commands inside that. They will run after the initial resources are created: