Skip to content

Instantly share code, notes, and snippets.

@Yamini-crypto
Created January 19, 2024 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yamini-crypto/75c58c69980a3b92cead6684ccbaeb78 to your computer and use it in GitHub Desktop.
Save Yamini-crypto/75c58c69980a3b92cead6684ccbaeb78 to your computer and use it in GitHub Desktop.
terraform refresh
# setting variables for auto scaling groups and policies location in state file
asg_location=module.asg.aws_autoscaling_group.id[0]
# checking the status of asgs in terraform state if there are changes then the new asg will be imported in place of that
# importing the updates in asg
terraform state show $asg_location | grep $(terraform output -raw asg_name) > /dev/null 2>&1
if [ $? != 0 ]
then
terraform state rm $asg_location
terraform import $asg_location $(terraform output -raw asg_name)
terraform refresh
terraform state rm 'module.asg.aws_autoscaling_policy.this["dynamic_TTS_policy"]'
terraform import 'module.asg.aws_autoscaling_policy.this["dynamic_TTS_policy"]' $(terraform output -raw asg_name)/dynamic_TTS_policy
echo "updated asg"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment