mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-08 15:13:56 -06:00
4fe7ee16e6
Fixes: #13035 It was pointed out in the issue that the addition of a new parameter with a default value AND a ForceNew: true is causing Terraform to try and recreate the VPC This PR migrates the state to add the default value of false for `assign_generated_ipv6_cidr_block` ``` % make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAWSVpcMigrateState' ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2017/03/24 12:51:41 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAWSVpcMigrateState -timeout 120m === RUN TestAWSVpcMigrateState 2017/03/24 12:52:26 [INFO] Found AWS VPC State v0; migrating to v1 2017/03/24 12:52:26 [DEBUG] Attributes before migration: map[string]string{"assign_generated_ipv6_cidr_block":"true"} 2017/03/24 12:52:26 [DEBUG] Attributes after migration: map[string]string{"assign_generated_ipv6_cidr_block":"false"} 2017/03/24 12:52:26 [INFO] Found AWS VPC State v0; migrating to v1 2017/03/24 12:52:26 [DEBUG] Attributes before migration: map[string]string{} 2017/03/24 12:52:26 [DEBUG] Attributes after migration: map[string]string{"assign_generated_ipv6_cidr_block":"false"} --- PASS: TestAWSVpcMigrateState (0.00s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws 0.024s ```
34 lines
842 B
Go
34 lines
842 B
Go
package aws
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
)
|
|
|
|
func resourceAwsVpcMigrateState(
|
|
v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
|
|
switch v {
|
|
case 0:
|
|
log.Println("[INFO] Found AWS VPC State v0; migrating to v1")
|
|
return migrateVpcStateV0toV1(is)
|
|
default:
|
|
return is, fmt.Errorf("Unexpected schema version: %d", v)
|
|
}
|
|
}
|
|
|
|
func migrateVpcStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
|
|
if is.Empty() || is.Attributes == nil {
|
|
log.Println("[DEBUG] Empty VPC State; nothing to migrate.")
|
|
return is, nil
|
|
}
|
|
|
|
log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes)
|
|
|
|
is.Attributes["assign_generated_ipv6_cidr_block"] = "false"
|
|
|
|
log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes)
|
|
return is, nil
|
|
}
|