github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/aws/resource_aws_kinesis_firehose_delivery_stream_migrate.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  
     7  	"github.com/hashicorp/terraform/terraform"
     8  )
     9  
    10  func resourceAwsKinesisFirehoseMigrateState(
    11  	v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
    12  	switch v {
    13  	case 0:
    14  		log.Println("[INFO] Found AWS Kinesis Firehose Delivery Stream State v0; migrating to v1")
    15  		return migrateKinesisFirehoseV0toV1(is)
    16  	default:
    17  		return is, fmt.Errorf("Unexpected schema version: %d", v)
    18  	}
    19  }
    20  
    21  func migrateKinesisFirehoseV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
    22  	if is.Empty() {
    23  		log.Println("[DEBUG] Empty Kinesis Firehose Delivery State; nothing to migrate.")
    24  		return is, nil
    25  	}
    26  
    27  	log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes)
    28  
    29  	// migrate flate S3 configuration to a s3_configuration block
    30  	// grab initial values
    31  	is.Attributes["s3_configuration.#"] = "1"
    32  	// Required parameters
    33  	is.Attributes["s3_configuration.0.role_arn"] = is.Attributes["role_arn"]
    34  	is.Attributes["s3_configuration.0.bucket_arn"] = is.Attributes["s3_bucket_arn"]
    35  
    36  	// Optional parameters
    37  	if is.Attributes["s3_buffer_size"] != "" {
    38  		is.Attributes["s3_configuration.0.buffer_size"] = is.Attributes["s3_buffer_size"]
    39  	}
    40  	if is.Attributes["s3_data_compression"] != "" {
    41  		is.Attributes["s3_configuration.0.compression_format"] = is.Attributes["s3_data_compression"]
    42  	}
    43  	if is.Attributes["s3_buffer_interval"] != "" {
    44  		is.Attributes["s3_configuration.0.buffer_interval"] = is.Attributes["s3_buffer_interval"]
    45  	}
    46  	if is.Attributes["s3_prefix"] != "" {
    47  		is.Attributes["s3_configuration.0.prefix"] = is.Attributes["s3_prefix"]
    48  	}
    49  
    50  	delete(is.Attributes, "role_arn")
    51  	delete(is.Attributes, "s3_bucket_arn")
    52  	delete(is.Attributes, "s3_buffer_size")
    53  	delete(is.Attributes, "s3_data_compression")
    54  	delete(is.Attributes, "s3_buffer_interval")
    55  	delete(is.Attributes, "s3_prefix")
    56  
    57  	log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes)
    58  	return is, nil
    59  }