github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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 testAccAWSDBInstanceConfigWithDataSource(rInt int) string {
    32  	return fmt.Sprintf(`
    33  resource "aws_db_instance" "bar" {
    34  	identifier = "datasource-test-terraform-%d"
    35  
    36  	allocated_storage = 10
    37  	engine = "MySQL"
    38  	instance_class = "db.m1.small"
    39  	name = "baz"
    40  	password = "barbarbarbar"
    41  	username = "foo"
    42  
    43  	backup_retention_period = 0
    44  	skip_final_snapshot = true
    45  }
    46  
    47  data "aws_db_instance" "bar" {
    48  	db_instance_identifier = "${aws_db_instance.bar.identifier}"
    49  }
    50  
    51  `, rInt)
    52  }