Merge pull request #11818 from hashicorp/f-update-ecs-task-definition-tests

provider/aws: Fix ECS Task Definition tests
This commit is contained in:
Jake Champlin 2017-02-09 09:31:26 -05:00 committed by GitHub
commit 30fc87ce55
1 changed files with 127 additions and 122 deletions

View File

@ -6,6 +6,7 @@ import (
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ecs" "github.com/aws/aws-sdk-go/service/ecs"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -79,13 +80,14 @@ func TestAccAWSEcsTaskDefinition_withEcsService(t *testing.T) {
func TestAccAWSEcsTaskDefinition_withTaskRoleArn(t *testing.T) { func TestAccAWSEcsTaskDefinition_withTaskRoleArn(t *testing.T) {
var def ecs.TaskDefinition var def ecs.TaskDefinition
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy, CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccAWSEcsTaskDefinitionWithTaskRoleArn, Config: testAccAWSEcsTaskDefinitionWithTaskRoleArn(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep", &def), testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep", &def),
), ),
@ -96,13 +98,14 @@ func TestAccAWSEcsTaskDefinition_withTaskRoleArn(t *testing.T) {
func TestAccAWSEcsTaskDefinition_withNetworkMode(t *testing.T) { func TestAccAWSEcsTaskDefinition_withNetworkMode(t *testing.T) {
var def ecs.TaskDefinition var def ecs.TaskDefinition
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders, Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy, CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccAWSEcsTaskDefinitionWithNetworkMode, Config: testAccAWSEcsTaskDefinitionWithNetworkMode(rInt),
Check: resource.ComposeTestCheckFunc( Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep", &def), testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep", &def),
resource.TestCheckResourceAttr( resource.TestCheckResourceAttr(
@ -338,132 +341,134 @@ TASK_DEFINITION
} }
` `
var testAccAWSEcsTaskDefinitionWithTaskRoleArn = ` func testAccAWSEcsTaskDefinitionWithTaskRoleArn(rInt int) string {
resource "aws_iam_role" "role_test" { return fmt.Sprintf(`
name = "tf_old_name" resource "aws_iam_role" "role_test" {
path = "/test/" name = "tf_old_name-%d"
assume_role_policy = <<EOF path = "/test/"
{ assume_role_policy = <<EOF
"Version": "2012-10-17", {
"Statement": [ "Version": "2012-10-17",
{ "Statement": [
"Action": "sts:AssumeRole", {
"Principal": { "Action": "sts:AssumeRole",
"Service": "ec2.amazonaws.com" "Principal": {
}, "Service": "ec2.amazonaws.com"
"Effect": "Allow", },
"Sid": "" "Effect": "Allow",
} "Sid": ""
] }
} ]
EOF }
EOF
}
resource "aws_iam_role_policy" "role_test" {
name = "role_update_test-%d"
role = "${aws_iam_role.role_test.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Resource": "arn:aws:s3:::*"
}
]
}
EOF
}
resource "aws_ecs_task_definition" "sleep" {
family = "terraform-acc-sc-volume-test"
task_role_arn = "${aws_iam_role.role_test.arn}"
container_definitions = <<TASK_DEFINITION
[
{
"name": "sleep",
"image": "busybox",
"cpu": 10,
"command": ["sleep","360"],
"memory": 10,
"essential": true
}
]
TASK_DEFINITION
volume {
name = "database_scratch"
}
}`, rInt, rInt)
} }
resource "aws_iam_role_policy" "role_test" { func testAccAWSEcsTaskDefinitionWithNetworkMode(rInt int) string {
name = "role_update_test" return fmt.Sprintf(`
role = "${aws_iam_role.role_test.id}" resource "aws_iam_role" "role_test" {
policy = <<EOF name = "tf_old_name-%d"
{ path = "/test/"
"Version": "2012-10-17", assume_role_policy = <<EOF
"Statement": [ {
{ "Version": "2012-10-17",
"Effect": "Allow", "Statement": [
"Action": [ {
"s3:GetBucketLocation", "Action": "sts:AssumeRole",
"s3:ListAllMyBuckets" "Principal": {
], "Service": "ec2.amazonaws.com"
"Resource": "arn:aws:s3:::*" },
} "Effect": "Allow",
] "Sid": ""
} }
EOF ]
} }
EOF
}
resource "aws_ecs_task_definition" "sleep" { resource "aws_iam_role_policy" "role_test" {
family = "terraform-acc-sc-volume-test" name = "role_update_test-%d"
task_role_arn = "${aws_iam_role.role_test.arn}" role = "${aws_iam_role.role_test.id}"
container_definitions = <<TASK_DEFINITION policy = <<EOF
[ {
{ "Version": "2012-10-17",
"name": "sleep", "Statement": [
"image": "busybox", {
"cpu": 10, "Effect": "Allow",
"command": ["sleep","360"], "Action": [
"memory": 10, "s3:GetBucketLocation",
"essential": true "s3:ListAllMyBuckets"
} ],
] "Resource": "arn:aws:s3:::*"
TASK_DEFINITION }
]
}
EOF
}
volume { resource "aws_ecs_task_definition" "sleep" {
name = "database_scratch" family = "terraform-acc-sc-volume-test-network-mode"
} task_role_arn = "${aws_iam_role.role_test.arn}"
} network_mode = "bridge"
` container_definitions = <<TASK_DEFINITION
[
{
"name": "sleep",
"image": "busybox",
"cpu": 10,
"command": ["sleep","360"],
"memory": 10,
"essential": true
}
]
TASK_DEFINITION
var testAccAWSEcsTaskDefinitionWithNetworkMode = ` volume {
resource "aws_iam_role" "role_test" { name = "database_scratch"
name = "tf_old_name" }
path = "/test/" }`, rInt, rInt)
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
} }
EOF
}
resource "aws_iam_role_policy" "role_test" {
name = "role_update_test"
role = "${aws_iam_role.role_test.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetBucketLocation",
"s3:ListAllMyBuckets"
],
"Resource": "arn:aws:s3:::*"
}
]
}
EOF
}
resource "aws_ecs_task_definition" "sleep" {
family = "terraform-acc-sc-volume-test-network-mode"
task_role_arn = "${aws_iam_role.role_test.arn}"
network_mode = "bridge"
container_definitions = <<TASK_DEFINITION
[
{
"name": "sleep",
"image": "busybox",
"cpu": 10,
"command": ["sleep","360"],
"memory": 10,
"essential": true
}
]
TASK_DEFINITION
volume {
name = "database_scratch"
}
}
`
var testAccAWSEcsTaskDefinitionWithEcsService = ` var testAccAWSEcsTaskDefinitionWithEcsService = `
resource "aws_ecs_cluster" "default" { resource "aws_ecs_cluster" "default" {