github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/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  	return is, nil
    22  }
    23  
    24  func migrateKeyPairStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
    25  	if is.Empty() {
    26  		log.Println("[DEBUG] Empty InstanceState; nothing to migrate.")
    27  		return is, nil
    28  	}
    29  
    30  	log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes)
    31  
    32  	// replace public_key with a stripped version, removing `\n` from the end
    33  	// see https://github.com/hashicorp/terraform/issues/3455
    34  	is.Attributes["public_key"] = strings.TrimSpace(is.Attributes["public_key"])
    35  
    36  	log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes)
    37  	return is, nil
    38  }