provider/aws: Added migration for `tier` attribute in aws_elastic_beanstalk_environment resource. (#6167)
Fixes #6164.
This commit is contained in:
parent
fcea17e9ed
commit
b78f4c1114
|
@ -43,6 +43,9 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource {
|
||||||
Update: resourceAwsElasticBeanstalkEnvironmentUpdate,
|
Update: resourceAwsElasticBeanstalkEnvironmentUpdate,
|
||||||
Delete: resourceAwsElasticBeanstalkEnvironmentDelete,
|
Delete: resourceAwsElasticBeanstalkEnvironmentDelete,
|
||||||
|
|
||||||
|
SchemaVersion: 1,
|
||||||
|
MigrateState: resourceAwsElasticBeanstalkEnvironmentMigrateState,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package aws
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
)
|
||||||
|
|
||||||
|
func resourceAwsElasticBeanstalkEnvironmentMigrateState(
|
||||||
|
v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
|
||||||
|
switch v {
|
||||||
|
case 0:
|
||||||
|
log.Println("[INFO] Found AWS Elastic Beanstalk Environment State v0; migrating to v1")
|
||||||
|
return migrateBeanstalkEnvironmentStateV0toV1(is)
|
||||||
|
default:
|
||||||
|
return is, fmt.Errorf("Unexpected schema version: %d", v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func migrateBeanstalkEnvironmentStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
|
||||||
|
if is.Empty() || is.Attributes == nil {
|
||||||
|
log.Println("[DEBUG] Empty Elastic Beanstalk Environment State; nothing to migrate.")
|
||||||
|
return is, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] Attributes before migration: %#v", is.Attributes)
|
||||||
|
|
||||||
|
if is.Attributes["tier"] == "" {
|
||||||
|
is.Attributes["tier"] = "WebServer"
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("[DEBUG] Attributes after migration: %#v", is.Attributes)
|
||||||
|
return is, nil
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package aws
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAWSElasticBeanstalkEnvironmentMigrateState(t *testing.T) {
|
||||||
|
cases := map[string]struct {
|
||||||
|
StateVersion int
|
||||||
|
Attributes map[string]string
|
||||||
|
Expected map[string]string
|
||||||
|
Meta interface{}
|
||||||
|
}{
|
||||||
|
"v0_1_web": {
|
||||||
|
StateVersion: 0,
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"tier": "",
|
||||||
|
},
|
||||||
|
Expected: map[string]string{
|
||||||
|
"tier": "WebServer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"v0_1_web_explicit": {
|
||||||
|
StateVersion: 0,
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"tier": "WebServer",
|
||||||
|
},
|
||||||
|
Expected: map[string]string{
|
||||||
|
"tier": "WebServer",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"v0_1_worker": {
|
||||||
|
StateVersion: 0,
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"tier": "Worker",
|
||||||
|
},
|
||||||
|
Expected: map[string]string{
|
||||||
|
"tier": "Worker",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for tn, tc := range cases {
|
||||||
|
is := &terraform.InstanceState{
|
||||||
|
ID: "e-abcde12345",
|
||||||
|
Attributes: tc.Attributes,
|
||||||
|
}
|
||||||
|
is, err := resourceAwsElasticBeanstalkEnvironmentMigrateState(
|
||||||
|
tc.StateVersion, is, tc.Meta)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("bad: %s, err: %#v", tn, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue