github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/resource_aws_key_pair_migrate.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"strings"
     7  
     8  	"github.com/hashicorp/terraform/terraform"
     9  )
    10  
    11  func resourceAwsKeyPairMigrateState(
    12  	v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
    13  	switch v {
    14  	case 0:
    15  		log.Println("[INFO] Found AWS Key Pair State v0; migrating to v1")
    16  		return migrateKeyPairStateV0toV1(is)
    17  	default:
    18  		return is, fmt.Errorf("Unexpected schema version: %d", v)
    19  	}
    20  }
    21  
    22  func migrateKeyPairStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
    23  	if is.Empty() {
    24  		log.Println("[DEBUG] Empty InstanceState; nothing to migrate.")
    25  		return is, nil
    26  	}
    27  
    28  	log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes)
    29  
    30  	// replace public_key with a stripped version, removing `\n` from the end
    31  	// see https://github.com/hashicorp/terraform/issues/3455
    32  	is.Attributes["public_key"] = strings.TrimSpace(is.Attributes["public_key"])
    33  
    34  	log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes)
    35  	return is, nil
    36  }