Merge pull request #11818 from hashicorp/f-update-ecs-task-definition-tests
provider/aws: Fix ECS Task Definition tests
This commit is contained in:
commit
30fc87ce55
|
@ -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,12 +341,13 @@ 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" {
|
||||||
|
name = "tf_old_name-%d"
|
||||||
path = "/test/"
|
path = "/test/"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = <<EOF
|
||||||
{
|
{
|
||||||
"Version": "2012-10-17",
|
"Version": "2012-10-17",
|
||||||
"Statement": [
|
"Statement": [
|
||||||
{
|
{
|
||||||
|
@ -355,15 +359,15 @@ resource "aws_iam_role" "role_test" {
|
||||||
"Sid": ""
|
"Sid": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy" "role_test" {
|
resource "aws_iam_role_policy" "role_test" {
|
||||||
name = "role_update_test"
|
name = "role_update_test-%d"
|
||||||
role = "${aws_iam_role.role_test.id}"
|
role = "${aws_iam_role.role_test.id}"
|
||||||
policy = <<EOF
|
policy = <<EOF
|
||||||
{
|
{
|
||||||
"Version": "2012-10-17",
|
"Version": "2012-10-17",
|
||||||
"Statement": [
|
"Statement": [
|
||||||
{
|
{
|
||||||
|
@ -375,15 +379,15 @@ resource "aws_iam_role_policy" "role_test" {
|
||||||
"Resource": "arn:aws:s3:::*"
|
"Resource": "arn:aws:s3:::*"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_ecs_task_definition" "sleep" {
|
resource "aws_ecs_task_definition" "sleep" {
|
||||||
family = "terraform-acc-sc-volume-test"
|
family = "terraform-acc-sc-volume-test"
|
||||||
task_role_arn = "${aws_iam_role.role_test.arn}"
|
task_role_arn = "${aws_iam_role.role_test.arn}"
|
||||||
container_definitions = <<TASK_DEFINITION
|
container_definitions = <<TASK_DEFINITION
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "sleep",
|
"name": "sleep",
|
||||||
"image": "busybox",
|
"image": "busybox",
|
||||||
|
@ -392,21 +396,22 @@ resource "aws_ecs_task_definition" "sleep" {
|
||||||
"memory": 10,
|
"memory": 10,
|
||||||
"essential": true
|
"essential": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
TASK_DEFINITION
|
TASK_DEFINITION
|
||||||
|
|
||||||
volume {
|
volume {
|
||||||
name = "database_scratch"
|
name = "database_scratch"
|
||||||
}
|
}
|
||||||
|
}`, rInt, rInt)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
||||||
var testAccAWSEcsTaskDefinitionWithNetworkMode = `
|
func testAccAWSEcsTaskDefinitionWithNetworkMode(rInt int) string {
|
||||||
resource "aws_iam_role" "role_test" {
|
return fmt.Sprintf(`
|
||||||
name = "tf_old_name"
|
resource "aws_iam_role" "role_test" {
|
||||||
|
name = "tf_old_name-%d"
|
||||||
path = "/test/"
|
path = "/test/"
|
||||||
assume_role_policy = <<EOF
|
assume_role_policy = <<EOF
|
||||||
{
|
{
|
||||||
"Version": "2012-10-17",
|
"Version": "2012-10-17",
|
||||||
"Statement": [
|
"Statement": [
|
||||||
{
|
{
|
||||||
|
@ -418,15 +423,15 @@ resource "aws_iam_role" "role_test" {
|
||||||
"Sid": ""
|
"Sid": ""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_iam_role_policy" "role_test" {
|
resource "aws_iam_role_policy" "role_test" {
|
||||||
name = "role_update_test"
|
name = "role_update_test-%d"
|
||||||
role = "${aws_iam_role.role_test.id}"
|
role = "${aws_iam_role.role_test.id}"
|
||||||
policy = <<EOF
|
policy = <<EOF
|
||||||
{
|
{
|
||||||
"Version": "2012-10-17",
|
"Version": "2012-10-17",
|
||||||
"Statement": [
|
"Statement": [
|
||||||
{
|
{
|
||||||
|
@ -438,16 +443,16 @@ resource "aws_iam_role_policy" "role_test" {
|
||||||
"Resource": "arn:aws:s3:::*"
|
"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"
|
family = "terraform-acc-sc-volume-test-network-mode"
|
||||||
task_role_arn = "${aws_iam_role.role_test.arn}"
|
task_role_arn = "${aws_iam_role.role_test.arn}"
|
||||||
network_mode = "bridge"
|
network_mode = "bridge"
|
||||||
container_definitions = <<TASK_DEFINITION
|
container_definitions = <<TASK_DEFINITION
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"name": "sleep",
|
"name": "sleep",
|
||||||
"image": "busybox",
|
"image": "busybox",
|
||||||
|
@ -456,14 +461,14 @@ resource "aws_ecs_task_definition" "sleep" {
|
||||||
"memory": 10,
|
"memory": 10,
|
||||||
"essential": true
|
"essential": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
TASK_DEFINITION
|
TASK_DEFINITION
|
||||||
|
|
||||||
volume {
|
volume {
|
||||||
name = "database_scratch"
|
name = "database_scratch"
|
||||||
}
|
}
|
||||||
|
}`, rInt, rInt)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
||||||
var testAccAWSEcsTaskDefinitionWithEcsService = `
|
var testAccAWSEcsTaskDefinitionWithEcsService = `
|
||||||
resource "aws_ecs_cluster" "default" {
|
resource "aws_ecs_cluster" "default" {
|
||||||
|
|
Loading…
Reference in New Issue