github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/data_source_aws_db_instance_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 TestAccAWSDataDbInstance_basic(t *testing.T) {
    12  	rInt := acctest.RandInt()
    13  	resource.Test(t, resource.TestCase{
    14  		PreCheck:  func() { testAccPreCheck(t) },
    15  		Providers: testAccProviders,
    16  		Steps: []resource.TestStep{
    17  			{
    18  				Config: testAccAWSDBInstanceConfigWithDataSource(rInt),
    19  				Check: resource.ComposeAggregateTestCheckFunc(
    20  					resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "allocated_storage"),
    21  					resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "engine"),
    22  					resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "db_instance_class"),
    23  					resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "db_name"),
    24  					resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "master_username"),
    25  				),
    26  			},
    27  		},
    28  	})
    29  }
    30  
    31  func TestAccAWSDataDbInstance_endpoint(t *testing.T) {
    32  	rInt := acctest.RandInt()
    33  	resource.Test(t, resource.TestCase{
    34  		PreCheck:  func() { testAccPreCheck(t) },
    35  		Providers: testAccProviders,
    36  		Steps: []resource.TestStep{
    37  			{
    38  				Config: testAccAWSDBInstanceConfigWithDataSource(rInt),
    39  				Check: resource.ComposeAggregateTestCheckFunc(
    40  					resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "address"),
    41  					resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "port"),
    42  					resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "hosted_zone_id"),
    43  					resource.TestCheckResourceAttrSet("data.aws_db_instance.bar", "endpoint"),
    44  				),
    45  			},
    46  		},
    47  	})
    48  }
    49  
    50  func testAccAWSDBInstanceConfigWithDataSource(rInt int) string {
    51  	return fmt.Sprintf(`
    52  resource "aws_db_instance" "bar" {
    53  	identifier = "datasource-test-terraform-%d"
    54  
    55  	allocated_storage = 10
    56  	engine = "MySQL"
    57  	instance_class = "db.m1.small"
    58  	name = "baz"
    59  	password = "barbarbarbar"
    60  	username = "foo"
    61  
    62  	backup_retention_period = 0
    63  	skip_final_snapshot = true
    64  }
    65  
    66  data "aws_db_instance" "bar" {
    67  	db_instance_identifier = "${aws_db_instance.bar.identifier}"
    68  }
    69  
    70  `, rInt)
    71  }