Skip to content

Commit

Permalink
wip: ecs svc tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Dec 22, 2015
1 parent f8bb48b commit c8fa8c3
Showing 1 changed file with 57 additions and 9 deletions.
66 changes: 57 additions & 9 deletions builtin/providers/aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,39 @@ func TestAccAWSEcsService_withIamRole(t *testing.T) {
testAccCheckAWSEcsServiceExists("aws_ecs_service.ghost"),
),
},
resource.TestStep{
Config: testAccAWSEcsService_withIamRole_modified,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists("aws_ecs_service.ghost"),
),
},
},
})
}

// Regression for https://github.com/hashicorp/terraform/issues/3444
// func TestAccAWSEcsService_withLbChanges(t *testing.T) {
// resource.Test(t, resource.TestCase{
// PreCheck: func() { testAccPreCheck(t) },
// Providers: testAccProviders,
// CheckDestroy: testAccCheckAWSEcsServiceDestroy,
// Steps: []resource.TestStep{
// resource.TestStep{
// Config: testAccAWSEcsService_withLbChanges,
// Check: resource.ComposeTestCheckFunc(
// testAccCheckAWSEcsServiceExists("aws_ecs_service.with_lb_changes"),
// ),
// },
// resource.TestStep{
// Config: testAccAWSEcsService_withLbChanges_modified,
// Check: resource.ComposeTestCheckFunc(
// testAccCheckAWSEcsServiceExists("aws_ecs_service.with_lb_changes"),
// ),
// },
// },
// })
// }

// Regression for https://github.com/hashicorp/terraform/issues/3361
func TestAccAWSEcsService_withEcsClusterName(t *testing.T) {
clusterName := regexp.MustCompile("^terraformecstestcluster$")
Expand Down Expand Up @@ -209,6 +238,7 @@ func testAccCheckAWSEcsServiceDestroy(s *terraform.State) error {

out, err := conn.DescribeServices(&ecs.DescribeServicesInput{
Services: []*string{aws.String(rs.Primary.ID)},
Cluster: aws.String(rs.Primary.Attributes["cluster"]),
})

if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "ClusterNotFoundException" {
Expand All @@ -217,8 +247,19 @@ func testAccCheckAWSEcsServiceDestroy(s *terraform.State) error {

if err == nil {
if len(out.Services) > 0 {
return fmt.Errorf("ECS service still exists:\n%#v", out.Services)
var activeServices []*ecs.Service
for _, svc := range out.Services {
if *svc.Status != "INACTIVE" {
activeServices = append(activeServices, svc)
}
}
if len(activeServices) == 0 {
return nil
}

return fmt.Errorf("ECS service still exists:\n%#v", activeServices)
}
return nil
}

return err
Expand Down Expand Up @@ -294,7 +335,7 @@ resource "aws_ecs_service" "mongo" {
}
`

var testAccAWSEcsService_withIamRole = `
var tpl_testAccAWSEcsService_withIamRole = `
resource "aws_ecs_cluster" "main" {
name = "terraformecstest11"
}
Expand All @@ -306,13 +347,13 @@ resource "aws_ecs_task_definition" "ghost" {
{
"cpu": 128,
"essential": true,
"image": "ghost:latest",
"image": "%s",
"memory": 128,
"name": "ghost",
"name": "%s",
"portMappings": [
{
"containerPort": 2368,
"hostPort": 8080
"containerPort": %d,
"hostPort": %d
}
]
}
Expand Down Expand Up @@ -364,7 +405,7 @@ resource "aws_elb" "main" {
availability_zones = ["us-west-2a"]
listener {
instance_port = 8080
instance_port = %d
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
Expand All @@ -380,14 +421,21 @@ resource "aws_ecs_service" "ghost" {
load_balancer {
elb_name = "${aws_elb.main.id}"
container_name = "ghost"
container_port = "2368"
container_name = "%s"
container_port = "%d"
}
depends_on = ["aws_iam_role_policy.ecs_service"]
}
`

var testAccAWSEcsService_withIamRole = fmt.Sprintf(
tpl_testAccAWSEcsService_withIamRole,
"ghost:latest", "ghost", 2368, 8080, 8080, "ghost", 2368)
var testAccAWSEcsService_withIamRole_modified = fmt.Sprintf(
tpl_testAccAWSEcsService_withIamRole,
"nginx:latest", "nginx", 80, 8080, 8080, "nginx", 80)

var testAccAWSEcsServiceWithFamilyAndRevision = `
resource "aws_ecs_cluster" "default" {
name = "terraformecstest2"
Expand Down

0 comments on commit c8fa8c3

Please sign in to comment.