provider/aws: randomize ECS name

This commit is contained in:
clint shryock 2017-04-14 14:13:09 -05:00
parent 7b32ad2b99
commit 46809cc2cc
1 changed files with 52 additions and 61 deletions

View File

@ -108,20 +108,21 @@ func TestAccAWSEcsServiceWithARN(t *testing.T) {
}
func TestAccAWSEcsServiceWithFamilyAndRevision(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-test")
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcsServiceWithFamilyAndRevision,
Config: testAccAWSEcsServiceWithFamilyAndRevision(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists("aws_ecs_service.jenkins"),
),
},
{
Config: testAccAWSEcsServiceWithFamilyAndRevisionModified,
Config: testAccAWSEcsServiceWithFamilyAndRevisionModified(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists("aws_ecs_service.jenkins"),
),
@ -243,14 +244,13 @@ func TestAccAWSEcsService_withEcsClusterName(t *testing.T) {
}
func TestAccAWSEcsService_withAlb(t *testing.T) {
rString := acctest.RandString(10)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcsServiceWithAlb(rString),
Config: testAccAWSEcsServiceWithAlb,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists("aws_ecs_service.with_alb"),
),
@ -301,14 +301,13 @@ func TestAccAWSEcsServiceWithPlacementConstraints(t *testing.T) {
}
func TestAccAWSEcsServiceWithPlacementConstraints_emptyExpression(t *testing.T) {
rInt := acctest.RandInt()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEcsServiceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEcsServiceWithPlacementConstraintEmptyExpression(rInt),
Config: testAccAWSEcsServiceWithPlacementConstraintEmptyExpression,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEcsServiceExists("aws_ecs_service.mongo"),
resource.TestCheckResourceAttr("aws_ecs_service.mongo", "placement_constraints.#", "1"),
@ -485,36 +484,34 @@ resource "aws_ecs_service" "mongo" {
}
`
func testAccAWSEcsServiceWithPlacementConstraintEmptyExpression(rInt int) string {
return fmt.Sprintf(`
resource "aws_ecs_cluster" "default" {
name = "terraformecstest%d"
}
resource "aws_ecs_task_definition" "mongo" {
family = "mongodb"
container_definitions = <<DEFINITION
[
{
"cpu": 128,
"essential": true,
"image": "mongo:latest",
"memory": 128,
"name": "mongodb"
}
]
DEFINITION
}
resource "aws_ecs_service" "mongo" {
name = "mongodb-%d"
cluster = "${aws_ecs_cluster.default.id}"
task_definition = "${aws_ecs_task_definition.mongo.arn}"
desired_count = 1
placement_constraints {
type = "distinctInstance"
}
}
`, rInt, rInt)
var testAccAWSEcsServiceWithPlacementConstraintEmptyExpression = `
resource "aws_ecs_cluster" "default" {
name = "terraformecstest212"
}
resource "aws_ecs_task_definition" "mongo" {
family = "mongodb"
container_definitions = <<DEFINITION
[
{
"cpu": 128,
"essential": true,
"image": "mongo:latest",
"memory": 128,
"name": "mongodb"
}
]
DEFINITION
}
resource "aws_ecs_service" "mongo" {
name = "mongodb"
cluster = "${aws_ecs_cluster.default.id}"
task_definition = "${aws_ecs_task_definition.mongo.arn}"
desired_count = 1
placement_constraints {
type = "distinctInstance"
}
}
`
var testAccAWSEcsService_withIamRole = `
resource "aws_ecs_cluster" "main" {
@ -739,13 +736,14 @@ var testAccAWSEcsService_withLbChanges_modified = fmt.Sprintf(
tpl_testAccAWSEcsService_withLbChanges,
"nginx:latest", "nginx", 80, 8080, 8080, "nginx", 80)
var testAccAWSEcsServiceWithFamilyAndRevision = `
func testAccAWSEcsServiceWithFamilyAndRevision(rName string) string {
return fmt.Sprintf(`
resource "aws_ecs_cluster" "default" {
name = "terraformecstest2"
name = "%s"
}
resource "aws_ecs_task_definition" "jenkins" {
family = "jenkins"
family = "%s"
container_definitions = <<DEFINITION
[
{
@ -760,20 +758,21 @@ DEFINITION
}
resource "aws_ecs_service" "jenkins" {
name = "jenkins"
name = "%s"
cluster = "${aws_ecs_cluster.default.id}"
task_definition = "${aws_ecs_task_definition.jenkins.family}:${aws_ecs_task_definition.jenkins.revision}"
desired_count = 1
}`, rName, rName, rName)
}
`
var testAccAWSEcsServiceWithFamilyAndRevisionModified = `
func testAccAWSEcsServiceWithFamilyAndRevisionModified(rName string) string {
return fmt.Sprintf(`
resource "aws_ecs_cluster" "default" {
name = "terraformecstest2"
name = "%s"
}
resource "aws_ecs_task_definition" "jenkins" {
family = "jenkins"
family = "%s"
container_definitions = <<DEFINITION
[
{
@ -788,12 +787,12 @@ DEFINITION
}
resource "aws_ecs_service" "jenkins" {
name = "jenkins"
name = "%s"
cluster = "${aws_ecs_cluster.default.id}"
task_definition = "${aws_ecs_task_definition.jenkins.family}:${aws_ecs_task_definition.jenkins.revision}"
desired_count = 1
}`, rName, rName, rName)
}
`
var testAccAWSEcsServiceWithRenamedCluster = `
resource "aws_ecs_cluster" "default" {
@ -875,8 +874,7 @@ resource "aws_ecs_service" "jenkins" {
}
`
func testAccAWSEcsServiceWithAlb(rString string) string {
return fmt.Sprintf(`
var testAccAWSEcsServiceWithAlb = `
data "aws_availability_zones" "available" {}
resource "aws_vpc" "main" {
@ -891,7 +889,7 @@ resource "aws_subnet" "main" {
}
resource "aws_ecs_cluster" "main" {
name = "terraform_acc_test_ecs_%s"
name = "terraform_acc_test_ecs_15"
}
resource "aws_ecs_task_definition" "with_lb_changes" {
@ -916,7 +914,7 @@ DEFINITION
}
resource "aws_iam_role" "ecs_service" {
name = "tf_acc_test_%s_role"
name = "tf_acc_test_15_role"
assume_role_policy = <<EOF
{
"Version": "2008-10-17",
@ -935,7 +933,7 @@ EOF
}
resource "aws_iam_role_policy" "ecs_service" {
name = "tf_acc_test_%s_policy"
name = "tf_acc_test_15_policy"
role = "${aws_iam_role.ecs_service.name}"
policy = <<EOF
{
@ -959,22 +957,16 @@ EOF
}
resource "aws_alb_target_group" "test" {
name = "tf-acc-test-ecs-ghost-%s"
name = "tf-acc-test-ecs-ghost"
port = 80
protocol = "HTTP"
vpc_id = "${aws_vpc.main.id}"
tags {
Name = "TestAccAWSEcsService_withAlb"
}
}
resource "aws_alb" "main" {
name = "tf-acc-test-alb-ecs-%s"
name = "tf-acc-test-test-alb-ecs"
internal = true
subnets = ["${aws_subnet.main.*.id}"]
tags {
Name = "TestAccAWSEcsService_withAlb"
}
}
resource "aws_alb_listener" "front_end" {
@ -989,7 +981,7 @@ resource "aws_alb_listener" "front_end" {
}
resource "aws_ecs_service" "with_alb" {
name = "tf-acc-test-ecs-ghost-%s"
name = "tf-acc-test-ecs-ghost"
cluster = "${aws_ecs_cluster.main.id}"
task_definition = "${aws_ecs_task_definition.with_lb_changes.arn}"
desired_count = 1
@ -1006,5 +998,4 @@ resource "aws_ecs_service" "with_alb" {
"aws_alb_listener.front_end"
]
}
`, rString, rString, rString, rString, rString, rString)
}
`