github.com/koding/terraform@v0.6.4-0.20170608090606-5d7e0339779d/builtin/providers/aws/data_source_aws_elasticache_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 TestAccAWSDataElasticacheCluster_basic(t *testing.T) {
    12  	rInt := acctest.RandInt()
    13  	rString := acctest.RandString(10)
    14  	resource.Test(t, resource.TestCase{
    15  		PreCheck:  func() { testAccPreCheck(t) },
    16  		Providers: testAccProviders,
    17  		Steps: []resource.TestStep{
    18  			{
    19  				Config: testAccAWSElastiCacheClusterConfigWithDataSource(rString, rInt),
    20  				Check: resource.ComposeAggregateTestCheckFunc(
    21  					resource.TestCheckResourceAttr("data.aws_elasticache_cluster.bar", "engine", "memcached"),
    22  					resource.TestCheckResourceAttr("data.aws_elasticache_cluster.bar", "node_type", "cache.m1.small"),
    23  					resource.TestCheckResourceAttr("data.aws_elasticache_cluster.bar", "port", "11211"),
    24  					resource.TestCheckResourceAttr("data.aws_elasticache_cluster.bar", "num_cache_nodes", "1"),
    25  					resource.TestCheckResourceAttrSet("data.aws_elasticache_cluster.bar", "configuration_endpoint"),
    26  					resource.TestCheckResourceAttrSet("data.aws_elasticache_cluster.bar", "cluster_address"),
    27  					resource.TestCheckResourceAttrSet("data.aws_elasticache_cluster.bar", "availability_zone"),
    28  				),
    29  			},
    30  		},
    31  	})
    32  }
    33  
    34  func testAccAWSElastiCacheClusterConfigWithDataSource(rString string, rInt int) string {
    35  	return fmt.Sprintf(`
    36  provider "aws" {
    37  	region = "us-east-1"
    38  }
    39  
    40  resource "aws_security_group" "bar" {
    41      name = "tf-test-security-group-%d"
    42      description = "tf-test-security-group-descr"
    43      ingress {
    44          from_port = -1
    45          to_port = -1
    46          protocol = "icmp"
    47          cidr_blocks = ["0.0.0.0/0"]
    48      }
    49  }
    50  
    51  resource "aws_elasticache_security_group" "bar" {
    52      name = "tf-test-security-group-%d"
    53      description = "tf-test-security-group-descr"
    54      security_group_names = ["${aws_security_group.bar.name}"]
    55  }
    56  
    57  resource "aws_elasticache_cluster" "bar" {
    58      cluster_id = "tf-%s"
    59      engine = "memcached"
    60      node_type = "cache.m1.small"
    61      num_cache_nodes = 1
    62      port = 11211
    63      parameter_group_name = "default.memcached1.4"
    64      security_group_names = ["${aws_elasticache_security_group.bar.name}"]
    65  }
    66  
    67  data "aws_elasticache_cluster" "bar" {
    68  	cluster_id = "${aws_elasticache_cluster.bar.cluster_id}"
    69  }
    70  
    71  `, rInt, rInt, rString)
    72  }