github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/aws/data_source_aws_ecs_cluster_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/acctest"
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  )
    10  
    11  func TestAccAWSEcsDataSource_ecsCluster(t *testing.T) {
    12  	resource.Test(t, resource.TestCase{
    13  		PreCheck:  func() { testAccPreCheck(t) },
    14  		Providers: testAccProviders,
    15  		Steps: []resource.TestStep{
    16  			{
    17  				Config: testAccCheckAwsEcsClusterDataSourceConfig,
    18  				Check: resource.ComposeTestCheckFunc(
    19  					resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "status", "ACTIVE"),
    20  					resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "pending_tasks_count", "0"),
    21  					resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "running_tasks_count", "0"),
    22  					resource.TestCheckResourceAttr("data.aws_ecs_cluster.default", "registered_container_instances_count", "0"),
    23  				),
    24  			},
    25  		},
    26  	})
    27  }
    28  
    29  var testAccCheckAwsEcsClusterDataSourceConfig = fmt.Sprintf(`
    30  resource "aws_ecs_cluster" "default" {
    31    name = "default-%d"
    32  }
    33  
    34  resource "aws_ecs_task_definition" "mongo" {
    35    family = "mongodb"
    36    container_definitions = <<DEFINITION
    37  [
    38    {
    39      "cpu": 128,
    40      "essential": true,
    41      "image": "mongo:latest",
    42      "memory": 128,
    43      "memoryReservation": 64,
    44      "name": "mongodb"
    45    }
    46  ]
    47  DEFINITION
    48  }
    49  
    50  resource "aws_ecs_service" "mongo" {
    51    name = "mongodb"
    52    cluster = "${aws_ecs_cluster.default.id}"
    53    task_definition = "${aws_ecs_task_definition.mongo.arn}"
    54    desired_count = 1
    55  }
    56  
    57  data "aws_ecs_cluster" "default" {
    58    cluster_name = "${aws_ecs_cluster.default.name}"
    59  }
    60  `, acctest.RandInt())