forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_aws_ecs_task_definition_migrate.go
44 lines (35 loc) · 1.17 KB
/
resource_aws_ecs_task_definition_migrate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package aws
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/private/protocol/json/jsonutil"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/hashicorp/terraform/terraform"
)
func resourceAwsEcsTaskDefinitionMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
conn := meta.(*AWSClient).ecsconn
switch v {
case 0:
log.Println("[INFO] Found AWS ECS Task Definition State v0; migrating to v1")
return migrateEcsTaskDefinitionStateV0toV1(is, conn)
default:
return is, fmt.Errorf("Unexpected schema version: %d", v)
}
}
func migrateEcsTaskDefinitionStateV0toV1(is *terraform.InstanceState, conn *ecs.ECS) (*terraform.InstanceState, error) {
arn := is.Attributes["arn"]
// We need to pull definitions from the API b/c they're unrecoverable from the checksum
td, err := conn.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
TaskDefinition: aws.String(arn),
})
if err != nil {
return nil, err
}
b, err := jsonutil.BuildJSON(td.TaskDefinition.ContainerDefinitions)
if err != nil {
return nil, err
}
is.Attributes["container_definitions"] = string(b)
return is, nil
}