Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Make all fields in ecs_task_definition ForceNew #3924

Merged
merged 3 commits into from
Nov 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions builtin/providers/aws/resource_aws_codedeploy_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAccAWSCodeDeployApp_basic(t *testing.T) {
),
},
resource.TestStep{
Config: testAccAWSCodeDeployAppModifier,
Config: testAccAWSCodeDeployAppModified,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
),
Expand Down Expand Up @@ -72,7 +72,7 @@ resource "aws_codedeploy_app" "foo" {
name = "foo"
}`

var testAccAWSCodeDeployAppModifier = `
var testAccAWSCodeDeployAppModified = `
resource "aws_codedeploy_app" "foo" {
name = "bar"
}`
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAccAWSCodeDeployDeploymentGroup_basic(t *testing.T) {
),
},
resource.TestStep{
Config: testAccAWSCodeDeployDeploymentGroupModifier,
Config: testAccAWSCodeDeployDeploymentGroupModified,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeDeployDeploymentGroupExists("aws_codedeploy_deployment_group.foo"),
),
Expand Down Expand Up @@ -133,7 +133,7 @@ resource "aws_codedeploy_deployment_group" "foo" {
}
}`

var testAccAWSCodeDeployDeploymentGroupModifier = `
var testAccAWSCodeDeployDeploymentGroupModified = `
resource "aws_codedeploy_app" "foo_app" {
name = "foo_app"
}
Expand Down
26 changes: 2 additions & 24 deletions builtin/providers/aws/resource_aws_ecs_task_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
return &schema.Resource{
Create: resourceAwsEcsTaskDefinitionCreate,
Read: resourceAwsEcsTaskDefinitionRead,
Update: resourceAwsEcsTaskDefinitionUpdate,
Delete: resourceAwsEcsTaskDefinitionDelete,

Schema: map[string]*schema.Schema{
Expand All @@ -40,6 +39,7 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
"container_definitions": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
StateFunc: func(v interface{}) string {
hash := sha1.Sum([]byte(v.(string)))
return hex.EncodeToString(hash[:])
Expand All @@ -49,6 +49,7 @@ func resourceAwsEcsTaskDefinition() *schema.Resource {
"volume": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Expand Down Expand Up @@ -131,29 +132,6 @@ func resourceAwsEcsTaskDefinitionRead(d *schema.ResourceData, meta interface{})
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 {
conn := meta.(*AWSClient).ecsconn

Expand Down
94 changes: 92 additions & 2 deletions builtin/providers/aws/resource_aws_ecs_task_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestAccAWSEcsTaskDefinition_basic(t *testing.T) {
),
},
resource.TestStep{
Config: testAccAWSEcsTaskDefinitionModifier,
Config: testAccAWSEcsTaskDefinitionModified,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.jenkins"),
),
Expand All @@ -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 {
conn := testAccProvider.Meta().(*AWSClient).ecsconn

Expand Down Expand Up @@ -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" {
family = "terraform-acc-test"
container_definitions = <<TASK_DEFINITION
Expand Down