diff --git a/docs/upgrading_to_v2.0.md b/docs/upgrading_to_v2.0.md index 17711e6b3..ea7bd714c 100644 --- a/docs/upgrading_to_v2.0.md +++ b/docs/upgrading_to_v2.0.md @@ -7,7 +7,7 @@ Because v2.x changed how the subnet resource is iterated on, resources in Terraf ## Migration Instructions -- Upgrade to the new version of this module. +- Upgrade to the new version of this module. if you run `terraform plan` at this point. Terraform will inform you that it will attempt to delete and recreate your existing subnets. This is almost certainly not the behavior you want. For example: diff --git a/scripts/migrate.sh b/scripts/migrate.sh index 69658434c..a36e2d8c2 100755 --- a/scripts/migrate.sh +++ b/scripts/migrate.sh @@ -1,13 +1,26 @@ #!/usr/bin/env bash +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # shellcheck shell=bash # Output Terraform Commands to migrate to new subnet config set -e set -o pipefail if [[ "$MODULE_NAME" ]]; then - NAME=$(terraform state list | grep ${MODULE_NAME}.google_compute_network.network | sed 's/.google_compute_network.network//') - for x in $(terraform state list | grep ${NAME}.google_compute_subnetwork.subnetwork); do - ID=$(terraform state show $x | grep id | grep -v ip_cidr_range | awk '{ print $3 }'| tr -d '"') + NAME=$(terraform state list | grep "${MODULE_NAME}".google_compute_network.network | sed 's/.google_compute_network.network//') + for x in $(terraform state list | grep "${NAME}".google_compute_subnetwork.subnetwork); do + ID=$(terraform state show "$x" | grep id | grep -v ip_cidr_range | awk '{ print $3 }'| tr -d '"') echo "terraform state mv $x ${NAME}.google_compute_subnetwork.subnetwork[\\\"${ID}\\\"]" done else