providers/aws: tests passing, compiles

This commit is contained in:
Mitchell Hashimoto 2014-09-16 17:44:42 -07:00
parent 71782c57b3
commit c5d6df692d
32 changed files with 234 additions and 297 deletions

View File

@ -13,9 +13,9 @@ import (
) )
func resource_aws_autoscaling_group_create( func resource_aws_autoscaling_group_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn autoscalingconn := p.autoscalingconn
@ -81,9 +81,6 @@ func resource_aws_autoscaling_group_create(
} }
rs.ID = rs.Attributes["name"] rs.ID = rs.Attributes["name"]
rs.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: rs.Attributes["launch_configuration"]},
}
log.Printf("[INFO] AutoScaling Group ID: %s", rs.ID) log.Printf("[INFO] AutoScaling Group ID: %s", rs.ID)
@ -96,9 +93,9 @@ func resource_aws_autoscaling_group_create(
} }
func resource_aws_autoscaling_group_update( func resource_aws_autoscaling_group_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn autoscalingconn := p.autoscalingconn
rs := s.MergeDiff(d) rs := s.MergeDiff(d)
@ -141,7 +138,7 @@ func resource_aws_autoscaling_group_update(
} }
func resource_aws_autoscaling_group_destroy( func resource_aws_autoscaling_group_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn autoscalingconn := p.autoscalingconn
@ -173,8 +170,8 @@ func resource_aws_autoscaling_group_destroy(
} }
func resource_aws_autoscaling_group_refresh( func resource_aws_autoscaling_group_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn autoscalingconn := p.autoscalingconn
@ -188,7 +185,7 @@ func resource_aws_autoscaling_group_refresh(
} }
func resource_aws_autoscaling_group_diff( func resource_aws_autoscaling_group_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
@ -223,8 +220,8 @@ func resource_aws_autoscaling_group_diff(
} }
func resource_aws_autoscaling_group_update_state( func resource_aws_autoscaling_group_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
g *autoscaling.AutoScalingGroup) (*terraform.ResourceState, error) { g *autoscaling.AutoScalingGroup) (*terraform.InstanceState, error) {
s.Attributes["min_size"] = strconv.Itoa(g.MinSize) s.Attributes["min_size"] = strconv.Itoa(g.MinSize)
s.Attributes["max_size"] = strconv.Itoa(g.MaxSize) s.Attributes["max_size"] = strconv.Itoa(g.MaxSize)

View File

@ -65,7 +65,7 @@ func TestAccAWSAutoScalingGroupWithLoadBalancer(t *testing.T) {
func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error { func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error {
conn := testAccProvider.autoscalingconn conn := testAccProvider.autoscalingconn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_autoscaling_group" { if rs.Type != "aws_autoscaling_group" {
continue continue
} }
@ -73,12 +73,12 @@ func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error {
// Try to find the Group // Try to find the Group
describeGroups, err := conn.DescribeAutoScalingGroups( describeGroups, err := conn.DescribeAutoScalingGroups(
&autoscaling.DescribeAutoScalingGroups{ &autoscaling.DescribeAutoScalingGroups{
Names: []string{rs.ID}, Names: []string{rs.Primary.ID},
}) })
if err == nil { if err == nil {
if len(describeGroups.AutoScalingGroups) != 0 && if len(describeGroups.AutoScalingGroups) != 0 &&
describeGroups.AutoScalingGroups[0].Name == rs.ID { describeGroups.AutoScalingGroups[0].Name == rs.Primary.ID {
return fmt.Errorf("AutoScaling Group still exists") return fmt.Errorf("AutoScaling Group still exists")
} }
} }
@ -146,19 +146,19 @@ func testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(group *autoscaling.Au
func testAccCheckAWSAutoScalingGroupExists(n string, group *autoscaling.AutoScalingGroup) resource.TestCheckFunc { func testAccCheckAWSAutoScalingGroupExists(n string, group *autoscaling.AutoScalingGroup) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No AutoScaling Group ID is set") return fmt.Errorf("No AutoScaling Group ID is set")
} }
conn := testAccProvider.autoscalingconn conn := testAccProvider.autoscalingconn
describeOpts := autoscaling.DescribeAutoScalingGroups{ describeOpts := autoscaling.DescribeAutoScalingGroups{
Names: []string{rs.ID}, Names: []string{rs.Primary.ID},
} }
describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts) describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts)
@ -167,7 +167,7 @@ func testAccCheckAWSAutoScalingGroupExists(n string, group *autoscaling.AutoScal
} }
if len(describeGroups.AutoScalingGroups) != 1 || if len(describeGroups.AutoScalingGroups) != 1 ||
describeGroups.AutoScalingGroups[0].Name != rs.ID { describeGroups.AutoScalingGroups[0].Name != rs.Primary.ID {
return fmt.Errorf("AutoScaling Group not found") return fmt.Errorf("AutoScaling Group not found")
} }

View File

@ -16,9 +16,9 @@ import (
) )
func resource_aws_db_instance_create( func resource_aws_db_instance_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
conn := p.rdsconn conn := p.rdsconn
@ -136,14 +136,14 @@ func resource_aws_db_instance_create(
} }
func resource_aws_db_instance_update( func resource_aws_db_instance_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
panic("Cannot update DB") panic("Cannot update DB")
} }
func resource_aws_db_instance_destroy( func resource_aws_db_instance_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
conn := p.rdsconn conn := p.rdsconn
@ -184,8 +184,8 @@ func resource_aws_db_instance_destroy(
} }
func resource_aws_db_instance_refresh( func resource_aws_db_instance_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
conn := p.rdsconn conn := p.rdsconn
@ -199,7 +199,7 @@ func resource_aws_db_instance_refresh(
} }
func resource_aws_db_instance_diff( func resource_aws_db_instance_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
@ -247,8 +247,8 @@ func resource_aws_db_instance_diff(
} }
func resource_aws_db_instance_update_state( func resource_aws_db_instance_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
v *rds.DBInstance) (*terraform.ResourceState, error) { v *rds.DBInstance) (*terraform.InstanceState, error) {
s.Attributes["address"] = v.Address s.Attributes["address"] = v.Address
s.Attributes["allocated_storage"] = strconv.Itoa(v.AllocatedStorage) s.Attributes["allocated_storage"] = strconv.Itoa(v.AllocatedStorage)
@ -279,13 +279,6 @@ func resource_aws_db_instance_update_state(
s.Attributes[k] = v s.Attributes[k] = v
} }
// We depend on any security groups attached
for _, g := range v.DBSecurityGroupNames {
s.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: g},
}
}
return s, nil return s, nil
} }

View File

@ -52,7 +52,7 @@ func TestAccAWSDBInstance(t *testing.T) {
func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error { func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
conn := testAccProvider.rdsconn conn := testAccProvider.rdsconn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_db_instance" { if rs.Type != "aws_db_instance" {
continue continue
} }
@ -60,12 +60,12 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error {
// Try to find the Group // Try to find the Group
resp, err := conn.DescribeDBInstances( resp, err := conn.DescribeDBInstances(
&rds.DescribeDBInstances{ &rds.DescribeDBInstances{
DBInstanceIdentifier: rs.ID, DBInstanceIdentifier: rs.Primary.ID,
}) })
if err == nil { if err == nil {
if len(resp.DBInstances) != 0 && if len(resp.DBInstances) != 0 &&
resp.DBInstances[0].DBInstanceIdentifier == rs.ID { resp.DBInstances[0].DBInstanceIdentifier == rs.Primary.ID {
return fmt.Errorf("DB Instance still exists") return fmt.Errorf("DB Instance still exists")
} }
} }
@ -104,19 +104,19 @@ func testAccCheckAWSDBInstanceAttributes(v *rds.DBInstance) resource.TestCheckFu
func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestCheckFunc { func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No DB Instance ID is set") return fmt.Errorf("No DB Instance ID is set")
} }
conn := testAccProvider.rdsconn conn := testAccProvider.rdsconn
opts := rds.DescribeDBInstances{ opts := rds.DescribeDBInstances{
DBInstanceIdentifier: rs.ID, DBInstanceIdentifier: rs.Primary.ID,
} }
resp, err := conn.DescribeDBInstances(&opts) resp, err := conn.DescribeDBInstances(&opts)
@ -126,7 +126,7 @@ func testAccCheckAWSDBInstanceExists(n string, v *rds.DBInstance) resource.TestC
} }
if len(resp.DBInstances) != 1 || if len(resp.DBInstances) != 1 ||
resp.DBInstances[0].DBInstanceIdentifier != rs.ID { resp.DBInstances[0].DBInstanceIdentifier != rs.Primary.ID {
return fmt.Errorf("DB Instance not found") return fmt.Errorf("DB Instance not found")
} }

View File

@ -15,9 +15,9 @@ import (
) )
func resource_aws_db_security_group_create( func resource_aws_db_security_group_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
conn := p.rdsconn conn := p.rdsconn
@ -85,14 +85,14 @@ func resource_aws_db_security_group_create(
} }
func resource_aws_db_security_group_update( func resource_aws_db_security_group_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
panic("Cannot update DB security group") panic("Cannot update DB security group")
} }
func resource_aws_db_security_group_destroy( func resource_aws_db_security_group_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
conn := p.rdsconn conn := p.rdsconn
@ -116,8 +116,8 @@ func resource_aws_db_security_group_destroy(
} }
func resource_aws_db_security_group_refresh( func resource_aws_db_security_group_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
conn := p.rdsconn conn := p.rdsconn
@ -131,7 +131,7 @@ func resource_aws_db_security_group_refresh(
} }
func resource_aws_db_security_group_diff( func resource_aws_db_security_group_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
@ -152,8 +152,8 @@ func resource_aws_db_security_group_diff(
} }
func resource_aws_db_security_group_update_state( func resource_aws_db_security_group_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
v *rds.DBSecurityGroup) (*terraform.ResourceState, error) { v *rds.DBSecurityGroup) (*terraform.InstanceState, error) {
s.Attributes["name"] = v.Name s.Attributes["name"] = v.Name
s.Attributes["description"] = v.Description s.Attributes["description"] = v.Description

View File

@ -39,7 +39,7 @@ func TestAccAWSDBSecurityGroup(t *testing.T) {
func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error { func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
conn := testAccProvider.rdsconn conn := testAccProvider.rdsconn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_db_security_group" { if rs.Type != "aws_db_security_group" {
continue continue
} }
@ -47,12 +47,12 @@ func testAccCheckAWSDBSecurityGroupDestroy(s *terraform.State) error {
// Try to find the Group // Try to find the Group
resp, err := conn.DescribeDBSecurityGroups( resp, err := conn.DescribeDBSecurityGroups(
&rds.DescribeDBSecurityGroups{ &rds.DescribeDBSecurityGroups{
DBSecurityGroupName: rs.ID, DBSecurityGroupName: rs.Primary.ID,
}) })
if err == nil { if err == nil {
if len(resp.DBSecurityGroups) != 0 && if len(resp.DBSecurityGroups) != 0 &&
resp.DBSecurityGroups[0].Name == rs.ID { resp.DBSecurityGroups[0].Name == rs.Primary.ID {
return fmt.Errorf("DB Security Group still exists") return fmt.Errorf("DB Security Group still exists")
} }
} }
@ -98,19 +98,19 @@ func testAccCheckAWSDBSecurityGroupAttributes(group *rds.DBSecurityGroup) resour
func testAccCheckAWSDBSecurityGroupExists(n string, v *rds.DBSecurityGroup) resource.TestCheckFunc { func testAccCheckAWSDBSecurityGroupExists(n string, v *rds.DBSecurityGroup) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No DB Security Group ID is set") return fmt.Errorf("No DB Security Group ID is set")
} }
conn := testAccProvider.rdsconn conn := testAccProvider.rdsconn
opts := rds.DescribeDBSecurityGroups{ opts := rds.DescribeDBSecurityGroups{
DBSecurityGroupName: rs.ID, DBSecurityGroupName: rs.Primary.ID,
} }
resp, err := conn.DescribeDBSecurityGroups(&opts) resp, err := conn.DescribeDBSecurityGroups(&opts)
@ -120,7 +120,7 @@ func testAccCheckAWSDBSecurityGroupExists(n string, v *rds.DBSecurityGroup) reso
} }
if len(resp.DBSecurityGroups) != 1 || if len(resp.DBSecurityGroups) != 1 ||
resp.DBSecurityGroups[0].Name != rs.ID { resp.DBSecurityGroups[0].Name != rs.Primary.ID {
return fmt.Errorf("DB Security Group not found") return fmt.Errorf("DB Security Group not found")
} }

View File

@ -59,16 +59,16 @@ func TestAccAWSEIP_instance(t *testing.T) {
func testAccCheckAWSEIPDestroy(s *terraform.State) error { func testAccCheckAWSEIPDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_eip" { if rs.Type != "aws_eip" {
continue continue
} }
describe, err := conn.Addresses([]string{rs.ID}, []string{}, nil) describe, err := conn.Addresses([]string{rs.Primary.ID}, []string{}, nil)
if err == nil { if err == nil {
if len(describe.Addresses) != 0 && if len(describe.Addresses) != 0 &&
describe.Addresses[0].PublicIp == rs.ID { describe.Addresses[0].PublicIp == rs.Primary.ID {
return fmt.Errorf("EIP still exists") return fmt.Errorf("EIP still exists")
} }
} }
@ -103,37 +103,37 @@ func testAccCheckAWSEIPAttributes(conf *ec2.Address) resource.TestCheckFunc {
func testAccCheckAWSEIPExists(n string, res *ec2.Address) resource.TestCheckFunc { func testAccCheckAWSEIPExists(n string, res *ec2.Address) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No EIP ID is set") return fmt.Errorf("No EIP ID is set")
} }
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
if strings.Contains(rs.ID, "eipalloc") { if strings.Contains(rs.Primary.ID, "eipalloc") {
describe, err := conn.Addresses([]string{}, []string{rs.ID}, nil) describe, err := conn.Addresses([]string{}, []string{rs.Primary.ID}, nil)
if err != nil { if err != nil {
return err return err
} }
if len(describe.Addresses) != 1 || if len(describe.Addresses) != 1 ||
describe.Addresses[0].AllocationId != rs.ID { describe.Addresses[0].AllocationId != rs.Primary.ID {
return fmt.Errorf("EIP not found") return fmt.Errorf("EIP not found")
} }
*res = describe.Addresses[0] *res = describe.Addresses[0]
} else { } else {
describe, err := conn.Addresses([]string{rs.ID}, []string{}, nil) describe, err := conn.Addresses([]string{rs.Primary.ID}, []string{}, nil)
if err != nil { if err != nil {
return err return err
} }
if len(describe.Addresses) != 1 || if len(describe.Addresses) != 1 ||
describe.Addresses[0].PublicIp != rs.ID { describe.Addresses[0].PublicIp != rs.Primary.ID {
return fmt.Errorf("EIP not found") return fmt.Errorf("EIP not found")
} }
*res = describe.Addresses[0] *res = describe.Addresses[0]

View File

@ -13,9 +13,9 @@ import (
) )
func resource_aws_elb_create( func resource_aws_elb_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
elbconn := p.elbconn elbconn := p.elbconn
@ -124,9 +124,9 @@ func resource_aws_elb_create(
} }
func resource_aws_elb_update( func resource_aws_elb_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
elbconn := p.elbconn elbconn := p.elbconn
@ -214,7 +214,7 @@ func resource_aws_elb_update(
} }
func resource_aws_elb_destroy( func resource_aws_elb_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
elbconn := p.elbconn elbconn := p.elbconn
@ -235,8 +235,8 @@ func resource_aws_elb_destroy(
} }
func resource_aws_elb_refresh( func resource_aws_elb_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
elbconn := p.elbconn elbconn := p.elbconn
@ -249,7 +249,7 @@ func resource_aws_elb_refresh(
} }
func resource_aws_elb_diff( func resource_aws_elb_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
@ -273,8 +273,8 @@ func resource_aws_elb_diff(
} }
func resource_aws_elb_update_state( func resource_aws_elb_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
balancer *elb.LoadBalancer) (*terraform.ResourceState, error) { balancer *elb.LoadBalancer) (*terraform.InstanceState, error) {
s.Attributes["name"] = balancer.LoadBalancerName s.Attributes["name"] = balancer.LoadBalancerName
s.Attributes["dns_name"] = balancer.DNSName s.Attributes["dns_name"] = balancer.DNSName

View File

@ -112,18 +112,18 @@ func TestAccAWSELB_HealthCheck(t *testing.T) {
func testAccCheckAWSELBDestroy(s *terraform.State) error { func testAccCheckAWSELBDestroy(s *terraform.State) error {
conn := testAccProvider.elbconn conn := testAccProvider.elbconn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_elb" { if rs.Type != "aws_elb" {
continue continue
} }
describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancer{ describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancer{
Names: []string{rs.ID}, Names: []string{rs.Primary.ID},
}) })
if err == nil { if err == nil {
if len(describe.LoadBalancers) != 0 && if len(describe.LoadBalancers) != 0 &&
describe.LoadBalancers[0].LoadBalancerName == rs.ID { describe.LoadBalancers[0].LoadBalancerName == rs.Primary.ID {
return fmt.Errorf("ELB still exists") return fmt.Errorf("ELB still exists")
} }
} }
@ -209,19 +209,19 @@ func testAccCheckAWSELBAttributesHealthCheck(conf *elb.LoadBalancer) resource.Te
func testAccCheckAWSELBExists(n string, res *elb.LoadBalancer) resource.TestCheckFunc { func testAccCheckAWSELBExists(n string, res *elb.LoadBalancer) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No ELB ID is set") return fmt.Errorf("No ELB ID is set")
} }
conn := testAccProvider.elbconn conn := testAccProvider.elbconn
describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancer{ describe, err := conn.DescribeLoadBalancers(&elb.DescribeLoadBalancer{
Names: []string{rs.ID}, Names: []string{rs.Primary.ID},
}) })
if err != nil { if err != nil {
@ -229,7 +229,7 @@ func testAccCheckAWSELBExists(n string, res *elb.LoadBalancer) resource.TestChec
} }
if len(describe.LoadBalancers) != 1 || if len(describe.LoadBalancers) != 1 ||
describe.LoadBalancers[0].LoadBalancerName != rs.ID { describe.LoadBalancers[0].LoadBalancerName != rs.Primary.ID {
return fmt.Errorf("ELB not found") return fmt.Errorf("ELB not found")
} }

View File

@ -11,7 +11,6 @@ import (
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
) )
@ -315,8 +314,6 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("subnet_id", instance.SubnetId) d.Set("subnet_id", instance.SubnetId)
d.Set("ebs_optimized", instance.EbsOptimized) d.Set("ebs_optimized", instance.EbsOptimized)
var deps []terraform.ResourceDependency
// Determine whether we're referring to security groups with // Determine whether we're referring to security groups with
// IDs or names. We use a heuristic to figure this out. By default, // IDs or names. We use a heuristic to figure this out. By default,
// we use IDs if we're in a VPC. However, if we previously had an // we use IDs if we're in a VPC. However, if we previously had an
@ -343,17 +340,9 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
} else { } else {
sgs[i] = sg.Name sgs[i] = sg.Name
} }
deps = append(deps, terraform.ResourceDependency{ID: sg.Id})
} }
d.Set("security_groups", sgs) d.Set("security_groups", sgs)
// If we're in a VPC, we depend on the subnet
if instance.SubnetId != "" {
deps = append(deps, terraform.ResourceDependency{ID: instance.SubnetId})
}
d.SetDependencies(deps)
return nil return nil
} }

View File

@ -125,14 +125,14 @@ func TestAccAWSInstance_vpc(t *testing.T) {
func testAccCheckInstanceDestroy(s *terraform.State) error { func testAccCheckInstanceDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_instance" { if rs.Type != "aws_instance" {
continue continue
} }
// Try to find the resource // Try to find the resource
resp, err := conn.Instances( resp, err := conn.Instances(
[]string{rs.ID}, ec2.NewFilter()) []string{rs.Primary.ID}, ec2.NewFilter())
if err == nil { if err == nil {
if len(resp.Reservations) > 0 { if len(resp.Reservations) > 0 {
return fmt.Errorf("still exist.") return fmt.Errorf("still exist.")
@ -156,18 +156,18 @@ func testAccCheckInstanceDestroy(s *terraform.State) error {
func testAccCheckInstanceExists(n string, i *ec2.Instance) resource.TestCheckFunc { func testAccCheckInstanceExists(n string, i *ec2.Instance) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set") return fmt.Errorf("No ID is set")
} }
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
resp, err := conn.Instances( resp, err := conn.Instances(
[]string{rs.ID}, ec2.NewFilter()) []string{rs.Primary.ID}, ec2.NewFilter())
if err != nil { if err != nil {
return err return err
} }

View File

@ -12,9 +12,9 @@ import (
) )
func resource_aws_internet_gateway_create( func resource_aws_internet_gateway_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -35,9 +35,9 @@ func resource_aws_internet_gateway_create(
} }
func resource_aws_internet_gateway_update( func resource_aws_internet_gateway_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -70,7 +70,7 @@ func resource_aws_internet_gateway_update(
} }
func resource_aws_internet_gateway_destroy( func resource_aws_internet_gateway_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -108,8 +108,8 @@ func resource_aws_internet_gateway_destroy(
} }
func resource_aws_internet_gateway_refresh( func resource_aws_internet_gateway_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -126,7 +126,7 @@ func resource_aws_internet_gateway_refresh(
} }
func resource_aws_internet_gateway_diff( func resource_aws_internet_gateway_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
b := &diff.ResourceBuilder{ b := &diff.ResourceBuilder{
@ -140,7 +140,7 @@ func resource_aws_internet_gateway_diff(
func resource_aws_internet_gateway_attach( func resource_aws_internet_gateway_attach(
ec2conn *ec2.EC2, ec2conn *ec2.EC2,
s *terraform.ResourceState, s *terraform.InstanceState,
vpcId string) error { vpcId string) error {
log.Printf( log.Printf(
"[INFO] Attaching Internet Gateway '%s' to VPC '%s'", "[INFO] Attaching Internet Gateway '%s' to VPC '%s'",
@ -170,7 +170,7 @@ func resource_aws_internet_gateway_attach(
func resource_aws_internet_gateway_detach( func resource_aws_internet_gateway_detach(
ec2conn *ec2.EC2, ec2conn *ec2.EC2,
s *terraform.ResourceState) error { s *terraform.InstanceState) error {
if s.Attributes["vpc_id"] == "" { if s.Attributes["vpc_id"] == "" {
return nil return nil
} }
@ -222,15 +222,8 @@ func resource_aws_internet_gateway_detach(
} }
func resource_aws_internet_gateway_update_state( func resource_aws_internet_gateway_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
ig *ec2.InternetGateway) (*terraform.ResourceState, error) { ig *ec2.InternetGateway) (*terraform.InstanceState, error) {
if s.Attributes["vpc_id"] != "" {
// We belong to a VPC
s.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: s.Attributes["vpc_id"]},
}
}
return s, nil return s, nil
} }

View File

@ -57,14 +57,14 @@ func TestAccAWSInternetGateway(t *testing.T) {
func testAccCheckInternetGatewayDestroy(s *terraform.State) error { func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_internet_gateway" { if rs.Type != "aws_internet_gateway" {
continue continue
} }
// Try to find the resource // Try to find the resource
resp, err := conn.DescribeInternetGateways( resp, err := conn.DescribeInternetGateways(
[]string{rs.ID}, ec2.NewFilter()) []string{rs.Primary.ID}, ec2.NewFilter())
if err == nil { if err == nil {
if len(resp.InternetGateways) > 0 { if len(resp.InternetGateways) > 0 {
return fmt.Errorf("still exist.") return fmt.Errorf("still exist.")
@ -88,18 +88,18 @@ func testAccCheckInternetGatewayDestroy(s *terraform.State) error {
func testAccCheckInternetGatewayExists(n string, ig *ec2.InternetGateway) resource.TestCheckFunc { func testAccCheckInternetGatewayExists(n string, ig *ec2.InternetGateway) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set") return fmt.Errorf("No ID is set")
} }
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
resp, err := conn.DescribeInternetGateways( resp, err := conn.DescribeInternetGateways(
[]string{rs.ID}, ec2.NewFilter()) []string{rs.Primary.ID}, ec2.NewFilter())
if err != nil { if err != nil {
return err return err
} }

View File

@ -12,9 +12,9 @@ import (
) )
func resource_aws_launch_configuration_create( func resource_aws_launch_configuration_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn autoscalingconn := p.autoscalingconn
@ -75,14 +75,14 @@ func resource_aws_launch_configuration_create(
} }
func resource_aws_launch_configuration_update( func resource_aws_launch_configuration_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
panic("Update for AWS Launch Configuration is not supported") panic("Update for AWS Launch Configuration is not supported")
} }
func resource_aws_launch_configuration_destroy( func resource_aws_launch_configuration_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn autoscalingconn := p.autoscalingconn
@ -103,8 +103,8 @@ func resource_aws_launch_configuration_destroy(
} }
func resource_aws_launch_configuration_refresh( func resource_aws_launch_configuration_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn autoscalingconn := p.autoscalingconn
@ -118,7 +118,7 @@ func resource_aws_launch_configuration_refresh(
} }
func resource_aws_launch_configuration_diff( func resource_aws_launch_configuration_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
@ -142,8 +142,8 @@ func resource_aws_launch_configuration_diff(
} }
func resource_aws_launch_configuration_update_state( func resource_aws_launch_configuration_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
lc *autoscaling.LaunchConfiguration) (*terraform.ResourceState, error) { lc *autoscaling.LaunchConfiguration) (*terraform.InstanceState, error) {
s.Attributes["image_id"] = lc.ImageId s.Attributes["image_id"] = lc.ImageId
s.Attributes["instance_type"] = lc.InstanceType s.Attributes["instance_type"] = lc.InstanceType

View File

@ -40,19 +40,19 @@ func TestAccAWSLaunchConfiguration(t *testing.T) {
func testAccCheckAWSLaunchConfigurationDestroy(s *terraform.State) error { func testAccCheckAWSLaunchConfigurationDestroy(s *terraform.State) error {
conn := testAccProvider.autoscalingconn conn := testAccProvider.autoscalingconn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_launch_configuration" { if rs.Type != "aws_launch_configuration" {
continue continue
} }
describe, err := conn.DescribeLaunchConfigurations( describe, err := conn.DescribeLaunchConfigurations(
&autoscaling.DescribeLaunchConfigurations{ &autoscaling.DescribeLaunchConfigurations{
Names: []string{rs.ID}, Names: []string{rs.Primary.ID},
}) })
if err == nil { if err == nil {
if len(describe.LaunchConfigurations) != 0 && if len(describe.LaunchConfigurations) != 0 &&
describe.LaunchConfigurations[0].Name == rs.ID { describe.LaunchConfigurations[0].Name == rs.Primary.ID {
return fmt.Errorf("Launch Configuration still exists") return fmt.Errorf("Launch Configuration still exists")
} }
} }
@ -94,19 +94,19 @@ func testAccCheckAWSLaunchConfigurationAttributes(conf *autoscaling.LaunchConfig
func testAccCheckAWSLaunchConfigurationExists(n string, res *autoscaling.LaunchConfiguration) resource.TestCheckFunc { func testAccCheckAWSLaunchConfigurationExists(n string, res *autoscaling.LaunchConfiguration) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No Launch Configuration ID is set") return fmt.Errorf("No Launch Configuration ID is set")
} }
conn := testAccProvider.autoscalingconn conn := testAccProvider.autoscalingconn
describeOpts := autoscaling.DescribeLaunchConfigurations{ describeOpts := autoscaling.DescribeLaunchConfigurations{
Names: []string{rs.ID}, Names: []string{rs.Primary.ID},
} }
describe, err := conn.DescribeLaunchConfigurations(&describeOpts) describe, err := conn.DescribeLaunchConfigurations(&describeOpts)
@ -115,7 +115,7 @@ func testAccCheckAWSLaunchConfigurationExists(n string, res *autoscaling.LaunchC
} }
if len(describe.LaunchConfigurations) != 1 || if len(describe.LaunchConfigurations) != 1 ||
describe.LaunchConfigurations[0].Name != rs.ID { describe.LaunchConfigurations[0].Name != rs.Primary.ID {
return fmt.Errorf("Launch Configuration Group not found") return fmt.Errorf("Launch Configuration Group not found")
} }

View File

@ -28,9 +28,9 @@ func resource_aws_r53_record_validation() *config.Validator {
} }
func resource_aws_r53_record_create( func resource_aws_r53_record_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
conn := p.route53 conn := p.route53
@ -87,9 +87,6 @@ func resource_aws_r53_record_create(
// Generate an ID // Generate an ID
rs.ID = fmt.Sprintf("%s_%s_%s", zone, rs.Attributes["name"], rs.Attributes["type"]) rs.ID = fmt.Sprintf("%s_%s_%s", zone, rs.Attributes["name"], rs.Attributes["type"])
rs.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: zone},
}
// Wait until we are done // Wait until we are done
wait = resource.StateChangeConf{ wait = resource.StateChangeConf{
@ -109,7 +106,7 @@ func resource_aws_r53_record_create(
return rs, nil return rs, nil
} }
func resource_aws_r53_build_record_set(s *terraform.ResourceState) (*route53.ResourceRecordSet, error) { func resource_aws_r53_build_record_set(s *terraform.InstanceState) (*route53.ResourceRecordSet, error) {
// Parse the TTL // Parse the TTL
ttl, err := strconv.ParseInt(s.Attributes["ttl"], 10, 32) ttl, err := strconv.ParseInt(s.Attributes["ttl"], 10, 32)
if err != nil { if err != nil {
@ -133,7 +130,7 @@ func resource_aws_r53_build_record_set(s *terraform.ResourceState) (*route53.Res
} }
func resource_aws_r53_record_destroy( func resource_aws_r53_record_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
conn := p.route53 conn := p.route53
@ -185,8 +182,8 @@ func resource_aws_r53_record_destroy(
} }
func resource_aws_r53_record_refresh( func resource_aws_r53_record_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
conn := p.route53 conn := p.route53
@ -221,7 +218,7 @@ func resource_aws_r53_record_refresh(
} }
func resource_aws_r53_record_update_state( func resource_aws_r53_record_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
rec *route53.ResourceRecordSet) { rec *route53.ResourceRecordSet) {
flatRec := flatmap.Flatten(map[string]interface{}{ flatRec := flatmap.Flatten(map[string]interface{}{
@ -235,7 +232,7 @@ func resource_aws_r53_record_update_state(
} }
func resource_aws_r53_record_diff( func resource_aws_r53_record_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
b := &diff.ResourceBuilder{ b := &diff.ResourceBuilder{

View File

@ -28,12 +28,12 @@ func TestAccRoute53Record(t *testing.T) {
func testAccCheckRoute53RecordDestroy(s *terraform.State) error { func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
conn := testAccProvider.route53 conn := testAccProvider.route53
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route53_record" { if rs.Type != "aws_route53_record" {
continue continue
} }
parts := strings.Split(rs.ID, "_") parts := strings.Split(rs.Primary.ID, "_")
zone := parts[0] zone := parts[0]
name := parts[1] name := parts[1]
rType := parts[2] rType := parts[2]
@ -57,16 +57,16 @@ func testAccCheckRoute53RecordDestroy(s *terraform.State) error {
func testAccCheckRoute53RecordExists(n string) resource.TestCheckFunc { func testAccCheckRoute53RecordExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
conn := testAccProvider.route53 conn := testAccProvider.route53
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No hosted zone ID is set") return fmt.Errorf("No hosted zone ID is set")
} }
parts := strings.Split(rs.ID, "_") parts := strings.Split(rs.Primary.ID, "_")
zone := parts[0] zone := parts[0]
name := parts[1] name := parts[1]
rType := parts[2] rType := parts[2]

View File

@ -21,9 +21,9 @@ func resource_aws_r53_zone_validation() *config.Validator {
} }
func resource_aws_r53_zone_create( func resource_aws_r53_zone_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
r53 := p.route53 r53 := p.route53
@ -74,7 +74,7 @@ func resource_aws_r53_wait(r53 *route53.Route53, ref string) (result interface{}
} }
func resource_aws_r53_zone_destroy( func resource_aws_r53_zone_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
r53 := p.route53 r53 := p.route53
@ -89,8 +89,8 @@ func resource_aws_r53_zone_destroy(
} }
func resource_aws_r53_zone_refresh( func resource_aws_r53_zone_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
r53 := p.route53 r53 := p.route53
@ -107,7 +107,7 @@ func resource_aws_r53_zone_refresh(
} }
func resource_aws_r53_zone_diff( func resource_aws_r53_zone_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {

View File

@ -26,12 +26,12 @@ func TestAccRoute53Zone(t *testing.T) {
func testAccCheckRoute53ZoneDestroy(s *terraform.State) error { func testAccCheckRoute53ZoneDestroy(s *terraform.State) error {
conn := testAccProvider.route53 conn := testAccProvider.route53
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route53_zone" { if rs.Type != "aws_route53_zone" {
continue continue
} }
_, err := conn.GetHostedZone(rs.ID) _, err := conn.GetHostedZone(rs.Primary.ID)
if err == nil { if err == nil {
return fmt.Errorf("Hosted zone still exists") return fmt.Errorf("Hosted zone still exists")
} }
@ -41,17 +41,17 @@ func testAccCheckRoute53ZoneDestroy(s *terraform.State) error {
func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc { func testAccCheckRoute53ZoneExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No hosted zone ID is set") return fmt.Errorf("No hosted zone ID is set")
} }
conn := testAccProvider.route53 conn := testAccProvider.route53
_, err := conn.GetHostedZone(rs.ID) _, err := conn.GetHostedZone(rs.Primary.ID)
if err != nil { if err != nil {
return fmt.Errorf("Hosted zone err: %v", err) return fmt.Errorf("Hosted zone err: %v", err)
} }

View File

@ -14,9 +14,9 @@ import (
) )
func resource_aws_route_table_create( func resource_aws_route_table_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -56,9 +56,9 @@ func resource_aws_route_table_create(
} }
func resource_aws_route_table_update( func resource_aws_route_table_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -133,7 +133,7 @@ func resource_aws_route_table_update(
} }
func resource_aws_route_table_destroy( func resource_aws_route_table_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -188,8 +188,8 @@ func resource_aws_route_table_destroy(
} }
func resource_aws_route_table_refresh( func resource_aws_route_table_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -206,7 +206,7 @@ func resource_aws_route_table_refresh(
} }
func resource_aws_route_table_diff( func resource_aws_route_table_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
b := &diff.ResourceBuilder{ b := &diff.ResourceBuilder{
@ -220,15 +220,10 @@ func resource_aws_route_table_diff(
} }
func resource_aws_route_table_update_state( func resource_aws_route_table_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
rt *ec2.RouteTable) (*terraform.ResourceState, error) { rt *ec2.RouteTable) (*terraform.InstanceState, error) {
s.Attributes["vpc_id"] = rt.VpcId s.Attributes["vpc_id"] = rt.VpcId
// We belong to a VPC
s.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: rt.VpcId},
}
return s, nil return s, nil
} }

View File

@ -10,9 +10,9 @@ import (
) )
func resource_aws_route_table_association_create( func resource_aws_route_table_association_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
rs := s.MergeDiff(d) rs := s.MergeDiff(d)
@ -32,17 +32,13 @@ func resource_aws_route_table_association_create(
rs.ID = resp.AssociationId rs.ID = resp.AssociationId
log.Printf("[INFO] Association ID: %s", rs.ID) log.Printf("[INFO] Association ID: %s", rs.ID)
rs.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: rs.Attributes["route_table_id"]},
}
return rs, nil return rs, nil
} }
func resource_aws_route_table_association_update( func resource_aws_route_table_association_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -68,15 +64,11 @@ func resource_aws_route_table_association_update(
rs.ID = resp.AssociationId rs.ID = resp.AssociationId
log.Printf("[INFO] Association ID: %s", rs.ID) log.Printf("[INFO] Association ID: %s", rs.ID)
rs.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: rs.Attributes["route_table_id"]},
}
return rs, nil return rs, nil
} }
func resource_aws_route_table_association_destroy( func resource_aws_route_table_association_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -95,8 +87,8 @@ func resource_aws_route_table_association_destroy(
} }
func resource_aws_route_table_association_refresh( func resource_aws_route_table_association_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -128,7 +120,7 @@ func resource_aws_route_table_association_refresh(
} }
func resource_aws_route_table_association_diff( func resource_aws_route_table_association_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
b := &diff.ResourceBuilder{ b := &diff.ResourceBuilder{

View File

@ -39,14 +39,14 @@ func TestAccAWSRouteTableAssociation(t *testing.T) {
func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error { func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route_table_association" { if rs.Type != "aws_route_table_association" {
continue continue
} }
// Try to find the resource // Try to find the resource
resp, err := conn.DescribeRouteTables( resp, err := conn.DescribeRouteTables(
[]string{rs.Attributes["route_table_Id"]}, ec2.NewFilter()) []string{rs.Primary.Attributes["route_table_Id"]}, ec2.NewFilter())
if err != nil { if err != nil {
// Verify the error is what we want // Verify the error is what we want
ec2err, ok := err.(*ec2.Error) ec2err, ok := err.(*ec2.Error)
@ -72,18 +72,18 @@ func testAccCheckRouteTableAssociationDestroy(s *terraform.State) error {
func testAccCheckRouteTableAssociationExists(n string, v *ec2.RouteTable) resource.TestCheckFunc { func testAccCheckRouteTableAssociationExists(n string, v *ec2.RouteTable) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set") return fmt.Errorf("No ID is set")
} }
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
resp, err := conn.DescribeRouteTables( resp, err := conn.DescribeRouteTables(
[]string{rs.Attributes["route_table_id"]}, ec2.NewFilter()) []string{rs.Primary.Attributes["route_table_id"]}, ec2.NewFilter())
if err != nil { if err != nil {
return err return err
} }

View File

@ -124,14 +124,14 @@ func TestAccAWSRouteTable_instance(t *testing.T) {
func testAccCheckRouteTableDestroy(s *terraform.State) error { func testAccCheckRouteTableDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_route_table" { if rs.Type != "aws_route_table" {
continue continue
} }
// Try to find the resource // Try to find the resource
resp, err := conn.DescribeRouteTables( resp, err := conn.DescribeRouteTables(
[]string{rs.ID}, ec2.NewFilter()) []string{rs.Primary.ID}, ec2.NewFilter())
if err == nil { if err == nil {
if len(resp.RouteTables) > 0 { if len(resp.RouteTables) > 0 {
return fmt.Errorf("still exist.") return fmt.Errorf("still exist.")
@ -155,18 +155,18 @@ func testAccCheckRouteTableDestroy(s *terraform.State) error {
func testAccCheckRouteTableExists(n string, v *ec2.RouteTable) resource.TestCheckFunc { func testAccCheckRouteTableExists(n string, v *ec2.RouteTable) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set") return fmt.Errorf("No ID is set")
} }
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
resp, err := conn.DescribeRouteTables( resp, err := conn.DescribeRouteTables(
[]string{rs.ID}, ec2.NewFilter()) []string{rs.Primary.ID}, ec2.NewFilter())
if err != nil { if err != nil {
return err return err
} }

View File

@ -22,9 +22,9 @@ func resource_aws_s3_bucket_validation() *config.Validator {
} }
func resource_aws_s3_bucket_create( func resource_aws_s3_bucket_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
s3conn := p.s3conn s3conn := p.s3conn
@ -52,7 +52,7 @@ func resource_aws_s3_bucket_create(
} }
func resource_aws_s3_bucket_destroy( func resource_aws_s3_bucket_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
s3conn := p.s3conn s3conn := p.s3conn
@ -65,8 +65,8 @@ func resource_aws_s3_bucket_destroy(
} }
func resource_aws_s3_bucket_refresh( func resource_aws_s3_bucket_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
s3conn := p.s3conn s3conn := p.s3conn
@ -80,7 +80,7 @@ func resource_aws_s3_bucket_refresh(
} }
func resource_aws_s3_bucket_diff( func resource_aws_s3_bucket_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {

View File

@ -27,12 +27,12 @@ func TestAccAWSS3Bucket(t *testing.T) {
func testAccCheckAWSS3BucketDestroy(s *terraform.State) error { func testAccCheckAWSS3BucketDestroy(s *terraform.State) error {
conn := testAccProvider.s3conn conn := testAccProvider.s3conn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_s3_bucket" { if rs.Type != "aws_s3_bucket" {
continue continue
} }
bucket := conn.Bucket(rs.ID) bucket := conn.Bucket(rs.Primary.ID)
resp, err := bucket.Head("/") resp, err := bucket.Head("/")
if err == nil { if err == nil {
return fmt.Errorf("S3Bucket still exists") return fmt.Errorf("S3Bucket still exists")
@ -44,17 +44,17 @@ func testAccCheckAWSS3BucketDestroy(s *terraform.State) error {
func testAccCheckAWSS3BucketExists(n string) resource.TestCheckFunc { func testAccCheckAWSS3BucketExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No S3 Bucket ID is set") return fmt.Errorf("No S3 Bucket ID is set")
} }
conn := testAccProvider.s3conn conn := testAccProvider.s3conn
bucket := conn.Bucket(rs.ID) bucket := conn.Bucket(rs.Primary.ID)
resp, err := bucket.Head("/") resp, err := bucket.Head("/")
if err != nil { if err != nil {
return fmt.Errorf("S3Bucket error: %v", err) return fmt.Errorf("S3Bucket error: %v", err)

View File

@ -10,7 +10,6 @@ import (
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
) )
@ -271,8 +270,6 @@ func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) erro
sg := sgRaw.(*ec2.SecurityGroupInfo) sg := sgRaw.(*ec2.SecurityGroupInfo)
var deps []terraform.ResourceDependency
// Gather our ingress rules // Gather our ingress rules
ingressRules := make([]map[string]interface{}, len(sg.IPPerms)) ingressRules := make([]map[string]interface{}, len(sg.IPPerms))
for i, perm := range sg.IPPerms { for i, perm := range sg.IPPerms {
@ -286,31 +283,17 @@ func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) erro
} }
if len(perm.SourceGroups) > 0 { if len(perm.SourceGroups) > 0 {
// We depend on other security groups
for _, v := range perm.SourceGroups {
deps = append(deps,
terraform.ResourceDependency{ID: v.Id},
)
}
n["security_groups"] = flattenSecurityGroups(perm.SourceGroups) n["security_groups"] = flattenSecurityGroups(perm.SourceGroups)
} }
ingressRules[i] = n ingressRules[i] = n
} }
if v := d.Get("vpc_id"); v != nil && v.(string) != "" {
deps = append(deps,
terraform.ResourceDependency{ID: v.(string)},
)
}
d.Set("description", sg.Description) d.Set("description", sg.Description)
d.Set("name", sg.Name) d.Set("name", sg.Name)
d.Set("vpc_id", sg.VpcId) d.Set("vpc_id", sg.VpcId)
d.Set("owner_id", sg.OwnerId) d.Set("owner_id", sg.OwnerId)
d.Set("ingress", ingressRules) d.Set("ingress", ingressRules)
d.SetDependencies(deps)
return nil return nil
} }

View File

@ -131,22 +131,22 @@ func TestAccAWSSecurityGroup_Change(t *testing.T) {
func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error { func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_security_group" { if rs.Type != "aws_security_group" {
continue continue
} }
sgs := []ec2.SecurityGroup{ sgs := []ec2.SecurityGroup{
ec2.SecurityGroup{ ec2.SecurityGroup{
Id: rs.ID, Id: rs.Primary.ID,
}, },
} }
// Retrieve our group // Retrieve our group
resp, err := conn.SecurityGroups(sgs, nil) resp, err := conn.SecurityGroups(sgs, nil)
if err == nil { if err == nil {
if len(resp.Groups) > 0 && resp.Groups[0].Id == rs.ID { if len(resp.Groups) > 0 && resp.Groups[0].Id == rs.Primary.ID {
return fmt.Errorf("Security Group (%s) still exists.", rs.ID) return fmt.Errorf("Security Group (%s) still exists.", rs.Primary.ID)
} }
return nil return nil
@ -167,19 +167,19 @@ func testAccCheckAWSSecurityGroupDestroy(s *terraform.State) error {
func testAccCheckAWSSecurityGroupExists(n string, group *ec2.SecurityGroupInfo) resource.TestCheckFunc { func testAccCheckAWSSecurityGroupExists(n string, group *ec2.SecurityGroupInfo) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No Security Group is set") return fmt.Errorf("No Security Group is set")
} }
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
sgs := []ec2.SecurityGroup{ sgs := []ec2.SecurityGroup{
ec2.SecurityGroup{ ec2.SecurityGroup{
Id: rs.ID, Id: rs.Primary.ID,
}, },
} }
resp, err := conn.SecurityGroups(sgs, nil) resp, err := conn.SecurityGroups(sgs, nil)
@ -187,7 +187,7 @@ func testAccCheckAWSSecurityGroupExists(n string, group *ec2.SecurityGroupInfo)
return err return err
} }
if len(resp.Groups) > 0 && resp.Groups[0].Id == rs.ID { if len(resp.Groups) > 0 && resp.Groups[0].Id == rs.Primary.ID {
*group = resp.Groups[0] *group = resp.Groups[0]

View File

@ -12,9 +12,9 @@ import (
) )
func resource_aws_subnet_create( func resource_aws_subnet_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -60,16 +60,16 @@ func resource_aws_subnet_create(
} }
func resource_aws_subnet_update( func resource_aws_subnet_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
// This should never be called because we have no update-able // This should never be called because we have no update-able
// attributes // attributes
panic("Update for subnet is not supported") panic("Update for subnet is not supported")
} }
func resource_aws_subnet_destroy( func resource_aws_subnet_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -102,8 +102,8 @@ func resource_aws_subnet_destroy(
} }
func resource_aws_subnet_refresh( func resource_aws_subnet_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -120,7 +120,7 @@ func resource_aws_subnet_refresh(
} }
func resource_aws_subnet_diff( func resource_aws_subnet_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
b := &diff.ResourceBuilder{ b := &diff.ResourceBuilder{
@ -139,17 +139,12 @@ func resource_aws_subnet_diff(
} }
func resource_aws_subnet_update_state( func resource_aws_subnet_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
subnet *ec2.Subnet) (*terraform.ResourceState, error) { subnet *ec2.Subnet) (*terraform.InstanceState, error) {
s.Attributes["availability_zone"] = subnet.AvailabilityZone s.Attributes["availability_zone"] = subnet.AvailabilityZone
s.Attributes["cidr_block"] = subnet.CidrBlock s.Attributes["cidr_block"] = subnet.CidrBlock
s.Attributes["vpc_id"] = subnet.VpcId s.Attributes["vpc_id"] = subnet.VpcId
// We belong to a VPC
s.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: subnet.VpcId},
}
return s, nil return s, nil
} }

View File

@ -40,14 +40,14 @@ func TestAccAWSSubnet(t *testing.T) {
func testAccCheckSubnetDestroy(s *terraform.State) error { func testAccCheckSubnetDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_subnet" { if rs.Type != "aws_subnet" {
continue continue
} }
// Try to find the resource // Try to find the resource
resp, err := conn.DescribeSubnets( resp, err := conn.DescribeSubnets(
[]string{rs.ID}, ec2.NewFilter()) []string{rs.Primary.ID}, ec2.NewFilter())
if err == nil { if err == nil {
if len(resp.Subnets) > 0 { if len(resp.Subnets) > 0 {
return fmt.Errorf("still exist.") return fmt.Errorf("still exist.")
@ -71,18 +71,18 @@ func testAccCheckSubnetDestroy(s *terraform.State) error {
func testAccCheckSubnetExists(n string, v *ec2.Subnet) resource.TestCheckFunc { func testAccCheckSubnetExists(n string, v *ec2.Subnet) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set") return fmt.Errorf("No ID is set")
} }
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
resp, err := conn.DescribeSubnets( resp, err := conn.DescribeSubnets(
[]string{rs.ID}, ec2.NewFilter()) []string{rs.Primary.ID}, ec2.NewFilter())
if err != nil { if err != nil {
return err return err
} }

View File

@ -13,9 +13,9 @@ import (
) )
func resource_aws_vpc_create( func resource_aws_vpc_create(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -89,9 +89,9 @@ func resource_aws_vpc_create(
} }
func resource_aws_vpc_update( func resource_aws_vpc_update(
s *terraform.ResourceState, s *terraform.InstanceState,
d *terraform.ResourceDiff, d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
rs := s.MergeDiff(d) rs := s.MergeDiff(d)
@ -132,7 +132,7 @@ func resource_aws_vpc_update(
} }
func resource_aws_vpc_destroy( func resource_aws_vpc_destroy(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) error { meta interface{}) error {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -151,8 +151,8 @@ func resource_aws_vpc_destroy(
} }
func resource_aws_vpc_refresh( func resource_aws_vpc_refresh(
s *terraform.ResourceState, s *terraform.InstanceState,
meta interface{}) (*terraform.ResourceState, error) { meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider) p := meta.(*ResourceProvider)
ec2conn := p.ec2conn ec2conn := p.ec2conn
@ -180,7 +180,7 @@ func resource_aws_vpc_refresh(
} }
func resource_aws_vpc_diff( func resource_aws_vpc_diff(
s *terraform.ResourceState, s *terraform.InstanceState,
c *terraform.ResourceConfig, c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) { meta interface{}) (*terraform.ResourceDiff, error) {
b := &diff.ResourceBuilder{ b := &diff.ResourceBuilder{
@ -200,8 +200,8 @@ func resource_aws_vpc_diff(
} }
func resource_aws_vpc_update_state( func resource_aws_vpc_update_state(
s *terraform.ResourceState, s *terraform.InstanceState,
vpc *ec2.VPC) (*terraform.ResourceState, error) { vpc *ec2.VPC) (*terraform.InstanceState, error) {
s.Attributes["cidr_block"] = vpc.CidrBlock s.Attributes["cidr_block"] = vpc.CidrBlock
return s, nil return s, nil
} }

View File

@ -62,13 +62,13 @@ func TestAccVpcUpdate(t *testing.T) {
func testAccCheckVpcDestroy(s *terraform.State) error { func testAccCheckVpcDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
for _, rs := range s.Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_vpc" { if rs.Type != "aws_vpc" {
continue continue
} }
// Try to find the VPC // Try to find the VPC
resp, err := conn.DescribeVpcs([]string{rs.ID}, ec2.NewFilter()) resp, err := conn.DescribeVpcs([]string{rs.Primary.ID}, ec2.NewFilter())
if err == nil { if err == nil {
if len(resp.VPCs) > 0 { if len(resp.VPCs) > 0 {
return fmt.Errorf("VPCs still exist.") return fmt.Errorf("VPCs still exist.")
@ -102,17 +102,17 @@ func testAccCheckVpcCidr(vpc *ec2.VPC, expected string) resource.TestCheckFunc {
func testAccCheckVpcExists(n string, vpc *ec2.VPC) resource.TestCheckFunc { func testAccCheckVpcExists(n string, vpc *ec2.VPC) resource.TestCheckFunc {
return func(s *terraform.State) error { return func(s *terraform.State) error {
rs, ok := s.Resources[n] rs, ok := s.RootModule().Resources[n]
if !ok { if !ok {
return fmt.Errorf("Not found: %s", n) return fmt.Errorf("Not found: %s", n)
} }
if rs.ID == "" { if rs.Primary.ID == "" {
return fmt.Errorf("No VPC ID is set") return fmt.Errorf("No VPC ID is set")
} }
conn := testAccProvider.ec2conn conn := testAccProvider.ec2conn
resp, err := conn.DescribeVpcs([]string{rs.ID}, ec2.NewFilter()) resp, err := conn.DescribeVpcs([]string{rs.Primary.ID}, ec2.NewFilter())
if err != nil { if err != nil {
return err return err
} }

View File

@ -91,32 +91,35 @@ func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
} }
func (p *ResourceProvider) Apply( func (p *ResourceProvider) Apply(
s *terraform.ResourceState, info *terraform.InstanceInfo,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) { s *terraform.InstanceState,
if _, ok := p.p.ResourcesMap[s.Type]; ok { d *terraform.ResourceDiff) (*terraform.InstanceState, error) {
return p.p.Apply(s, d) if _, ok := p.p.ResourcesMap[info.Type]; ok {
return p.p.Apply(info, s, d)
} }
return resourceMap.Apply(s, d, p) return resourceMap.Apply(info, s, d, p)
} }
func (p *ResourceProvider) Diff( func (p *ResourceProvider) Diff(
s *terraform.ResourceState, info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) { c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
if _, ok := p.p.ResourcesMap[s.Type]; ok { if _, ok := p.p.ResourcesMap[info.Type]; ok {
return p.p.Diff(s, c) return p.p.Diff(info, s, c)
} }
return resourceMap.Diff(s, c, p) return resourceMap.Diff(info, s, c, p)
} }
func (p *ResourceProvider) Refresh( func (p *ResourceProvider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) { info *terraform.InstanceInfo,
if _, ok := p.p.ResourcesMap[s.Type]; ok { s *terraform.InstanceState) (*terraform.InstanceState, error) {
return p.p.Refresh(s) if _, ok := p.p.ResourcesMap[info.Type]; ok {
return p.p.Refresh(info, s)
} }
return resourceMap.Refresh(s, p) return resourceMap.Refresh(info, s, p)
} }
func (p *ResourceProvider) Resources() []terraform.ResourceType { func (p *ResourceProvider) Resources() []terraform.ResourceType {