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/service/ecs"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
@ -79,13 +80,14 @@ func TestAccAWSEcsTaskDefinition_withEcsService(t *testing.T) {
func TestAccAWSEcsTaskDefinition_withTaskRoleArn(t *testing.T) {
var def ecs.TaskDefinition
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcsTaskDefinitionWithTaskRoleArn,
Config: testAccAWSEcsTaskDefinitionWithTaskRoleArn(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep", &def),
),
@ -96,13 +98,14 @@ func TestAccAWSEcsTaskDefinition_withTaskRoleArn(t *testing.T) {
func TestAccAWSEcsTaskDefinition_withNetworkMode(t *testing.T) {
var def ecs.TaskDefinition
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsTaskDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcsTaskDefinitionWithNetworkMode,
Config: testAccAWSEcsTaskDefinitionWithNetworkMode(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsTaskDefinitionExists("aws_ecs_task_definition.sleep", &def),
resource.TestCheckResourceAttr(
@ -338,12 +341,13 @@ TASK_DEFINITION
}
`
var testAccAWSEcsTaskDefinitionWithTaskRoleArn = `
resource "aws_iam_role" "role_test" {
name = "tf_old_name"
func testAccAWSEcsTaskDefinitionWithTaskRoleArn(rInt int) string {
return fmt.Sprintf(`
resource "aws_iam_role" "role_test" {
name = "tf_old_name-%d"
path = "/test/"
assume_role_policy = <<EOF
{
{
"Version": "2012-10-17",
"Statement": [
{
@ -355,15 +359,15 @@ resource "aws_iam_role" "role_test" {
"Sid": ""
}
]
}
EOF
}
}
EOF
}
resource "aws_iam_role_policy" "role_test" {
name = "role_update_test"
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": [
{
@ -375,15 +379,15 @@ resource "aws_iam_role_policy" "role_test" {
"Resource": "arn:aws:s3:::*"
}
]
}
EOF
}
}
EOF
}
resource "aws_ecs_task_definition" "sleep" {
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",
@ -392,21 +396,22 @@ resource "aws_ecs_task_definition" "sleep" {
"memory": 10,
"essential": true
}
]
TASK_DEFINITION
]
TASK_DEFINITION
volume {
name = "database_scratch"
}
}`, rInt, rInt)
}
`
var testAccAWSEcsTaskDefinitionWithNetworkMode = `
resource "aws_iam_role" "role_test" {
name = "tf_old_name"
func testAccAWSEcsTaskDefinitionWithNetworkMode(rInt int) string {
return fmt.Sprintf(`
resource "aws_iam_role" "role_test" {
name = "tf_old_name-%d"
path = "/test/"
assume_role_policy = <<EOF
{
{
"Version": "2012-10-17",
"Statement": [
{
@ -418,15 +423,15 @@ resource "aws_iam_role" "role_test" {
"Sid": ""
}
]
}
EOF
}
}
EOF
}
resource "aws_iam_role_policy" "role_test" {
name = "role_update_test"
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": [
{
@ -438,16 +443,16 @@ resource "aws_iam_role_policy" "role_test" {
"Resource": "arn:aws:s3:::*"
}
]
}
EOF
}
}
EOF
}
resource "aws_ecs_task_definition" "sleep" {
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",
@ -456,14 +461,14 @@ resource "aws_ecs_task_definition" "sleep" {
"memory": 10,
"essential": true
}
]
TASK_DEFINITION
]
TASK_DEFINITION
volume {
name = "database_scratch"
}
}`, rInt, rInt)
}
`
var testAccAWSEcsTaskDefinitionWithEcsService = `
resource "aws_ecs_cluster" "default" {