Merge pull request #3924 from TimeIncOSS/b-aws-ecs-td-computed
provider/aws: Make all fields in ecs_task_definition ForceNew
This commit is contained in:
commit
5c59bd95cb
|
@ -23,7 +23,7 @@ func TestAccAWSCodeDeployApp_basic(t *testing.T) {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSCodeDeployAppModifier,
|
Config: testAccAWSCodeDeployAppModified,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
|
testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
|
||||||
),
|
),
|
||||||
|
@ -72,7 +72,7 @@ resource "aws_codedeploy_app" "foo" {
|
||||||
name = "foo"
|
name = "foo"
|
||||||
}`
|
}`
|
||||||
|
|
||||||
var testAccAWSCodeDeployAppModifier = `
|
var testAccAWSCodeDeployAppModified = `
|
||||||
resource "aws_codedeploy_app" "foo" {
|
resource "aws_codedeploy_app" "foo" {
|
||||||
name = "bar"
|
name = "bar"
|
||||||
}`
|
}`
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestAccAWSCodeDeployDeploymentGroup_basic(t *testing.T) {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSCodeDeployDeploymentGroupModifier,
|
Config: testAccAWSCodeDeployDeploymentGroupModified,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo"),
|
testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo"),
|
||||||
),
|
),
|
||||||
|
@ -133,7 +133,7 @@ resource "aws_codedeploy_deployment_group" "foo" {
|
||||||
}
|
}
|
||||||
}`
|
}`
|
||||||
|
|
||||||
var testAccAWSCodeDeployDeploymentGroupModifier = `
|
var testAccAWSCodeDeployDeploymentGroupModified = `
|
||||||
resource "aws_codedeploy_app" "foo_app" {
|
resource "aws_codedeploy_app" "foo_app" {
|
||||||
name = "foo_app"
|
name = "foo_app"
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
|
||||||
return &schema.Resource{
|
return &schema.Resource{
|
||||||
Create: resourceAwsEcsTaskDefinitionCreate,
|
Create: resourceAwsEcsTaskDefinitionCreate,
|
||||||
Read: resourceAwsEcsTaskDefinitionRead,
|
Read: resourceAwsEcsTaskDefinitionRead,
|
||||||
Update: resourceAwsEcsTaskDefinitionUpdate,
|
|
||||||
Delete: resourceAwsEcsTaskDefinitionDelete,
|
Delete: resourceAwsEcsTaskDefinitionDelete,
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
|
@ -40,6 +39,7 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
|
||||||
"container_definitions": &schema.Schema{
|
"container_definitions": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
|
ForceNew: true,
|
||||||
StateFunc: func(v interface{}) string {
|
StateFunc: func(v interface{}) string {
|
||||||
hash := sha1.Sum([]byte(v.(string)))
|
hash := sha1.Sum([]byte(v.(string)))
|
||||||
return hex.EncodeToString(hash[:])
|
return hex.EncodeToString(hash[:])
|
||||||
|
@ -49,6 +49,7 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
|
||||||
"volume": &schema.Schema{
|
"volume": &schema.Schema{
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
Elem: &schema.Resource{
|
Elem: &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"name": &schema.Schema{
|
"name": &schema.Schema{
|
||||||
|
@ -131,29 +132,6 @@ func resourceAwsEcsTaskDefinitionRead(d *schema.ResourceData, meta interface{})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAwsEcsTaskDefinitionUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
||||||
oldArn := d.Get("arn").(string)
|
|
||||||
|
|
||||||
log.Printf("[DEBUG] Creating new revision of task definition %q", d.Id())
|
|
||||||
err := resourceAwsEcsTaskDefinitionCreate(d, meta)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log.Printf("[DEBUG] New revision of %q created: %q", d.Id(), d.Get("arn").(string))
|
|
||||||
|
|
||||||
log.Printf("[DEBUG] Deregistering old revision of task definition %q: %q", d.Id(), oldArn)
|
|
||||||
conn := meta.(*AWSClient).ecsconn
|
|
||||||
_, err = conn.DeregisterTaskDefinition(&ecs.DeregisterTaskDefinitionInput{
|
|
||||||
TaskDefinition: aws.String(oldArn),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
log.Printf("[DEBUG] Old revision of task definition deregistered: %q", oldArn)
|
|
||||||
|
|
||||||
return resourceAwsEcsTaskDefinitionRead(d, meta)
|
|
||||||
}
|
|
||||||
|
|
||||||
func resourceAwsEcsTaskDefinitionDelete(d *schema.ResourceData, meta interface{}) error {
|
func resourceAwsEcsTaskDefinitionDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
conn := meta.(*AWSClient).ecsconn
|
conn := meta.(*AWSClient).ecsconn
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestAccAWSEcsTaskDefinition_basic(t *testing.T) {
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAWSEcsTaskDefinitionModifier,
|
Config: testAccAWSEcsTaskDefinitionModified,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.jenkins"),
|
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.jenkins"),
|
||||||
),
|
),
|
||||||
|
@ -49,6 +49,31 @@ func TestAccAWSEcsTaskDefinition_withScratchVolume(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regression for https://github.com/hashicorp/terraform/issues/2694
|
||||||
|
func TestAccAWSEcsTaskDefinition_withEcsService(t *testing.T) {
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSEcsTaskDefinitionWithEcsService,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep"),
|
||||||
|
testAccCheckAWSEcsServiceExists("aws_ecs_service.sleep-svc"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccAWSEcsTaskDefinitionWithEcsServiceModified,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep"),
|
||||||
|
testAccCheckAWSEcsServiceExists("aws_ecs_service.sleep-svc"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckAWSEcsTaskDefinitionDestroy(s *terraform.State) error {
|
func testAccCheckAWSEcsTaskDefinitionDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).ecsconn
|
conn := testAccProvider.Meta().(*AWSClient).ecsconn
|
||||||
|
|
||||||
|
@ -155,7 +180,72 @@ TASK_DEFINITION
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
var testAccAWSEcsTaskDefinitionModifier = `
|
var testAccAWSEcsTaskDefinitionWithEcsService = `
|
||||||
|
resource "aws_ecs_cluster" "default" {
|
||||||
|
name = "terraform-acc-test"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_ecs_service" "sleep-svc" {
|
||||||
|
name = "tf-acc-ecs-svc"
|
||||||
|
cluster = "${aws_ecs_cluster.default.id}"
|
||||||
|
task_definition = "${aws_ecs_task_definition.sleep.arn}"
|
||||||
|
desired_count = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_ecs_task_definition" "sleep" {
|
||||||
|
family = "terraform-acc-sc-volume-test"
|
||||||
|
container_definitions = <<TASK_DEFINITION
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "sleep",
|
||||||
|
"image": "busybox",
|
||||||
|
"cpu": 10,
|
||||||
|
"command": ["sleep","360"],
|
||||||
|
"memory": 10,
|
||||||
|
"essential": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
TASK_DEFINITION
|
||||||
|
|
||||||
|
volume {
|
||||||
|
name = "database_scratch"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
var testAccAWSEcsTaskDefinitionWithEcsServiceModified = `
|
||||||
|
resource "aws_ecs_cluster" "default" {
|
||||||
|
name = "terraform-acc-test"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_ecs_service" "sleep-svc" {
|
||||||
|
name = "tf-acc-ecs-svc"
|
||||||
|
cluster = "${aws_ecs_cluster.default.id}"
|
||||||
|
task_definition = "${aws_ecs_task_definition.sleep.arn}"
|
||||||
|
desired_count = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_ecs_task_definition" "sleep" {
|
||||||
|
family = "terraform-acc-sc-volume-test"
|
||||||
|
container_definitions = <<TASK_DEFINITION
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "sleep",
|
||||||
|
"image": "busybox",
|
||||||
|
"cpu": 20,
|
||||||
|
"command": ["sleep","360"],
|
||||||
|
"memory": 50,
|
||||||
|
"essential": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
TASK_DEFINITION
|
||||||
|
|
||||||
|
volume {
|
||||||
|
name = "database_scratch"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
var testAccAWSEcsTaskDefinitionModified = `
|
||||||
resource "aws_ecs_task_definition" "jenkins" {
|
resource "aws_ecs_task_definition" "jenkins" {
|
||||||
family = "terraform-acc-test"
|
family = "terraform-acc-test"
|
||||||
container_definitions = <<TASK_DEFINITION
|
container_definitions = <<TASK_DEFINITION
|
||||||
|
|
Loading…
Reference in New Issue