Created
July 2, 2020 15:08
-
-
Save anilshrish/0eeda4bd3d3620a78dc50b89d6d20640 to your computer and use it in GitHub Desktop.
terraform duplicate the infrastructure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | |
alias gsed=sed | |
fi | |
NEW_PATTERN="_v2" | |
# find . -type f -exec gsed -i '/^data /s/" {/_v2" {/' {} + | |
# find . -type f -exec gsed -i '/^resource /s/" {/_v2" {/' {} + | |
find . -type f -exec gsed -i "/^data /s/\" {/${NEW_PATTERN}\" {/" {} + | |
find . -type f -exec gsed -i "/^resource /s/\" {/${NEW_PATTERN}\" {/" {} + | |
# grep -arin "^data " circleci.tf | grep -o '".*"' | gsed 's/"//g' | gsed 's/ /./' | | |
# grep -arin "^resource " circleci.tf | grep -o '".*"' | gsed 's/"//g' | gsed 's/ /./' | | |
# grep -arin "^data " * | grep -o '".*"' | gsed 's/"//g' | gsed 's/ /./' | xargs -L 1 -I% find . -type f -exec gsed "s/${%}/${%}${NEW_PATTERN}/" {} \; | |
# grep -arin "^data " * | grep -o '".*"' | gsed 's/"//g' | gsed 's/ /./' | xargs -L 1 -I% echo "this %" | |
# grep -arin "^data " * | grep -o '".*"' | gsed 's/"//g' | gsed 's/ /./' | xargs -I {} sh -c 'echo "$1"' sh {} | |
grep -ari "^data " * | awk -F':data|{' -v OFS='"' '{print $1, $2}' | gsed 's/^/"/' | grep -o '".*"' | gsed 's/"//g' | awk '{print $2 "." $3, $1}' | |
grep -ari "^resource " * | awk -F':resource|{' -v OFS='"' '{print $1, $2}' | gsed 's/^/"/' | grep -o '".*"' | gsed 's/"//g' | awk '{print $2 "." $3, $1}' | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_subnet.subnet/aws_subnet.subnet_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/template_file.services_user_data/template_file.services_user_data_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/template_file.circleci_policy/template_file.circleci_policy_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/template_file.output/template_file.output_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/template_file.nomad_user_data/template_file.nomad_user_data_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/template_file.mod/template_file.mod_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_s3_bucket.circleci_bucket/aws_s3_bucket.circleci_bucket_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_iam_role.circleci_role/aws_iam_role.circleci_role_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_iam_role_policy.circleci_policy/aws_iam_role_policy.circleci_policy_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_iam_instance_profile.circleci_profile/aws_iam_instance_profile.circleci_profile_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_security_group.circleci_builders_sg/aws_security_group.circleci_builders_sg_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_security_group.circleci_services_sg/aws_security_group.circleci_services_sg_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_security_group.circleci_builders_admin_sg/aws_security_group.circleci_builders_admin_sg_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_security_group.circleci_users_sg/aws_security_group.circleci_users_sg_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_security_group.circleci_vm_sg/aws_security_group.circleci_vm_sg_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_instance.services/aws_instance.services_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_route53_record.services_route/aws_route53_record.services_route_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_launch_configuration.mod_lc/aws_launch_configuration.mod_lc_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_autoscaling_group.mod_asg/aws_autoscaling_group.mod_asg_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_autoscaling_lifecycle_hook.mod_shutdown_hook/aws_autoscaling_lifecycle_hook.mod_shutdown_hook_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_security_group.nomad_sg/aws_security_group.nomad_sg_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_security_group.ssh_sg/aws_security_group.ssh_sg_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_launch_configuration.clients_lc/aws_launch_configuration.clients_lc_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_autoscaling_group.clients_asg/aws_autoscaling_group.clients_asg_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_sqs_queue.mod_queue/aws_sqs_queue.mod_queue_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_iam_role.mod_role/aws_iam_role.mod_role_v2/g" {} + ; | |
# find . -type f -name "*.tf" -exec gsed -i "s/aws_iam_role_policy.mod_role_policy/aws_iam_role_policy.mod_role_policy_v2/g" {} + ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment