Making some last tweaks and fixing some acc tests

This commit is contained in:
Sander van Harmelen 2014-11-24 21:22:18 +01:00
parent 0725486e89
commit d3e1a6678d
6 changed files with 51 additions and 16 deletions

View File

@ -9,7 +9,7 @@ import (
"github.com/mitchellh/goamz/rds"
)
func TestAccAWSDbSubnetGroup(t *testing.T) {
func TestAccAWSDBSubnetGroup(t *testing.T) {
var v rds.DBSubnetGroup
testCheck := func(*terraform.State) error {
@ -19,12 +19,12 @@ func TestAccAWSDbSubnetGroup(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDbSubnetGroupDestroy,
CheckDestroy: testAccCheckDBSubnetGroupDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDbSubnetGroupConfig,
Config: testAccDBSubnetGroupConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckDbSubnetGroupExists(
testAccCheckDBSubnetGroupExists(
"aws_db_subnet_group.foo", &v),
testCheck,
),
@ -33,7 +33,7 @@ func TestAccAWSDbSubnetGroup(t *testing.T) {
})
}
func testAccCheckDbSubnetGroupDestroy(s *terraform.State) error {
func testAccCheckDBSubnetGroupDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).rdsconn
for _, rs := range s.RootModule().Resources {
@ -64,7 +64,7 @@ func testAccCheckDbSubnetGroupDestroy(s *terraform.State) error {
return nil
}
func testAccCheckDbSubnetGroupExists(n string, v *rds.DBSubnetGroup) resource.TestCheckFunc {
func testAccCheckDBSubnetGroupExists(n string, v *rds.DBSubnetGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
@ -90,18 +90,20 @@ func testAccCheckDbSubnetGroupExists(n string, v *rds.DBSubnetGroup) resource.Te
}
}
const testAccDbSubnetGroupConfig = `
const testAccDBSubnetGroupConfig = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
}
resource "aws_subnet" "foo" {
cidr_block = "10.1.1.0/24"
availability_zone = "us-west-2a"
vpc_id = "${aws_vpc.foo.id}"
}
resource "aws_subnet" "bar" {
cidr_block = "10.1.2.0/24"
availability_zone = "us-west-2b"
vpc_id = "${aws_vpc.foo.id}"
}

View File

@ -343,6 +343,8 @@ resource "aws_instance" "foo" {
const testAccCheckInstanceConfigTags = `
resource "aws_instance" "foo" {
ami = "ami-4fccb37f"
instance_type = "m1.small"
tags {
foo = "bar"
}
@ -351,6 +353,8 @@ resource "aws_instance" "foo" {
const testAccCheckInstanceConfigTagsUpdate = `
resource "aws_instance" "foo" {
ami = "ami-4fccb37f"
instance_type = "m1.small"
tags {
bar = "baz"
}

View File

@ -16,6 +16,7 @@ func resourceAwsRouteTable() *schema.Resource {
return &schema.Resource{
Create: resourceAwsRouteTableCreate,
Read: resourceAwsRouteTableRead,
Update: resourceAwsRouteTableUpdate,
Delete: resourceAwsRouteTableDelete,
Schema: map[string]*schema.Schema{
@ -87,7 +88,7 @@ func resourceAwsRouteTableCreate(d *schema.ResourceData, meta interface{}) error
d.Id(), err)
}
return resourceAwsRouteTableRead(d, meta)
return resourceAwsRouteTableUpdate(d, meta)
}
func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
@ -104,7 +105,29 @@ func resourceAwsRouteTableRead(d *schema.ResourceData, meta interface{}) error {
rt := rtRaw.(*ec2.RouteTable)
d.Set("vpc_id", rt.VpcId)
// TODO: Add some code to also update the route set
// Create an empty schema.Set to hold all routes
route := &schema.Set{F: resourceAwsRouteTableHash}
// Loop through the routes and add them to the set
for _, r := range rt.Routes {
if r.GatewayId == "local" {
continue
}
m := make(map[string]interface{})
m["cidr_block"] = r.DestinationCidrBlock
if r.GatewayId != "" {
m["gateway_id"] = r.GatewayId
}
if r.InstanceId != "" {
m["instance_id"] = r.InstanceId
}
route.Add(m)
}
d.Set("route", route)
return nil
}

View File

@ -2,13 +2,17 @@ package aws
import (
"fmt"
"math/rand"
"testing"
"time"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccAWSS3Bucket(t *testing.T) {
rand.Seed(time.Now().UnixNano())
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
@ -64,9 +68,11 @@ func testAccCheckAWSS3BucketExists(n string) resource.TestCheckFunc {
}
}
const testAccAWSS3BucketConfig = `
// This needs a bit of randoness as the name can only be
// used once globally within AWS
var testAccAWSS3BucketConfig = fmt.Sprintf(`
resource "aws_s3_bucket" "bar" {
bucket = "tf-test-bucket"
bucket = "tf-test-bucket-%d"
acl = "public-read"
}
`
`, rand.Int())

View File

@ -275,7 +275,7 @@ func resourceAwsSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) er
d.SetPartial("tags")
}
return nil
return resourceAwsSecurityGroupRead(d, meta)
}
func resourceAwsSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {

View File

@ -192,9 +192,9 @@ func flattenParameters(list []rds.Parameter) []map[string]interface{} {
result := make([]map[string]interface{}, 0, len(list))
for _, i := range list {
result = append(result, map[string]interface{}{
"name": strings.ToLower(i.ParameterName),
"value": strings.ToLower(i.ParameterValue),
})
"name": strings.ToLower(i.ParameterName),
"value": strings.ToLower(i.ParameterValue),
})
}
return result
}