Merge branch 'f-state'

Conflicts:
	builtin/providers/aws/resource_aws_subnet.go
This commit is contained in:
Mitchell Hashimoto 2014-09-22 08:55:44 -07:00
commit 166847d5dc
121 changed files with 3830 additions and 2001 deletions

View File

@ -13,9 +13,9 @@ import (
)
func resource_aws_autoscaling_group_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn
@ -81,9 +81,6 @@ func resource_aws_autoscaling_group_create(
}
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)
@ -96,9 +93,9 @@ func resource_aws_autoscaling_group_create(
}
func resource_aws_autoscaling_group_update(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn
rs := s.MergeDiff(d)
@ -141,7 +138,7 @@ func resource_aws_autoscaling_group_update(
}
func resource_aws_autoscaling_group_destroy(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn
@ -173,8 +170,8 @@ func resource_aws_autoscaling_group_destroy(
}
func resource_aws_autoscaling_group_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
autoscalingconn := p.autoscalingconn
@ -188,9 +185,9 @@ func resource_aws_autoscaling_group_refresh(
}
func resource_aws_autoscaling_group_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
@ -223,8 +220,8 @@ func resource_aws_autoscaling_group_diff(
}
func resource_aws_autoscaling_group_update_state(
s *terraform.ResourceState,
g *autoscaling.AutoScalingGroup) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
g *autoscaling.AutoScalingGroup) (*terraform.InstanceState, error) {
s.Attributes["min_size"] = strconv.Itoa(g.MinSize)
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 {
conn := testAccProvider.autoscalingconn
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_autoscaling_group" {
continue
}
@ -73,12 +73,12 @@ func testAccCheckAWSAutoScalingGroupDestroy(s *terraform.State) error {
// Try to find the Group
describeGroups, err := conn.DescribeAutoScalingGroups(
&autoscaling.DescribeAutoScalingGroups{
Names: []string{rs.ID},
Names: []string{rs.Primary.ID},
})
if err == nil {
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")
}
}
@ -146,19 +146,19 @@ func testAccCheckAWSAutoScalingGroupAttributesLoadBalancer(group *autoscaling.Au
func testAccCheckAWSAutoScalingGroupExists(n string, group *autoscaling.AutoScalingGroup) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No AutoScaling Group ID is set")
}
conn := testAccProvider.autoscalingconn
describeOpts := autoscaling.DescribeAutoScalingGroups{
Names: []string{rs.ID},
Names: []string{rs.Primary.ID},
}
describeGroups, err := conn.DescribeAutoScalingGroups(&describeOpts)
@ -167,7 +167,7 @@ func testAccCheckAWSAutoScalingGroupExists(n string, group *autoscaling.AutoScal
}
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")
}

View File

@ -16,9 +16,9 @@ import (
)
func resource_aws_db_instance_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
conn := p.rdsconn
@ -140,14 +140,14 @@ func resource_aws_db_instance_create(
}
func resource_aws_db_instance_update(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
panic("Cannot update DB")
}
func resource_aws_db_instance_destroy(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
conn := p.rdsconn
@ -188,8 +188,8 @@ func resource_aws_db_instance_destroy(
}
func resource_aws_db_instance_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
conn := p.rdsconn
@ -203,9 +203,9 @@ func resource_aws_db_instance_refresh(
}
func resource_aws_db_instance_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
@ -252,8 +252,8 @@ func resource_aws_db_instance_diff(
}
func resource_aws_db_instance_update_state(
s *terraform.ResourceState,
v *rds.DBInstance) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
v *rds.DBInstance) (*terraform.InstanceState, error) {
s.Attributes["address"] = v.Address
s.Attributes["allocated_storage"] = strconv.Itoa(v.AllocatedStorage)
@ -285,13 +285,6 @@ func resource_aws_db_instance_update_state(
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
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,6 @@ import (
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/goamz/ec2"
)
@ -316,8 +315,6 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("subnet_id", instance.SubnetId)
d.Set("ebs_optimized", instance.EbsOptimized)
var deps []terraform.ResourceDependency
// Determine whether we're referring to security groups with
// 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
@ -344,17 +341,9 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
} else {
sgs[i] = sg.Name
}
deps = append(deps, terraform.ResourceDependency{ID: sg.Id})
}
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
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,9 +28,9 @@ func resource_aws_r53_record_validation() *config.Validator {
}
func resource_aws_r53_record_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
conn := p.route53
@ -87,9 +87,6 @@ func resource_aws_r53_record_create(
// Generate an ID
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 = resource.StateChangeConf{
@ -109,7 +106,7 @@ func resource_aws_r53_record_create(
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
ttl, err := strconv.ParseInt(s.Attributes["ttl"], 10, 32)
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(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
conn := p.route53
@ -185,8 +182,8 @@ func resource_aws_r53_record_destroy(
}
func resource_aws_r53_record_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
conn := p.route53
@ -221,7 +218,7 @@ func resource_aws_r53_record_refresh(
}
func resource_aws_r53_record_update_state(
s *terraform.ResourceState,
s *terraform.InstanceState,
rec *route53.ResourceRecordSet) {
flatRec := flatmap.Flatten(map[string]interface{}{
@ -235,9 +232,9 @@ func resource_aws_r53_record_update_state(
}
func resource_aws_r53_record_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
"zone_id": diff.AttrTypeCreate,

View File

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

View File

@ -21,9 +21,9 @@ func resource_aws_r53_zone_validation() *config.Validator {
}
func resource_aws_r53_zone_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
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(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
r53 := p.route53
@ -89,8 +89,8 @@ func resource_aws_r53_zone_destroy(
}
func resource_aws_r53_zone_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
r53 := p.route53
@ -107,9 +107,9 @@ func resource_aws_r53_zone_refresh(
}
func resource_aws_r53_zone_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,9 +22,9 @@ func resource_aws_s3_bucket_validation() *config.Validator {
}
func resource_aws_s3_bucket_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
s3conn := p.s3conn
@ -52,7 +52,7 @@ func resource_aws_s3_bucket_create(
}
func resource_aws_s3_bucket_destroy(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
s3conn := p.s3conn
@ -65,8 +65,8 @@ func resource_aws_s3_bucket_destroy(
}
func resource_aws_s3_bucket_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
s3conn := p.s3conn
@ -80,9 +80,9 @@ func resource_aws_s3_bucket_refresh(
}
func resource_aws_s3_bucket_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{

View File

@ -27,12 +27,12 @@ func TestAccAWSS3Bucket(t *testing.T) {
func testAccCheckAWSS3BucketDestroy(s *terraform.State) error {
conn := testAccProvider.s3conn
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_s3_bucket" {
continue
}
bucket := conn.Bucket(rs.ID)
bucket := conn.Bucket(rs.Primary.ID)
resp, err := bucket.Head("/")
if err == nil {
return fmt.Errorf("S3Bucket still exists")
@ -44,17 +44,17 @@ func testAccCheckAWSS3BucketDestroy(s *terraform.State) error {
func testAccCheckAWSS3BucketExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No S3 Bucket ID is set")
}
conn := testAccProvider.s3conn
bucket := conn.Bucket(rs.ID)
bucket := conn.Bucket(rs.Primary.ID)
resp, err := bucket.Head("/")
if err != nil {
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/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/goamz/ec2"
)
@ -271,8 +270,6 @@ func resourceAwsSecurityGroupRead(d *schema.ResourceData, meta interface{}) erro
sg := sgRaw.(*ec2.SecurityGroupInfo)
var deps []terraform.ResourceDependency
// Gather our ingress rules
ingressRules := make([]map[string]interface{}, len(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 {
// 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)
}
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("name", sg.Name)
d.Set("vpc_id", sg.VpcId)
d.Set("owner_id", sg.OwnerId)
d.Set("ingress", ingressRules)
d.SetDependencies(deps)
return nil
}

View File

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

View File

@ -12,9 +12,9 @@ import (
)
func resource_aws_subnet_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
ec2conn := p.ec2conn
@ -73,16 +73,16 @@ func resource_aws_subnet_create(
}
func resource_aws_subnet_update(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
// This should never be called because we have no update-able
// attributes
panic("Update for subnet is not supported")
}
func resource_aws_subnet_destroy(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
ec2conn := p.ec2conn
@ -115,8 +115,8 @@ func resource_aws_subnet_destroy(
}
func resource_aws_subnet_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
ec2conn := p.ec2conn
@ -133,9 +133,9 @@ func resource_aws_subnet_refresh(
}
func resource_aws_subnet_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
"availability_zone": diff.AttrTypeCreate,
@ -153,21 +153,15 @@ func resource_aws_subnet_diff(
}
func resource_aws_subnet_update_state(
s *terraform.ResourceState,
subnet *ec2.Subnet) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
subnet *ec2.Subnet) (*terraform.InstanceState, error) {
s.Attributes["availability_zone"] = subnet.AvailabilityZone
s.Attributes["cidr_block"] = subnet.CidrBlock
s.Attributes["vpc_id"] = subnet.VpcId
if subnet.MapPublicIpOnLaunch {
s.Attributes["map_public_ip_on_launch"] = "true"
}
// We belong to a VPC
s.Dependencies = []terraform.ResourceDependency{
terraform.ResourceDependency{ID: subnet.VpcId},
}
return s, nil
}

View File

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

View File

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

View File

@ -62,13 +62,13 @@ func TestAccVpcUpdate(t *testing.T) {
func testAccCheckVpcDestroy(s *terraform.State) error {
conn := testAccProvider.ec2conn
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_vpc" {
continue
}
// 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 len(resp.VPCs) > 0 {
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 {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No VPC ID is set")
}
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 {
return err
}

View File

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

View File

@ -11,9 +11,9 @@ import (
)
func resource_cloudflare_record_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
@ -51,9 +51,9 @@ func resource_cloudflare_record_create(
}
func resource_cloudflare_record_update(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
rs := s.MergeDiff(d)
@ -86,7 +86,7 @@ func resource_cloudflare_record_update(
}
func resource_cloudflare_record_destroy(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
client := p.client
@ -103,8 +103,8 @@ func resource_cloudflare_record_destroy(
}
func resource_cloudflare_record_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
@ -117,9 +117,9 @@ func resource_cloudflare_record_refresh(
}
func resource_cloudflare_record_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
@ -144,8 +144,8 @@ func resource_cloudflare_record_diff(
}
func resource_cloudflare_record_update_state(
s *terraform.ResourceState,
rec *cloudflare.Record) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
rec *cloudflare.Record) (*terraform.InstanceState, error) {
s.Attributes["name"] = rec.Name
s.Attributes["value"] = rec.Value

View File

@ -78,12 +78,12 @@ func TestAccCLOudflareRecord_Updated(t *testing.T) {
func testAccCheckCLOudflareRecordDestroy(s *terraform.State) error {
client := testAccProvider.client
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "cloudflare_record" {
continue
}
_, err := client.RetrieveRecord(rs.Attributes["domain"], rs.ID)
_, err := client.RetrieveRecord(rs.Primary.Attributes["domain"], rs.Primary.ID)
if err == nil {
return fmt.Errorf("Record still exists")
@ -117,25 +117,25 @@ func testAccCheckCLOudflareRecordAttributesUpdated(record *cloudflare.Record) re
func testAccCheckCLOudflareRecordExists(n string, record *cloudflare.Record) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Record ID is set")
}
client := testAccProvider.client
foundRecord, err := client.RetrieveRecord(rs.Attributes["domain"], rs.ID)
foundRecord, err := client.RetrieveRecord(rs.Primary.Attributes["domain"], rs.Primary.ID)
if err != nil {
return err
}
if foundRecord.Id != rs.ID {
if foundRecord.Id != rs.Primary.ID {
return fmt.Errorf("Record not found")
}

View File

@ -47,20 +47,23 @@ func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
}
func (p *ResourceProvider) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
return resourceMap.Apply(s, d, p)
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
return resourceMap.Apply(info, s, d, p)
}
func (p *ResourceProvider) Diff(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
return resourceMap.Diff(s, c, p)
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
return resourceMap.Diff(info, s, c, p)
}
func (p *ResourceProvider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
return resourceMap.Refresh(s, p)
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
return resourceMap.Refresh(info, s, p)
}
func (p *ResourceProvider) Resources() []terraform.ResourceType {

View File

@ -27,16 +27,16 @@ func resource_consul_keys_validation() *config.Validator {
}
}
func resource_consul_keys_update(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
return resource_consul_keys_create(s, d, meta)
}
func resource_consul_keys_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
// Merge the diff into the state so that we have all the attributes
@ -97,7 +97,7 @@ func resource_consul_keys_create(
}
func resource_consul_keys_destroy(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
client := p.client
@ -132,9 +132,9 @@ func resource_consul_keys_destroy(
}
func resource_consul_keys_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
// Determine the list of computed variables
var computed []string
@ -162,8 +162,8 @@ AFTER:
}
func resource_consul_keys_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
kv := client.KV()

View File

@ -58,13 +58,13 @@ func testAccCheckConsulKeysExists() resource.TestCheckFunc {
func testAccCheckConsulKeysValue(n, attr, val string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rn, ok := s.Resources[n]
rn, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Resource not found")
}
out, ok := rn.Attributes["var."+attr]
out, ok := rn.Primary.Attributes["var."+attr]
if !ok {
return fmt.Errorf("Attribute '%s' not found: %#v", attr, rn.Attributes)
return fmt.Errorf("Attribute '%s' not found: %#v", attr, rn.Primary.Attributes)
}
if val != "<any>" && out != val {
return fmt.Errorf("Attribute '%s' value '%s' != '%s'", attr, out, val)

View File

@ -43,20 +43,23 @@ func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
}
func (p *ResourceProvider) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
return resourceMap.Apply(s, d, p)
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
return resourceMap.Apply(info, s, d, p)
}
func (p *ResourceProvider) Diff(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
return resourceMap.Diff(s, c, p)
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
return resourceMap.Diff(info, s, c, p)
}
func (p *ResourceProvider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
return resourceMap.Refresh(s, p)
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
return resourceMap.Refresh(info, s, p)
}
func (p *ResourceProvider) Resources() []terraform.ResourceType {

View File

@ -35,13 +35,13 @@ func TestAccDigitalOceanDomain_Basic(t *testing.T) {
func testAccCheckDigitalOceanDomainDestroy(s *terraform.State) error {
client := testAccProvider.client
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "digitalocean_domain" {
continue
}
// Try to find the domain
_, err := client.RetrieveDomain(rs.ID)
_, err := client.RetrieveDomain(rs.Primary.ID)
if err == nil {
fmt.Errorf("Domain still exists")
@ -64,25 +64,25 @@ func testAccCheckDigitalOceanDomainAttributes(domain *digitalocean.Domain) resou
func testAccCheckDigitalOceanDomainExists(n string, domain *digitalocean.Domain) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Record ID is set")
}
client := testAccProvider.client
foundDomain, err := client.RetrieveDomain(rs.ID)
foundDomain, err := client.RetrieveDomain(rs.Primary.ID)
if err != nil {
return err
}
if foundDomain.Name != rs.ID {
if foundDomain.Name != rs.Primary.ID {
return fmt.Errorf("Record not found")
}

View File

@ -15,9 +15,9 @@ import (
)
func resource_digitalocean_droplet_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
@ -83,16 +83,16 @@ func resource_digitalocean_droplet_create(
droplet := dropletRaw.(*digitalocean.Droplet)
// Initialize the connection info
rs.ConnInfo["type"] = "ssh"
rs.ConnInfo["host"] = droplet.IPV4Address("public")
rs.Ephemeral.ConnInfo["type"] = "ssh"
rs.Ephemeral.ConnInfo["host"] = droplet.IPV4Address("public")
return resource_digitalocean_droplet_update_state(rs, droplet)
}
func resource_digitalocean_droplet_update(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
rs := s.MergeDiff(d)
@ -193,7 +193,7 @@ func resource_digitalocean_droplet_update(
}
func resource_digitalocean_droplet_destroy(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
client := p.client
@ -216,8 +216,8 @@ func resource_digitalocean_droplet_destroy(
}
func resource_digitalocean_droplet_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
@ -236,9 +236,9 @@ func resource_digitalocean_droplet_refresh(
}
func resource_digitalocean_droplet_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
@ -270,8 +270,8 @@ func resource_digitalocean_droplet_diff(
}
func resource_digitalocean_droplet_update_state(
s *terraform.ResourceState,
droplet *digitalocean.Droplet) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
droplet *digitalocean.Droplet) (*terraform.InstanceState, error) {
s.Attributes["name"] = droplet.Name
s.Attributes["region"] = droplet.RegionSlug()
@ -372,7 +372,7 @@ func new_droplet_state_refresh_func(id string, attribute string, client *digital
// Use our mapping to get back a map of the
// droplet properties
resourceMap, err := resource_digitalocean_droplet_update_state(
&terraform.ResourceState{Attributes: map[string]string{}}, &droplet)
&terraform.InstanceState{Attributes: map[string]string{}}, &droplet)
if err != nil {
log.Printf("Error creating map from droplet: %s", err)

View File

@ -96,20 +96,20 @@ func TestAccDigitalOceanDroplet_PrivateNetworkingIpv6(t *testing.T) {
func testAccCheckDigitalOceanDropletDestroy(s *terraform.State) error {
client := testAccProvider.client
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "digitalocean_droplet" {
continue
}
// Try to find the Droplet
_, err := client.RetrieveDroplet(rs.ID)
_, err := client.RetrieveDroplet(rs.Primary.ID)
// Wait
if err != nil && !strings.Contains(err.Error(), "404") {
return fmt.Errorf(
"Error waiting for droplet (%s) to be destroyed: %s",
rs.ID, err)
rs.Primary.ID, err)
}
}
@ -198,24 +198,24 @@ func testAccCheckDigitalOceanDropletAttributes_PrivateNetworkingIpv6(droplet *di
func testAccCheckDigitalOceanDropletExists(n string, droplet *digitalocean.Droplet) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Droplet ID is set")
}
client := testAccProvider.client
retrieveDroplet, err := client.RetrieveDroplet(rs.ID)
retrieveDroplet, err := client.RetrieveDroplet(rs.Primary.ID)
if err != nil {
return err
}
if retrieveDroplet.StringId() != rs.ID {
if retrieveDroplet.StringId() != rs.Primary.ID {
return fmt.Errorf("Droplet not found")
}
@ -230,7 +230,7 @@ func Test_new_droplet_state_refresh_func(t *testing.T) {
Name: "foobar",
}
resourceMap, _ := resource_digitalocean_droplet_update_state(
&terraform.ResourceState{Attributes: map[string]string{}}, &droplet)
&terraform.InstanceState{Attributes: map[string]string{}}, &droplet)
// See if we can access our attribute
if _, ok := resourceMap.Attributes["name"]; !ok {

View File

@ -6,7 +6,6 @@ import (
"strings"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
"github.com/pearkes/digitalocean"
)
@ -152,10 +151,5 @@ func resourceRecordRead(d *schema.ResourceData, meta interface{}) error {
d.Set("priority", rec.StringPriority())
d.Set("port", rec.StringPort())
// We belong to a Domain
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: d.Get("domain").(string)},
})
return nil
}

View File

@ -79,12 +79,12 @@ func TestAccDigitalOceanRecord_Updated(t *testing.T) {
func testAccCheckDigitalOceanRecordDestroy(s *terraform.State) error {
client := testAccProvider.client
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "digitalocean_record" {
continue
}
_, err := client.RetrieveRecord(rs.Attributes["domain"], rs.ID)
_, err := client.RetrieveRecord(rs.Primary.Attributes["domain"], rs.Primary.ID)
if err == nil {
return fmt.Errorf("Record still exists")
@ -118,25 +118,25 @@ func testAccCheckDigitalOceanRecordAttributesUpdated(record *digitalocean.Record
func testAccCheckDigitalOceanRecordExists(n string, record *digitalocean.Record) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Record ID is set")
}
client := testAccProvider.client
foundRecord, err := client.RetrieveRecord(rs.Attributes["domain"], rs.ID)
foundRecord, err := client.RetrieveRecord(rs.Primary.Attributes["domain"], rs.Primary.ID)
if err != nil {
return err
}
if foundRecord.StringId() != rs.ID {
if foundRecord.StringId() != rs.Primary.ID {
return fmt.Errorf("Record not found")
}

View File

@ -55,32 +55,35 @@ func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
}
func (p *ResourceProvider) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
if _, ok := p.p.ResourcesMap[s.Type]; ok {
return p.p.Apply(s, d)
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
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(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
if _, ok := p.p.ResourcesMap[s.Type]; ok {
return p.p.Diff(s, c)
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
if _, ok := p.p.ResourcesMap[info.Type]; ok {
return p.p.Diff(info, s, c)
}
return resourceMap.Diff(s, c, p)
return resourceMap.Diff(info, s, c, p)
}
func (p *ResourceProvider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
if _, ok := p.p.ResourcesMap[s.Type]; ok {
return p.p.Refresh(s)
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
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 {

View File

@ -11,9 +11,9 @@ import (
)
func resource_dnsimple_record_create(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
@ -53,9 +53,9 @@ func resource_dnsimple_record_create(
}
func resource_dnsimple_record_update(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
rs := s.MergeDiff(d)
@ -94,7 +94,7 @@ func resource_dnsimple_record_update(
}
func resource_dnsimple_record_destroy(
s *terraform.ResourceState,
s *terraform.InstanceState,
meta interface{}) error {
p := meta.(*ResourceProvider)
client := p.client
@ -111,8 +111,8 @@ func resource_dnsimple_record_destroy(
}
func resource_dnsimple_record_refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
p := meta.(*ResourceProvider)
client := p.client
@ -125,9 +125,9 @@ func resource_dnsimple_record_refresh(
}
func resource_dnsimple_record_diff(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
meta interface{}) (*terraform.InstanceDiff, error) {
b := &diff.ResourceBuilder{
Attrs: map[string]diff.AttrType{
@ -153,8 +153,8 @@ func resource_dnsimple_record_diff(
}
func resource_dnsimple_record_update_state(
s *terraform.ResourceState,
rec *dnsimple.Record) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
rec *dnsimple.Record) (*terraform.InstanceState, error) {
s.Attributes["name"] = rec.Name
s.Attributes["value"] = rec.Content

View File

@ -78,12 +78,12 @@ func TestAccDNSimpleRecord_Updated(t *testing.T) {
func testAccCheckDNSimpleRecordDestroy(s *terraform.State) error {
client := testAccProvider.client
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "dnsimple_record" {
continue
}
_, err := client.RetrieveRecord(rs.Attributes["domain"], rs.ID)
_, err := client.RetrieveRecord(rs.Primary.Attributes["domain"], rs.Primary.ID)
if err == nil {
return fmt.Errorf("Record still exists")
@ -117,25 +117,25 @@ func testAccCheckDNSimpleRecordAttributesUpdated(record *dnsimple.Record) resour
func testAccCheckDNSimpleRecordExists(n string, record *dnsimple.Record) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Record ID is set")
}
client := testAccProvider.client
foundRecord, err := client.RetrieveRecord(rs.Attributes["domain"], rs.ID)
foundRecord, err := client.RetrieveRecord(rs.Primary.Attributes["domain"], rs.Primary.ID)
if err != nil {
return err
}
if foundRecord.StringId() != rs.ID {
if foundRecord.StringId() != rs.Primary.ID {
return fmt.Errorf("Record not found")
}

View File

@ -47,20 +47,23 @@ func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
}
func (p *ResourceProvider) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
return resourceMap.Apply(s, d, p)
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
return resourceMap.Apply(info, s, d, p)
}
func (p *ResourceProvider) Diff(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
return resourceMap.Diff(s, c, p)
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
return resourceMap.Diff(info, s, c, p)
}
func (p *ResourceProvider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
return resourceMap.Refresh(s, p)
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
return resourceMap.Refresh(info, s, p)
}
func (p *ResourceProvider) Resources() []terraform.ResourceType {

View File

@ -31,13 +31,13 @@ func TestAccComputeAddress_basic(t *testing.T) {
func testAccCheckComputeAddressDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_address" {
continue
}
_, err := config.clientCompute.Addresses.Get(
config.Project, config.Region, rs.ID).Do()
config.Project, config.Region, rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Address still exists")
}
@ -48,24 +48,24 @@ func testAccCheckComputeAddressDestroy(s *terraform.State) error {
func testAccCheckComputeAddressExists(n string, addr *compute.Address) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
found, err := config.clientCompute.Addresses.Get(
config.Project, config.Region, rs.ID).Do()
config.Project, config.Region, rs.Primary.ID).Do()
if err != nil {
return err
}
if found.Name != rs.ID {
if found.Name != rs.Primary.ID {
return fmt.Errorf("Addr not found")
}

View File

@ -31,13 +31,13 @@ func TestAccComputeDisk_basic(t *testing.T) {
func testAccCheckComputeDiskDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_disk" {
continue
}
_, err := config.clientCompute.Disks.Get(
config.Project, rs.Attributes["zone"], rs.ID).Do()
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Disk still exists")
}
@ -48,24 +48,24 @@ func testAccCheckComputeDiskDestroy(s *terraform.State) error {
func testAccCheckComputeDiskExists(n string, disk *compute.Disk) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
found, err := config.clientCompute.Disks.Get(
config.Project, rs.Attributes["zone"], rs.ID).Do()
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
if err != nil {
return err
}
if found.Name != rs.ID {
if found.Name != rs.Primary.ID {
return fmt.Errorf("Disk not found")
}

View File

@ -59,13 +59,13 @@ func TestAccComputeFirewall_update(t *testing.T) {
func testAccCheckComputeFirewallDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_firewall" {
continue
}
_, err := config.clientCompute.Firewalls.Get(
config.Project, rs.ID).Do()
config.Project, rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Firewall still exists")
}
@ -76,24 +76,24 @@ func testAccCheckComputeFirewallDestroy(s *terraform.State) error {
func testAccCheckComputeFirewallExists(n string, firewall *compute.Firewall) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
found, err := config.clientCompute.Firewalls.Get(
config.Project, rs.ID).Do()
config.Project, rs.Primary.ID).Do()
if err != nil {
return err
}
if found.Name != rs.ID {
if found.Name != rs.Primary.ID {
return fmt.Errorf("Firewall not found")
}

View File

@ -106,13 +106,13 @@ func TestAccComputeInstance_update(t *testing.T) {
func testAccCheckComputeInstanceDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_instance" {
continue
}
_, err := config.clientCompute.Instances.Get(
config.Project, rs.Attributes["zone"], rs.ID).Do()
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Instance still exists")
}
@ -123,24 +123,24 @@ func testAccCheckComputeInstanceDestroy(s *terraform.State) error {
func testAccCheckComputeInstanceExists(n string, instance *compute.Instance) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
found, err := config.clientCompute.Instances.Get(
config.Project, rs.Attributes["zone"], rs.ID).Do()
config.Project, rs.Primary.Attributes["zone"], rs.Primary.ID).Do()
if err != nil {
return err
}
if found.Name != rs.ID {
if found.Name != rs.Primary.ID {
return fmt.Errorf("Instance not found")
}

View File

@ -31,13 +31,13 @@ func TestAccComputeNetwork_basic(t *testing.T) {
func testAccCheckComputeNetworkDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_network" {
continue
}
_, err := config.clientCompute.Networks.Get(
config.Project, rs.ID).Do()
config.Project, rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Network still exists")
}
@ -48,24 +48,24 @@ func testAccCheckComputeNetworkDestroy(s *terraform.State) error {
func testAccCheckComputeNetworkExists(n string, network *compute.Network) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
found, err := config.clientCompute.Networks.Get(
config.Project, rs.ID).Do()
config.Project, rs.Primary.ID).Do()
if err != nil {
return err
}
if found.Name != rs.ID {
if found.Name != rs.Primary.ID {
return fmt.Errorf("Network not found")
}

View File

@ -31,13 +31,13 @@ func TestAccComputeRoute_basic(t *testing.T) {
func testAccCheckComputeRouteDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "google_compute_route" {
continue
}
_, err := config.clientCompute.Routes.Get(
config.Project, rs.ID).Do()
config.Project, rs.Primary.ID).Do()
if err == nil {
return fmt.Errorf("Route still exists")
}
@ -48,24 +48,24 @@ func testAccCheckComputeRouteDestroy(s *terraform.State) error {
func testAccCheckComputeRouteExists(n string, route *compute.Route) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
config := testAccProvider.Meta().(*Config)
found, err := config.clientCompute.Routes.Get(
config.Project, rs.ID).Do()
config.Project, rs.Primary.ID).Do()
if err != nil {
return err
}
if found.Name != rs.ID {
if found.Name != rs.Primary.ID {
return fmt.Errorf("Route not found")
}

View File

@ -8,7 +8,6 @@ import (
"github.com/cyberdelia/heroku-go/v3"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
// Global lock to prevent parallelism for heroku_addon since
@ -116,9 +115,6 @@ func resourceHerokuAddonRead(d *schema.ResourceData, meta interface{}) error {
d.Set("plan", plan)
d.Set("provider_id", addon.ProviderID)
d.Set("config_vars", []interface{}{addon.ConfigVars})
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: d.Get("app").(string)},
})
return nil
}

View File

@ -72,12 +72,12 @@ func TestAccHerokuAddon_noPlan(t *testing.T) {
func testAccCheckHerokuAddonDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "heroku_addon" {
continue
}
_, err := client.AddonInfo(rs.Attributes["app"], rs.ID)
_, err := client.AddonInfo(rs.Primary.Attributes["app"], rs.Primary.ID)
if err == nil {
return fmt.Errorf("Addon still exists")
@ -100,25 +100,25 @@ func testAccCheckHerokuAddonAttributes(addon *heroku.Addon, n string) resource.T
func testAccCheckHerokuAddonExists(n string, addon *heroku.Addon) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Addon ID is set")
}
client := testAccProvider.Meta().(*heroku.Service)
foundAddon, err := client.AddonInfo(rs.Attributes["app"], rs.ID)
foundAddon, err := client.AddonInfo(rs.Primary.Attributes["app"], rs.Primary.ID)
if err != nil {
return err
}
if foundAddon.ID != rs.ID {
if foundAddon.ID != rs.Primary.ID {
return fmt.Errorf("Addon not found")
}

View File

@ -105,12 +105,12 @@ func TestAccHerokuApp_NukeVars(t *testing.T) {
func testAccCheckHerokuAppDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "heroku_app" {
continue
}
_, err := client.AppInfo(rs.ID)
_, err := client.AppInfo(rs.Primary.ID)
if err == nil {
return fmt.Errorf("App still exists")
@ -199,25 +199,25 @@ func testAccCheckHerokuAppAttributesNoVars(app *heroku.App) resource.TestCheckFu
func testAccCheckHerokuAppExists(n string, app *heroku.App) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No App Name is set")
}
client := testAccProvider.Meta().(*heroku.Service)
foundApp, err := client.AppInfo(rs.ID)
foundApp, err := client.AppInfo(rs.Primary.ID)
if err != nil {
return err
}
if foundApp.Name != rs.ID {
if foundApp.Name != rs.Primary.ID {
return fmt.Errorf("App not found")
}

View File

@ -6,7 +6,6 @@ import (
"github.com/cyberdelia/heroku-go/v3"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
func resourceHerokuDomain() *schema.Resource {
@ -52,9 +51,6 @@ func resourceHerokuDomainCreate(d *schema.ResourceData, meta interface{}) error
d.SetId(do.ID)
d.Set("hostname", do.Hostname)
d.Set("cname", fmt.Sprintf("%s.herokuapp.com", app))
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: app},
})
log.Printf("[INFO] Domain ID: %s", d.Id())
return nil

View File

@ -37,12 +37,12 @@ func TestAccHerokuDomain_Basic(t *testing.T) {
func testAccCheckHerokuDomainDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "heroku_domain" {
continue
}
_, err := client.DomainInfo(rs.Attributes["app"], rs.ID)
_, err := client.DomainInfo(rs.Primary.Attributes["app"], rs.Primary.ID)
if err == nil {
return fmt.Errorf("Domain still exists")
@ -65,25 +65,25 @@ func testAccCheckHerokuDomainAttributes(Domain *heroku.Domain) resource.TestChec
func testAccCheckHerokuDomainExists(n string, Domain *heroku.Domain) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Domain ID is set")
}
client := testAccProvider.Meta().(*heroku.Service)
foundDomain, err := client.DomainInfo(rs.Attributes["app"], rs.ID)
foundDomain, err := client.DomainInfo(rs.Primary.Attributes["app"], rs.Primary.ID)
if err != nil {
return err
}
if foundDomain.ID != rs.ID {
if foundDomain.ID != rs.Primary.ID {
return fmt.Errorf("Domain not found")
}

View File

@ -6,7 +6,6 @@ import (
"github.com/cyberdelia/heroku-go/v3"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform"
)
func resourceHerokuDrain() *schema.Resource {
@ -52,9 +51,6 @@ func resourceHerokuDrainCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId(dr.ID)
d.Set("url", dr.URL)
d.Set("token", dr.Token)
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: app},
})
log.Printf("[INFO] Drain ID: %s", d.Id())
return nil

View File

@ -35,12 +35,12 @@ func TestAccHerokuDrain_Basic(t *testing.T) {
func testAccCheckHerokuDrainDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*heroku.Service)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "heroku_drain" {
continue
}
_, err := client.LogDrainInfo(rs.Attributes["app"], rs.ID)
_, err := client.LogDrainInfo(rs.Primary.Attributes["app"], rs.Primary.ID)
if err == nil {
return fmt.Errorf("Drain still exists")
@ -67,25 +67,25 @@ func testAccCheckHerokuDrainAttributes(Drain *heroku.LogDrain) resource.TestChec
func testAccCheckHerokuDrainExists(n string, Drain *heroku.LogDrain) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Drain ID is set")
}
client := testAccProvider.Meta().(*heroku.Service)
foundDrain, err := client.LogDrainInfo(rs.Attributes["app"], rs.ID)
foundDrain, err := client.LogDrainInfo(rs.Primary.Attributes["app"], rs.Primary.ID)
if err != nil {
return err
}
if foundDrain.ID != rs.ID {
if foundDrain.ID != rs.Primary.ID {
return fmt.Errorf("Drain not found")
}

View File

@ -43,12 +43,12 @@ func TestAccMailgunDomain_Basic(t *testing.T) {
func testAccCheckMailgunDomainDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*mailgun.Client)
for _, rs := range s.Resources {
for _, rs := range s.RootModule().Resources {
if rs.Type != "mailgun_domain" {
continue
}
_, err := client.RetrieveDomain(rs.ID)
_, err := client.RetrieveDomain(rs.Primary.ID)
if err == nil {
return fmt.Errorf("Domain still exists")
@ -91,25 +91,25 @@ func testAccCheckMailgunDomainAttributes(DomainResp *mailgun.DomainResponse) res
func testAccCheckMailgunDomainExists(n string, DomainResp *mailgun.DomainResponse) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[n]
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}
if rs.ID == "" {
if rs.Primary.ID == "" {
return fmt.Errorf("No Domain ID is set")
}
client := testAccProvider.Meta().(*mailgun.Client)
resp, err := client.RetrieveDomain(rs.ID)
resp, err := client.RetrieveDomain(rs.Primary.ID)
if err != nil {
return err
}
if resp.Domain.Name != rs.ID {
if resp.Domain.Name != rs.Primary.ID {
return fmt.Errorf("Domain not found")
}

View File

@ -13,7 +13,7 @@ import (
type ResourceProvisioner struct{}
func (p *ResourceProvisioner) Apply(s *terraform.ResourceState,
func (p *ResourceProvisioner) Apply(s *terraform.InstanceState,
c *terraform.ResourceConfig) error {
// Ensure the connection type is SSH
if err := helper.VerifySSH(s); err != nil {

View File

@ -20,7 +20,7 @@ const (
type ResourceProvisioner struct{}
func (p *ResourceProvisioner) Apply(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig) error {
// Get the command

View File

@ -22,7 +22,7 @@ const (
type ResourceProvisioner struct{}
func (p *ResourceProvisioner) Apply(s *terraform.ResourceState,
func (p *ResourceProvisioner) Apply(s *terraform.InstanceState,
c *terraform.ResourceConfig) error {
// Ensure the connection type is SSH
if err := helper.VerifySSH(s); err != nil {

View File

@ -182,14 +182,18 @@ func (c *ApplyCommand) Run(args []string) int {
}
// If we have outputs, then output those at the end.
if state != nil && len(state.Outputs) > 0 {
var outputs map[string]string
if state != nil {
outputs = state.RootModule().Outputs
}
if len(outputs) > 0 {
outputBuf := new(bytes.Buffer)
outputBuf.WriteString("[reset][bold][green]\nOutputs:\n\n")
// Output the outputs in alphabetical order
keyLen := 0
keys := make([]string, 0, len(state.Outputs))
for key, _ := range state.Outputs {
keys := make([]string, 0, len(outputs))
for key, _ := range outputs {
keys = append(keys, key)
if len(key) > keyLen {
keyLen = len(key)
@ -198,7 +202,7 @@ func (c *ApplyCommand) Run(args []string) int {
sort.Strings(keys)
for _, k := range keys {
v := state.Outputs[k]
v := outputs[k]
outputBuf.WriteString(fmt.Sprintf(
" %s%s = %s\n",

View File

@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"reflect"
"strings"
"sync"
"testing"
"time"
@ -140,8 +141,9 @@ func TestApply_error(t *testing.T) {
var lock sync.Mutex
errored := false
p.ApplyFn = func(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
lock.Lock()
defer lock.Unlock()
@ -150,12 +152,13 @@ func TestApply_error(t *testing.T) {
return nil, fmt.Errorf("error")
}
return &terraform.ResourceState{ID: "foo"}, nil
return &terraform.InstanceState{ID: "foo"}, nil
}
p.DiffFn = func(
*terraform.ResourceState,
*terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
return &terraform.ResourceDiff{
*terraform.InstanceInfo,
*terraform.InstanceState,
*terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
return &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ami": &terraform.ResourceAttrDiff{
New: "bar",
@ -189,7 +192,7 @@ func TestApply_error(t *testing.T) {
if state == nil {
t.Fatal("state should not be nil")
}
if len(state.Resources) == 0 {
if len(state.RootModule().Resources) == 0 {
t.Fatal("no resources in state")
}
}
@ -367,10 +370,17 @@ func TestApply_planVars(t *testing.T) {
func TestApply_refresh(t *testing.T) {
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
Type: "test_instance",
Primary: &terraform.InstanceState{
ID: "bar",
},
},
},
},
},
}
@ -428,8 +438,10 @@ func TestApply_refresh(t *testing.T) {
t.Fatalf("err: %s", err)
}
if !reflect.DeepEqual(backupState, originalState) {
t.Fatalf("bad: %#v", backupState)
actualStr := strings.TrimSpace(backupState.String())
expectedStr := strings.TrimSpace(originalState.String())
if actualStr != expectedStr {
t.Fatalf("bad:\n\n%s\n\n%s", actualStr, expectedStr)
}
}
@ -453,9 +465,10 @@ func TestApply_shutdown(t *testing.T) {
}
p.DiffFn = func(
*terraform.ResourceState,
*terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
return &terraform.ResourceDiff{
*terraform.InstanceInfo,
*terraform.InstanceState,
*terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
return &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ami": &terraform.ResourceAttrDiff{
New: "bar",
@ -464,15 +477,16 @@ func TestApply_shutdown(t *testing.T) {
}, nil
}
p.ApplyFn = func(
*terraform.ResourceState,
*terraform.ResourceDiff) (*terraform.ResourceState, error) {
*terraform.InstanceInfo,
*terraform.InstanceState,
*terraform.InstanceDiff) (*terraform.InstanceState, error) {
if !stopped {
stopped = true
close(stopCh)
<-stopReplyCh
}
return &terraform.ResourceState{
return &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"ami": "2",
@ -518,18 +532,24 @@ func TestApply_shutdown(t *testing.T) {
t.Fatal("state should not be nil")
}
if len(state.Resources) != 1 {
t.Fatalf("bad: %d", len(state.Resources))
if len(state.RootModule().Resources) != 1 {
t.Fatalf("bad: %d", len(state.RootModule().Resources))
}
}
func TestApply_state(t *testing.T) {
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
ConnInfo: make(map[string]string),
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
Type: "test_instance",
Primary: &terraform.InstanceState{
ID: "bar",
},
},
},
},
},
}
@ -537,7 +557,7 @@ func TestApply_state(t *testing.T) {
statePath := testStateFile(t, originalState)
p := testProvider()
p.DiffReturn = &terraform.ResourceDiff{
p.DiffReturn = &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ami": &terraform.ResourceAttrDiff{
New: "bar",
@ -563,13 +583,16 @@ func TestApply_state(t *testing.T) {
}
// Verify that the provider was called with the existing state
expectedState := originalState.Resources["test_instance.foo"]
if !reflect.DeepEqual(p.DiffState, expectedState) {
t.Fatalf("bad: %#v", p.DiffState)
actual := strings.TrimSpace(p.DiffState.String())
expected := strings.TrimSpace(testApplyStateDiffStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
if !reflect.DeepEqual(p.ApplyState, expectedState) {
t.Fatalf("bad: %#v", p.ApplyState)
actual = strings.TrimSpace(p.ApplyState.String())
expected = strings.TrimSpace(testApplyStateStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
// Verify a new state exists
@ -604,10 +627,12 @@ func TestApply_state(t *testing.T) {
}
// nil out the ConnInfo since that should not be restored
originalState.Resources["test_instance.foo"].ConnInfo = nil
originalState.RootModule().Resources["test_instance.foo"].Primary.Ephemeral.ConnInfo = nil
if !reflect.DeepEqual(backupState, originalState) {
t.Fatalf("bad: %#v", backupState)
actualStr := strings.TrimSpace(backupState.String())
expectedStr := strings.TrimSpace(originalState.String())
if actualStr != expectedStr {
t.Fatalf("bad:\n\n%s\n\n%s", actualStr, expectedStr)
}
}
@ -644,13 +669,14 @@ func TestApply_vars(t *testing.T) {
actual := ""
p.DiffFn = func(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
if v, ok := c.Config["value"]; ok {
actual = v.(string)
}
return &terraform.ResourceDiff{}, nil
return &terraform.InstanceDiff{}, nil
}
args := []string{
@ -686,13 +712,14 @@ func TestApply_varFile(t *testing.T) {
actual := ""
p.DiffFn = func(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
if v, ok := c.Config["value"]; ok {
actual = v.(string)
}
return &terraform.ResourceDiff{}, nil
return &terraform.InstanceDiff{}, nil
}
args := []string{
@ -738,13 +765,14 @@ func TestApply_varFileDefault(t *testing.T) {
actual := ""
p.DiffFn = func(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
if v, ok := c.Config["value"]; ok {
actual = v.(string)
}
return &terraform.ResourceDiff{}, nil
return &terraform.InstanceDiff{}, nil
}
args := []string{
@ -762,10 +790,17 @@ func TestApply_varFileDefault(t *testing.T) {
func TestApply_backup(t *testing.T) {
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
Type: "test_instance",
Primary: &terraform.InstanceState{
ID: "bar",
},
},
},
},
},
}
@ -774,7 +809,7 @@ func TestApply_backup(t *testing.T) {
backupPath := testTempFile(t)
p := testProvider()
p.DiffReturn = &terraform.ResourceDiff{
p.DiffReturn = &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ami": &terraform.ResourceAttrDiff{
New: "bar",
@ -831,28 +866,19 @@ func TestApply_backup(t *testing.T) {
t.Fatalf("err: %s", err)
}
actual := backupState.Resources["test_instance.foo"]
expected := originalState.Resources["test_instance.foo"]
actual := backupState.RootModule().Resources["test_instance.foo"]
expected := originalState.RootModule().Resources["test_instance.foo"]
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v %#v", actual, expected)
}
}
func TestApply_disableBackup(t *testing.T) {
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
ConnInfo: make(map[string]string),
},
},
}
originalState := testState()
statePath := testStateFile(t, originalState)
p := testProvider()
p.DiffReturn = &terraform.ResourceDiff{
p.DiffReturn = &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ami": &terraform.ResourceAttrDiff{
New: "bar",
@ -879,13 +905,16 @@ func TestApply_disableBackup(t *testing.T) {
}
// Verify that the provider was called with the existing state
expectedState := originalState.Resources["test_instance.foo"]
if !reflect.DeepEqual(p.DiffState, expectedState) {
t.Fatalf("bad: %#v", p.DiffState)
actual := strings.TrimSpace(p.DiffState.String())
expected := strings.TrimSpace(testApplyDisableBackupStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
if !reflect.DeepEqual(p.ApplyState, expectedState) {
t.Fatalf("bad: %#v", p.ApplyState)
actual = strings.TrimSpace(p.ApplyState.String())
expected = strings.TrimSpace(testApplyDisableBackupStateStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
// Verify a new state exists
@ -917,3 +946,19 @@ func TestApply_disableBackup(t *testing.T) {
const applyVarFile = `
foo = "bar"
`
const testApplyDisableBackupStr = `
ID = bar
`
const testApplyDisableBackupStateStr = `
ID = bar
`
const testApplyStateStr = `
ID = bar
`
const testApplyStateDiffStr = `
ID = bar
`

View File

@ -67,6 +67,25 @@ func testReadPlan(t *testing.T, path string) *terraform.Plan {
return p
}
// testState returns a test State structure that we use for a lot of tests.
func testState() *terraform.State {
return &terraform.State{
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
Type: "test_instance",
Primary: &terraform.InstanceState{
ID: "bar",
},
},
},
},
},
}
}
func testStateFile(t *testing.T, s *terraform.State) string {
path := testTempFile(t)
@ -85,9 +104,10 @@ func testStateFile(t *testing.T, s *terraform.State) string {
func testProvider() *terraform.MockResourceProvider {
p := new(terraform.MockResourceProvider)
p.DiffReturn = &terraform.ResourceDiff{}
p.DiffReturn = &terraform.InstanceDiff{}
p.RefreshFn = func(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
return s, nil
}
p.ResourcesReturn = []terraform.ResourceType{

View File

@ -16,42 +16,49 @@ func FormatState(s *terraform.State, c *colorstring.Colorize) string {
panic("colorize not given")
}
if len(s.Resources) == 0 {
if len(s.Modules) == 0 {
return "The state file is empty. No resources are represented."
}
buf := new(bytes.Buffer)
var buf bytes.Buffer
for _, m := range s.Modules {
formatStateModule(&buf, m, c)
}
return c.Color(strings.TrimSpace(buf.String()))
}
func formatStateModule(buf *bytes.Buffer, m *terraform.ModuleState, c *colorstring.Colorize) {
buf.WriteString("[reset]")
// First get the names of all the resources so we can show them
// in alphabetical order.
names := make([]string, 0, len(s.Resources))
for name, _ := range s.Resources {
names := make([]string, 0, len(m.Resources))
for name, _ := range m.Resources {
names = append(names, name)
}
sort.Strings(names)
// Go through each resource and begin building up the output.
for _, k := range names {
rs := s.Resources[k]
id := rs.ID
rs := m.Resources[k]
is := rs.Primary
id := is.ID
if id == "" {
id = "<not created>"
}
taintStr := ""
if s.Tainted != nil {
if _, ok := s.Tainted[k]; ok {
taintStr = " (tainted)"
}
if len(rs.Tainted) > 0 {
taintStr = " (tainted)"
}
buf.WriteString(fmt.Sprintf("%s:%s\n", k, taintStr))
buf.WriteString(fmt.Sprintf(" id = %s\n", id))
// Sort the attributes
attrKeys := make([]string, 0, len(rs.Attributes))
for ak, _ := range rs.Attributes {
attrKeys := make([]string, 0, len(is.Attributes))
for ak, _ := range is.Attributes {
// Skip the id attribute since we just show the id directly
if ak == "id" {
continue
@ -63,27 +70,25 @@ func FormatState(s *terraform.State, c *colorstring.Colorize) string {
// Output each attribute
for _, ak := range attrKeys {
av := rs.Attributes[ak]
av := is.Attributes[ak]
buf.WriteString(fmt.Sprintf(" %s = %s\n", ak, av))
}
}
if len(s.Outputs) > 0 {
if len(m.Outputs) > 0 {
buf.WriteString("\nOutputs:\n\n")
// Sort the outputs
ks := make([]string, 0, len(s.Outputs))
for k, _ := range s.Outputs {
ks := make([]string, 0, len(m.Outputs))
for k, _ := range m.Outputs {
ks = append(ks, k)
}
sort.Strings(ks)
// Output each output k/v pair
for _, k := range ks {
v := s.Outputs[k]
v := m.Outputs[k]
buf.WriteString(fmt.Sprintf("%s = %s\n", k, v))
}
}
return c.Color(strings.TrimSpace(buf.String()))
}

View File

@ -39,8 +39,8 @@ func (h *CountHook) Reset() {
func (h *CountHook) PreApply(
id string,
s *terraform.ResourceState,
d *terraform.ResourceDiff) (terraform.HookAction, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff) (terraform.HookAction, error) {
h.Lock()
defer h.Unlock()
@ -62,7 +62,7 @@ func (h *CountHook) PreApply(
func (h *CountHook) PostApply(
id string,
s *terraform.ResourceState,
s *terraform.InstanceState,
e error) (terraform.HookAction, error) {
h.Lock()
defer h.Unlock()

View File

@ -35,8 +35,8 @@ const (
func (h *UiHook) PreApply(
id string,
s *terraform.ResourceState,
d *terraform.ResourceDiff) (terraform.HookAction, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff) (terraform.HookAction, error) {
h.once.Do(h.init)
op := uiResourceModify
@ -114,7 +114,7 @@ func (h *UiHook) PreApply(
func (h *UiHook) PostApply(
id string,
s *terraform.ResourceState,
s *terraform.InstanceState,
applyerr error) (terraform.HookAction, error) {
h.l.Lock()
op := h.resources[id]
@ -145,7 +145,7 @@ func (h *UiHook) PostApply(
}
func (h *UiHook) PreDiff(
id string, s *terraform.ResourceState) (terraform.HookAction, error) {
id string, s *terraform.InstanceState) (terraform.HookAction, error) {
return terraform.HookActionContinue, nil
}
@ -157,7 +157,7 @@ func (h *UiHook) PreProvision(id, provId string) (terraform.HookAction, error) {
}
func (h *UiHook) PreRefresh(
id string, s *terraform.ResourceState) (terraform.HookAction, error) {
id string, s *terraform.InstanceState) (terraform.HookAction, error) {
h.once.Do(h.init)
h.ui.Output(h.Colorize.Color(fmt.Sprintf(

View File

@ -50,14 +50,14 @@ func (c *OutputCommand) Run(args []string) int {
return 1
}
if len(state.Outputs) == 0 {
if len(state.RootModule().Outputs) == 0 {
c.Ui.Error(fmt.Sprintf(
"The state file has no outputs defined. Define an output\n" +
"in your configuration with the `output` directive and re-run\n" +
"`terraform apply` for it to become available."))
return 1
}
v, ok := state.Outputs[name]
v, ok := state.RootModule().Outputs[name]
if !ok {
c.Ui.Error(fmt.Sprintf(
"The output variable requested could not be found in the state\n" +

View File

@ -13,8 +13,13 @@ import (
func TestOutput(t *testing.T) {
originalState := &terraform.State{
Outputs: map[string]string{
"foo": "bar",
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Outputs: map[string]string{
"foo": "bar",
},
},
},
}
@ -44,8 +49,13 @@ func TestOutput(t *testing.T) {
func TestOutput_badVar(t *testing.T) {
originalState := &terraform.State{
Outputs: map[string]string{
"foo": "bar",
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Outputs: map[string]string{
"foo": "bar",
},
},
},
}
@ -70,8 +80,13 @@ func TestOutput_badVar(t *testing.T) {
func TestOutput_blank(t *testing.T) {
originalState := &terraform.State{
Outputs: map[string]string{
"foo": "bar",
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Outputs: map[string]string{
"foo": "bar",
},
},
},
}
@ -129,7 +144,12 @@ func TestOutput_noArgs(t *testing.T) {
func TestOutput_noVars(t *testing.T) {
originalState := &terraform.State{
Outputs: map[string]string{},
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Outputs: map[string]string{},
},
},
}
statePath := testStateFile(t, originalState)
@ -153,8 +173,13 @@ func TestOutput_noVars(t *testing.T) {
func TestOutput_stateDefault(t *testing.T) {
originalState := &terraform.State{
Outputs: map[string]string{
"foo": "bar",
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Outputs: map[string]string{
"foo": "bar",
},
},
},
}

View File

@ -4,7 +4,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"github.com/hashicorp/terraform/terraform"
@ -38,10 +38,17 @@ func TestPlan(t *testing.T) {
func TestPlan_destroy(t *testing.T) {
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
Type: "test_instance",
Primary: &terraform.InstanceState{
ID: "bar",
},
},
},
},
},
}
@ -90,10 +97,13 @@ func TestPlan_destroy(t *testing.T) {
t.Fatalf("err: %s", err)
}
if !reflect.DeepEqual(backupState, originalState) {
t.Fatalf("bad: %#v", backupState)
actualStr := strings.TrimSpace(backupState.String())
expectedStr := strings.TrimSpace(originalState.String())
if actualStr != expectedStr {
t.Fatalf("bad:\n\n%s\n\n%s", actualStr, expectedStr)
}
}
func TestPlan_noState(t *testing.T) {
p := testProvider()
ui := new(cli.MockUi)
@ -117,11 +127,10 @@ func TestPlan_noState(t *testing.T) {
}
// Verify that the provider was called with the existing state
expectedState := &terraform.ResourceState{
Type: "test_instance",
}
if !reflect.DeepEqual(p.DiffState, expectedState) {
t.Fatalf("bad: %#v", p.DiffState)
actual := strings.TrimSpace(p.DiffState.String())
expected := strings.TrimSpace(testPlanNoStateStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
@ -142,7 +151,7 @@ func TestPlan_outPath(t *testing.T) {
},
}
p.DiffReturn = &terraform.ResourceDiff{
p.DiffReturn = &terraform.InstanceDiff{
Destroy: true,
}
@ -197,15 +206,7 @@ func TestPlan_state(t *testing.T) {
statePath := tf.Name()
defer os.Remove(tf.Name())
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
originalState := testState()
err = terraform.WriteState(originalState, tf)
tf.Close()
if err != nil {
@ -230,21 +231,15 @@ func TestPlan_state(t *testing.T) {
}
// Verify that the provider was called with the existing state
expectedState := originalState.Resources["test_instance.foo"]
if !reflect.DeepEqual(p.DiffState, expectedState) {
t.Fatalf("bad: %#v", p.DiffState)
actual := strings.TrimSpace(p.DiffState.String())
expected := strings.TrimSpace(testPlanStateStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestPlan_stateDefault(t *testing.T) {
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
originalState := testState()
// Write the state file in a temporary directory with the
// default filename.
@ -291,9 +286,10 @@ func TestPlan_stateDefault(t *testing.T) {
}
// Verify that the provider was called with the existing state
expectedState := originalState.Resources["test_instance.foo"]
if !reflect.DeepEqual(p.DiffState, expectedState) {
t.Fatalf("bad: %#v", p.DiffState)
actual := strings.TrimSpace(p.DiffState.String())
expected := strings.TrimSpace(testPlanStateDefaultStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
@ -309,8 +305,9 @@ func TestPlan_vars(t *testing.T) {
actual := ""
p.DiffFn = func(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
if v, ok := c.Config["value"]; ok {
actual = v.(string)
}
@ -348,8 +345,9 @@ func TestPlan_varFile(t *testing.T) {
actual := ""
p.DiffFn = func(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
if v, ok := c.Config["value"]; ok {
actual = v.(string)
}
@ -397,8 +395,9 @@ func TestPlan_varFileDefault(t *testing.T) {
actual := ""
p.DiffFn = func(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
if v, ok := c.Config["value"]; ok {
actual = v.(string)
}
@ -438,10 +437,17 @@ func TestPlan_backup(t *testing.T) {
defer os.Remove(backupPath)
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
Type: "test_instance",
Primary: &terraform.InstanceState{
ID: "bar",
},
},
},
},
},
}
@ -471,9 +477,10 @@ func TestPlan_backup(t *testing.T) {
}
// Verify that the provider was called with the existing state
expectedState := originalState.Resources["test_instance.foo"]
if !reflect.DeepEqual(p.DiffState, expectedState) {
t.Fatalf("bad: %#v", p.DiffState)
actual := strings.TrimSpace(p.DiffState.String())
expected := strings.TrimSpace(testPlanBackupStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
// Verify the backup exist
@ -488,8 +495,10 @@ func TestPlan_backup(t *testing.T) {
t.Fatalf("err: %s", err)
}
if !reflect.DeepEqual(backupState, originalState) {
t.Fatalf("bad: %#v", backupState)
actualStr := strings.TrimSpace(backupState.String())
expectedStr := strings.TrimSpace(originalState.String())
if actualStr != expectedStr {
t.Fatalf("bad:\n\n%s\n\n%s", actualStr, expectedStr)
}
}
@ -503,10 +512,17 @@ func TestPlan_disableBackup(t *testing.T) {
defer os.Remove(tf.Name())
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
Modules: []*terraform.ModuleState{
&terraform.ModuleState{
Path: []string{"root"},
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
Type: "test_instance",
Primary: &terraform.InstanceState{
ID: "bar",
},
},
},
},
},
}
@ -536,9 +552,10 @@ func TestPlan_disableBackup(t *testing.T) {
}
// Verify that the provider was called with the existing state
expectedState := originalState.Resources["test_instance.foo"]
if !reflect.DeepEqual(p.DiffState, expectedState) {
t.Fatalf("bad: %#v", p.DiffState)
actual := strings.TrimSpace(p.DiffState.String())
expected := strings.TrimSpace(testPlanDisableBackupStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
// Ensure there is no backup
@ -551,3 +568,23 @@ func TestPlan_disableBackup(t *testing.T) {
const planVarFile = `
foo = "bar"
`
const testPlanBackupStr = `
ID = bar
`
const testPlanDisableBackupStr = `
ID = bar
`
const testPlanNoStateStr = `
<not created>
`
const testPlanStateStr = `
ID = bar
`
const testPlanStateDefaultStr = `
ID = bar
`

View File

@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"github.com/hashicorp/terraform/terraform"
@ -12,14 +13,7 @@ import (
)
func TestRefresh(t *testing.T) {
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
state := testState()
statePath := testStateFile(t, state)
p := testProvider()
@ -32,7 +26,7 @@ func TestRefresh(t *testing.T) {
}
p.RefreshFn = nil
p.RefreshReturn = &terraform.ResourceState{ID: "yes"}
p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
args := []string{
"-state", statePath,
@ -57,10 +51,10 @@ func TestRefresh(t *testing.T) {
t.Fatalf("err: %s", err)
}
actual := newState.Resources["test_instance.foo"]
expected := p.RefreshReturn
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
actual := strings.TrimSpace(newState.String())
expected := strings.TrimSpace(testRefreshStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
@ -93,14 +87,7 @@ func TestRefresh_cwd(t *testing.T) {
}
defer os.Chdir(cwd)
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
state := testState()
statePath := testStateFile(t, state)
p := testProvider()
@ -113,7 +100,7 @@ func TestRefresh_cwd(t *testing.T) {
}
p.RefreshFn = nil
p.RefreshReturn = &terraform.ResourceState{ID: "yes"}
p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
args := []string{
"-state", statePath,
@ -137,22 +124,15 @@ func TestRefresh_cwd(t *testing.T) {
t.Fatalf("err: %s", err)
}
actual := newState.Resources["test_instance.foo"]
expected := p.RefreshReturn
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
actual := strings.TrimSpace(newState.String())
expected := strings.TrimSpace(testRefreshCwdStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
func TestRefresh_defaultState(t *testing.T) {
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
originalState := testState()
// Write the state file in a temporary directory with the
// default filename.
@ -192,7 +172,7 @@ func TestRefresh_defaultState(t *testing.T) {
}
p.RefreshFn = nil
p.RefreshReturn = &terraform.ResourceState{ID: "yes"}
p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
args := []string{
testFixturePath("refresh"),
@ -216,7 +196,7 @@ func TestRefresh_defaultState(t *testing.T) {
t.Fatalf("err: %s", err)
}
actual := newState.Resources["test_instance.foo"]
actual := newState.RootModule().Resources["test_instance.foo"].Primary
expected := p.RefreshReturn
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
@ -233,22 +213,15 @@ func TestRefresh_defaultState(t *testing.T) {
t.Fatalf("err: %s", err)
}
actual = backupState.Resources["test_instance.foo"]
expected = originalState.Resources["test_instance.foo"]
actual = backupState.RootModule().Resources["test_instance.foo"].Primary
expected = originalState.RootModule().Resources["test_instance.foo"].Primary
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
}
}
func TestRefresh_outPath(t *testing.T) {
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
state := testState()
statePath := testStateFile(t, state)
// Output path
@ -270,7 +243,7 @@ func TestRefresh_outPath(t *testing.T) {
}
p.RefreshFn = nil
p.RefreshReturn = &terraform.ResourceState{ID: "yes"}
p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
args := []string{
"-state", statePath,
@ -307,7 +280,7 @@ func TestRefresh_outPath(t *testing.T) {
t.Fatalf("err: %s", err)
}
actual := newState.Resources["test_instance.foo"]
actual := newState.RootModule().Resources["test_instance.foo"].Primary
expected := p.RefreshReturn
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
@ -324,20 +297,15 @@ func TestRefresh_outPath(t *testing.T) {
t.Fatalf("err: %s", err)
}
if !reflect.DeepEqual(backupState, state) {
t.Fatalf("bad: %#v", backupState)
actualStr := strings.TrimSpace(backupState.String())
expectedStr := strings.TrimSpace(state.String())
if actualStr != expectedStr {
t.Fatalf("bad:\n\n%s\n\n%s", actualStr, expectedStr)
}
}
func TestRefresh_var(t *testing.T) {
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
state := testState()
statePath := testStateFile(t, state)
p := testProvider()
@ -367,14 +335,7 @@ func TestRefresh_var(t *testing.T) {
}
func TestRefresh_varFile(t *testing.T) {
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
state := testState()
statePath := testStateFile(t, state)
p := testProvider()
@ -409,14 +370,7 @@ func TestRefresh_varFile(t *testing.T) {
}
func TestRefresh_varFileDefault(t *testing.T) {
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
state := testState()
statePath := testStateFile(t, state)
p := testProvider()
@ -460,14 +414,7 @@ func TestRefresh_varFileDefault(t *testing.T) {
}
func TestRefresh_backup(t *testing.T) {
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
state := testState()
statePath := testStateFile(t, state)
// Output path
@ -498,7 +445,7 @@ func TestRefresh_backup(t *testing.T) {
}
p.RefreshFn = nil
p.RefreshReturn = &terraform.ResourceState{ID: "yes"}
p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
args := []string{
"-state", statePath,
@ -536,7 +483,7 @@ func TestRefresh_backup(t *testing.T) {
t.Fatalf("err: %s", err)
}
actual := newState.Resources["test_instance.foo"]
actual := newState.RootModule().Resources["test_instance.foo"].Primary
expected := p.RefreshReturn
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
@ -553,20 +500,15 @@ func TestRefresh_backup(t *testing.T) {
t.Fatalf("err: %s", err)
}
if !reflect.DeepEqual(backupState, state) {
t.Fatalf("bad: %#v", backupState)
actualStr := strings.TrimSpace(backupState.String())
expectedStr := strings.TrimSpace(state.String())
if actualStr != expectedStr {
t.Fatalf("bad:\n\n%s\n\n%s", actualStr, expectedStr)
}
}
func TestRefresh_disableBackup(t *testing.T) {
state := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
state := testState()
statePath := testStateFile(t, state)
// Output path
@ -588,7 +530,7 @@ func TestRefresh_disableBackup(t *testing.T) {
}
p.RefreshFn = nil
p.RefreshReturn = &terraform.ResourceState{ID: "yes"}
p.RefreshReturn = &terraform.InstanceState{ID: "yes"}
args := []string{
"-state", statePath,
@ -626,7 +568,7 @@ func TestRefresh_disableBackup(t *testing.T) {
t.Fatalf("err: %s", err)
}
actual := newState.Resources["test_instance.foo"]
actual := newState.RootModule().Resources["test_instance.foo"].Primary
expected := p.RefreshReturn
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("bad: %#v", actual)
@ -642,3 +584,12 @@ func TestRefresh_disableBackup(t *testing.T) {
const refreshVarFile = `
foo = "bar"
`
const testRefreshStr = `
test_instance.foo:
ID = yes
`
const testRefreshCwdStr = `
test_instance.foo:
ID = yes
`

View File

@ -63,15 +63,7 @@ func TestShow_plan(t *testing.T) {
}
func TestShow_state(t *testing.T) {
originalState := &terraform.State{
Resources: map[string]*terraform.ResourceState{
"test_instance.foo": &terraform.ResourceState{
ID: "bar",
Type: "test_instance",
},
},
}
originalState := testState()
statePath := testStateFile(t, originalState)
ui := new(cli.MockUi)

View File

@ -29,7 +29,7 @@ func testConfig(
return terraform.NewResourceConfig(rc)
}
func testResourceDiffStr(rd *terraform.ResourceDiff) string {
func testResourceDiffStr(rd *terraform.InstanceDiff) string {
var buf bytes.Buffer
crud := "UPDATE"

View File

@ -61,8 +61,8 @@ type PreProcessFunc func(string) string
// Diff returns the ResourceDiff for a resource given its state and
// configuration.
func (b *ResourceBuilder) Diff(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
attrs := make(map[string]*terraform.ResourceAttrDiff)
// We require a new resource if the ID is empty. Or, later, we set
@ -207,9 +207,9 @@ func (b *ResourceBuilder) Diff(
}
// Build our resulting diff if we had attributes change
var result *terraform.ResourceDiff
var result *terraform.InstanceDiff
if len(attrs) > 0 {
result = &terraform.ResourceDiff{
result = &terraform.InstanceDiff{
Attributes: attrs,
}
}

View File

@ -17,7 +17,7 @@ func TestResourceBuilder_attrSetComputed(t *testing.T) {
},
}
state := &terraform.ResourceState{}
state := &terraform.InstanceState{}
c := testConfig(t, map[string]interface{}{
"foo": "bar",
}, nil)
@ -47,7 +47,7 @@ func TestResourceBuilder_attrSetComputedComplex(t *testing.T) {
},
}
state := &terraform.ResourceState{
state := &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"foo.#": "0",
@ -75,7 +75,7 @@ func TestResourceBuilder_replaceComputed(t *testing.T) {
},
}
state := &terraform.ResourceState{
state := &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"foo": "bar",
@ -99,7 +99,7 @@ func TestResourceBuilder_complex(t *testing.T) {
},
}
state := &terraform.ResourceState{
state := &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"ignore": "1",
@ -138,7 +138,7 @@ func TestResourceBuilder_complexReplace(t *testing.T) {
},
}
state := &terraform.ResourceState{
state := &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"ignore": "1",
@ -180,7 +180,7 @@ func TestResourceBuilder_computedAttrsUpdate(t *testing.T) {
},
}
state := &terraform.ResourceState{
state := &terraform.InstanceState{
Attributes: map[string]string{"foo": "foo"},
}
c := testConfig(t, map[string]interface{}{
@ -210,7 +210,7 @@ func TestResourceBuilder_new(t *testing.T) {
ComputedAttrs: []string{"private_ip"},
}
state := &terraform.ResourceState{}
state := &terraform.InstanceState{}
c := testConfig(t, map[string]interface{}{
"foo": "bar",
@ -244,7 +244,7 @@ func TestResourceBuilder_preProcess(t *testing.T) {
},
}
state := &terraform.ResourceState{}
state := &terraform.InstanceState{}
c := testConfig(t, map[string]interface{}{
"foo": "foo",
}, nil)
@ -283,7 +283,7 @@ func TestResourceBuilder_preProcessUnknown(t *testing.T) {
},
}
state := &terraform.ResourceState{}
state := &terraform.InstanceState{}
c := testConfig(t, map[string]interface{}{
"foo": "${var.unknown}",
}, map[string]string{
@ -313,7 +313,7 @@ func TestResourceBuilder_requiresNew(t *testing.T) {
},
}
state := &terraform.ResourceState{
state := &terraform.InstanceState{
ID: "1",
Attributes: map[string]string{
"ami": "foo",
@ -345,7 +345,7 @@ func TestResourceBuilder_same(t *testing.T) {
ComputedAttrs: []string{"private_ip"},
}
state := &terraform.ResourceState{
state := &terraform.InstanceState{
ID: "1",
Attributes: map[string]string{
"foo": "bar",
@ -372,7 +372,7 @@ func TestResourceBuilder_unknown(t *testing.T) {
},
}
state := &terraform.ResourceState{}
state := &terraform.InstanceState{}
c := testConfig(t, map[string]interface{}{
"foo": "${var.unknown}",
@ -403,7 +403,7 @@ func TestResourceBuilder_vars(t *testing.T) {
},
}
state := &terraform.ResourceState{}
state := &terraform.InstanceState{}
c := testConfig(t, map[string]interface{}{
"foo": "${var.foo}",

View File

@ -31,12 +31,13 @@ func (m *Map) Validate(
// Apply performs a create or update depending on the diff, and calls
// the proper function on the matching Resource.
func (m *Map) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
r, ok := m.Mapping[s.Type]
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
r, ok := m.Mapping[info.Type]
if !ok {
return nil, fmt.Errorf("Unknown resource type: %s", s.Type)
return nil, fmt.Errorf("Unknown resource type: %s", info.Type)
}
if d.Destroy || d.RequiresNew() {
@ -57,7 +58,7 @@ func (m *Map) Apply(
}
}
var result *terraform.ResourceState
var result *terraform.InstanceState
var err error
if s.ID == "" {
result, err = r.Create(s, d, meta)
@ -65,7 +66,7 @@ func (m *Map) Apply(
if r.Update == nil {
return s, fmt.Errorf(
"Resource type '%s' doesn't support update",
s.Type)
info.Type)
}
result, err = r.Update(s, d, meta)
@ -83,12 +84,13 @@ func (m *Map) Apply(
// Diff performs a diff on the proper resource type.
func (m *Map) Diff(
s *terraform.ResourceState,
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig,
meta interface{}) (*terraform.ResourceDiff, error) {
r, ok := m.Mapping[s.Type]
meta interface{}) (*terraform.InstanceDiff, error) {
r, ok := m.Mapping[info.Type]
if !ok {
return nil, fmt.Errorf("Unknown resource type: %s", s.Type)
return nil, fmt.Errorf("Unknown resource type: %s", info.Type)
}
return r.Diff(s, c, meta)
@ -101,16 +103,17 @@ func (m *Map) Diff(
//
// An error is returned if the resource isn't registered.
func (m *Map) Refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
// If the resource isn't created, don't refresh.
if s.ID == "" {
return s, nil
}
r, ok := m.Mapping[s.Type]
r, ok := m.Mapping[info.Type]
if !ok {
return nil, fmt.Errorf("Unknown resource type: %s", s.Type)
return nil, fmt.Errorf("Unknown resource type: %s", info.Type)
}
return r.Refresh(s, meta)

View File

@ -17,33 +17,33 @@ type Resource struct {
// CreateFunc is a function that creates a resource that didn't previously
// exist.
type CreateFunc func(
*terraform.ResourceState,
*terraform.ResourceDiff,
interface{}) (*terraform.ResourceState, error)
*terraform.InstanceState,
*terraform.InstanceDiff,
interface{}) (*terraform.InstanceState, error)
// DestroyFunc is a function that destroys a resource that previously
// exists using the state.
type DestroyFunc func(
*terraform.ResourceState,
*terraform.InstanceState,
interface{}) error
// DiffFunc is a function that performs a diff of a resource.
type DiffFunc func(
*terraform.ResourceState,
*terraform.InstanceState,
*terraform.ResourceConfig,
interface{}) (*terraform.ResourceDiff, error)
interface{}) (*terraform.InstanceDiff, error)
// RefreshFunc is a function that performs a refresh of a specific type
// of resource.
type RefreshFunc func(
*terraform.ResourceState,
interface{}) (*terraform.ResourceState, error)
*terraform.InstanceState,
interface{}) (*terraform.InstanceState, error)
// UpdateFunc is a function that is called to update a resource that
// previously existed. The difference between this and CreateFunc is that
// the diff is guaranteed to only contain attributes that don't require
// a new resource.
type UpdateFunc func(
*terraform.ResourceState,
*terraform.ResourceDiff,
interface{}) (*terraform.ResourceState, error)
*terraform.InstanceState,
*terraform.InstanceDiff,
interface{}) (*terraform.InstanceState, error)

View File

@ -244,18 +244,24 @@ func ComposeTestCheckFunc(fs ...TestCheckFunc) TestCheckFunc {
func TestCheckResourceAttr(name, key, value string) TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.Resources[name]
ms := s.RootModule()
rs, ok := ms.Resources[name]
if !ok {
return fmt.Errorf("Not found: %s", name)
}
if rs.Attributes[key] != value {
is := rs.Primary
if is == nil {
return fmt.Errorf("No primary instance: %s", name)
}
if is.Attributes[key] != value {
return fmt.Errorf(
"%s: Attribute '%s' expected %#v, got %#v",
name,
key,
value,
rs.Attributes[key])
is.Attributes[key])
}
return nil

View File

@ -18,7 +18,7 @@ func init() {
func TestTest(t *testing.T) {
mp := testProvider()
mp.ApplyReturn = &terraform.ResourceState{
mp.ApplyReturn = &terraform.InstanceState{
ID: "foo",
}
@ -33,13 +33,14 @@ func TestTest(t *testing.T) {
checkStepFn := func(s *terraform.State) error {
checkStep = true
rs, ok := s.Resources["test_instance.foo"]
rs, ok := s.RootModule().Resources["test_instance.foo"]
if !ok {
t.Error("test_instance.foo is not present")
return nil
}
if rs.ID != "foo" {
t.Errorf("bad check ID: %s", rs.ID)
is := rs.Primary
if is.ID != "foo" {
t.Errorf("bad check ID: %s", is.ID)
}
return nil
@ -120,7 +121,7 @@ func TestTest_preCheck(t *testing.T) {
func TestTest_stepError(t *testing.T) {
mp := testProvider()
mp.ApplyReturn = &terraform.ResourceState{
mp.ApplyReturn = &terraform.InstanceState{
ID: "foo",
}
@ -260,7 +261,7 @@ func (t *mockT) failMessage() string {
func testProvider() *terraform.MockResourceProvider {
mp := new(terraform.MockResourceProvider)
mp.DiffReturn = &terraform.ResourceDiff{
mp.DiffReturn = &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"foo": &terraform.ResourceAttrDiff{
New: "bar",

View File

@ -136,11 +136,12 @@ func (p *Provider) Configure(c *terraform.ResourceConfig) error {
// Apply implementation of terraform.ResourceProvider interface.
func (p *Provider) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
r, ok := p.ResourcesMap[s.Type]
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
r, ok := p.ResourcesMap[info.Type]
if !ok {
return nil, fmt.Errorf("unknown resource type: %s", s.Type)
return nil, fmt.Errorf("unknown resource type: %s", info.Type)
}
return r.Apply(s, d, p.meta)
@ -148,11 +149,12 @@ func (p *Provider) Apply(
// Diff implementation of terraform.ResourceProvider interface.
func (p *Provider) Diff(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
r, ok := p.ResourcesMap[s.Type]
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
r, ok := p.ResourcesMap[info.Type]
if !ok {
return nil, fmt.Errorf("unknown resource type: %s", s.Type)
return nil, fmt.Errorf("unknown resource type: %s", info.Type)
}
return r.Diff(s, c)
@ -160,10 +162,11 @@ func (p *Provider) Diff(
// Refresh implementation of terraform.ResourceProvider interface.
func (p *Provider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
r, ok := p.ResourcesMap[s.Type]
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
r, ok := p.ResourcesMap[info.Type]
if !ok {
return nil, fmt.Errorf("unknown resource type: %s", s.Type)
return nil, fmt.Errorf("unknown resource type: %s", info.Type)
}
return r.Refresh(s, p.meta)

View File

@ -61,9 +61,9 @@ type DeleteFunc func(*ResourceData, interface{}) error
// Apply creates, updates, and/or deletes a resource.
func (r *Resource) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff,
meta interface{}) (*terraform.InstanceState, error) {
data, err := schemaMap(r.Schema).Data(s, d)
if err != nil {
return s, err
@ -72,7 +72,7 @@ func (r *Resource) Apply(
if s == nil {
// The Terraform API dictates that this should never happen, but
// it doesn't hurt to be safe in this case.
s = new(terraform.ResourceState)
s = new(terraform.InstanceState)
}
if d.Destroy || d.RequiresNew() {
@ -99,7 +99,7 @@ func (r *Resource) Apply(
err = r.Create(data, meta)
} else {
if r.Update == nil {
return s, fmt.Errorf("%s doesn't support update", s.Type)
return s, fmt.Errorf("doesn't support update")
}
err = r.Update(data, meta)
@ -111,8 +111,8 @@ func (r *Resource) Apply(
// Diff returns a diff of this resource and is API compatible with the
// ResourceProvider interface.
func (r *Resource) Diff(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
return schemaMap(r.Schema).Diff(s, c)
}
@ -123,8 +123,8 @@ func (r *Resource) Validate(c *terraform.ResourceConfig) ([]string, []error) {
// Refresh refreshes the state of the resource.
func (r *Resource) Refresh(
s *terraform.ResourceState,
meta interface{}) (*terraform.ResourceState, error) {
s *terraform.InstanceState,
meta interface{}) (*terraform.InstanceState, error) {
data, err := schemaMap(r.Schema).Data(s, nil)
if err != nil {
return s, err

View File

@ -23,13 +23,13 @@ type ResourceData struct {
// Settable (internally)
schema map[string]*Schema
config *terraform.ResourceConfig
state *terraform.ResourceState
diff *terraform.ResourceDiff
state *terraform.InstanceState
diff *terraform.InstanceDiff
diffing bool
// Don't set
setMap map[string]string
newState *terraform.ResourceState
newState *terraform.InstanceState
partial bool
partialMap map[string]struct{}
once sync.Once
@ -168,24 +168,11 @@ func (d *ResourceData) Id() string {
// ConnInfo returns the connection info for this resource.
func (d *ResourceData) ConnInfo() map[string]string {
if d.newState != nil {
return d.newState.ConnInfo
return d.newState.Ephemeral.ConnInfo
}
if d.state != nil {
return d.state.ConnInfo
}
return nil
}
// Dependencies returns the dependencies in this state.
func (d *ResourceData) Dependencies() []terraform.ResourceDependency {
if d.newState != nil {
return d.newState.Dependencies
}
if d.state != nil {
return d.state.Dependencies
return d.state.Ephemeral.ConnInfo
}
return nil
@ -201,19 +188,13 @@ func (d *ResourceData) SetId(v string) {
// SetConnInfo sets the connection info for a resource.
func (d *ResourceData) SetConnInfo(v map[string]string) {
d.once.Do(d.init)
d.newState.ConnInfo = v
d.newState.Ephemeral.ConnInfo = v
}
// SetDependencies sets the dependencies of a resource.
func (d *ResourceData) SetDependencies(ds []terraform.ResourceDependency) {
d.once.Do(d.init)
d.newState.Dependencies = ds
}
// State returns the new ResourceState after the diff and any Set
// State returns the new InstanceState after the diff and any Set
// calls.
func (d *ResourceData) State() *terraform.ResourceState {
var result terraform.ResourceState
func (d *ResourceData) State() *terraform.InstanceState {
var result terraform.InstanceState
result.ID = d.Id()
// If we have no ID, then this resource doesn't exist and we just
@ -223,8 +204,7 @@ func (d *ResourceData) State() *terraform.ResourceState {
}
result.Attributes = d.stateObject("", d.schema)
result.ConnInfo = d.ConnInfo()
result.Dependencies = d.Dependencies()
result.Ephemeral.ConnInfo = d.ConnInfo()
if v := d.Id(); v != "" {
result.Attributes["id"] = d.Id()
@ -234,7 +214,7 @@ func (d *ResourceData) State() *terraform.ResourceState {
}
func (d *ResourceData) init() {
var copyState terraform.ResourceState
var copyState terraform.InstanceState
if d.state != nil {
copyState = *d.state
}

View File

@ -10,8 +10,8 @@ import (
func TestResourceDataGet(t *testing.T) {
cases := []struct {
Schema map[string]*Schema
State *terraform.ResourceState
Diff *terraform.ResourceDiff
State *terraform.InstanceState
Diff *terraform.InstanceDiff
Key string
Value interface{}
}{
@ -27,7 +27,7 @@ func TestResourceDataGet(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "foo",
@ -53,7 +53,7 @@ func TestResourceDataGet(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -80,7 +80,7 @@ func TestResourceDataGet(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -104,7 +104,7 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "bar",
},
@ -127,13 +127,13 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "foo",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "foo",
@ -157,7 +157,7 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"port": "80",
},
@ -179,7 +179,7 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "3",
"ports.0": "1",
@ -202,7 +202,7 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "3",
"ports.0": "1",
@ -241,7 +241,7 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "3",
"ports.0": "1",
@ -273,7 +273,7 @@ func TestResourceDataGet(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ingress.#": &terraform.ResourceAttrDiff{
Old: "",
@ -311,7 +311,7 @@ func TestResourceDataGet(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ingress.#": &terraform.ResourceAttrDiff{
Old: "",
@ -342,7 +342,7 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "foo",
},
@ -366,7 +366,7 @@ func TestResourceDataGet(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -398,7 +398,7 @@ func TestResourceDataGet(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"config_vars.#": &terraform.ResourceAttrDiff{
Old: "0",
@ -440,7 +440,7 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"config_vars.#": "2",
"config_vars.0.foo": "baz",
@ -475,14 +475,14 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"config_vars.#": "1",
"config_vars.0.FOO": "bar",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"config_vars.#": &terraform.ResourceAttrDiff{
Old: "1",
@ -514,7 +514,7 @@ func TestResourceDataGet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "1",
"ports.0": "80",
@ -549,8 +549,8 @@ func TestResourceDataGet(t *testing.T) {
func TestResourceDataGetChange(t *testing.T) {
cases := []struct {
Schema map[string]*Schema
State *terraform.ResourceState
Diff *terraform.ResourceDiff
State *terraform.InstanceState
Diff *terraform.InstanceDiff
Key string
OldValue interface{}
NewValue interface{}
@ -567,7 +567,7 @@ func TestResourceDataGetChange(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -593,13 +593,13 @@ func TestResourceDataGetChange(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "foo",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -635,8 +635,8 @@ func TestResourceDataGetChange(t *testing.T) {
func TestResourceDataGetOk(t *testing.T) {
cases := []struct {
Schema map[string]*Schema
State *terraform.ResourceState
Diff *terraform.ResourceDiff
State *terraform.InstanceState
Diff *terraform.InstanceDiff
Key string
Value interface{}
Ok bool
@ -656,7 +656,7 @@ func TestResourceDataGetOk(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -798,8 +798,8 @@ func TestResourceDataGetOk(t *testing.T) {
func TestResourceDataHasChange(t *testing.T) {
cases := []struct {
Schema map[string]*Schema
State *terraform.ResourceState
Diff *terraform.ResourceDiff
State *terraform.InstanceState
Diff *terraform.InstanceDiff
Key string
Change bool
}{
@ -815,7 +815,7 @@ func TestResourceDataHasChange(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -840,13 +840,13 @@ func TestResourceDataHasChange(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "foo",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -878,8 +878,8 @@ func TestResourceDataHasChange(t *testing.T) {
func TestResourceDataSet(t *testing.T) {
cases := []struct {
Schema map[string]*Schema
State *terraform.ResourceState
Diff *terraform.ResourceDiff
State *terraform.InstanceState
Diff *terraform.InstanceDiff
Key string
Value interface{}
Err bool
@ -1002,7 +1002,7 @@ func TestResourceDataSet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "3",
"ports.0": "1",
@ -1079,7 +1079,7 @@ func TestResourceDataSet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ingress.#": "2",
"ingress.0.from": "80",
@ -1119,7 +1119,7 @@ func TestResourceDataSet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ingress.#": "2",
"ingress.0.from": "80",
@ -1164,7 +1164,7 @@ func TestResourceDataSet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ingress.#": "2",
"ingress.0.from": "80",
@ -1288,7 +1288,7 @@ func TestResourceDataSet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "3",
"ports.0": "100",
@ -1318,7 +1318,7 @@ func TestResourceDataSet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "3",
"ports.0": "100",
@ -1353,7 +1353,7 @@ func TestResourceDataSet(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "2",
"ports.0": "100",
@ -1394,10 +1394,10 @@ func TestResourceDataSet(t *testing.T) {
func TestResourceDataState(t *testing.T) {
cases := []struct {
Schema map[string]*Schema
State *terraform.ResourceState
Diff *terraform.ResourceDiff
State *terraform.InstanceState
Diff *terraform.InstanceDiff
Set map[string]interface{}
Result *terraform.ResourceState
Result *terraform.InstanceState
Partial []string
}{
// Basic primitive in diff
@ -1413,7 +1413,7 @@ func TestResourceDataState(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -1423,7 +1423,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "foo",
},
@ -1443,7 +1443,7 @@ func TestResourceDataState(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -1457,7 +1457,7 @@ func TestResourceDataState(t *testing.T) {
"availability_zone": "bar",
},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "bar",
},
@ -1480,7 +1480,7 @@ func TestResourceDataState(t *testing.T) {
"vpc": true,
},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"vpc": "true",
},
@ -1500,7 +1500,7 @@ func TestResourceDataState(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -1510,7 +1510,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "foo",
},
@ -1527,14 +1527,14 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "1",
"ports.0": "80",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "1",
@ -1547,7 +1547,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "2",
"ports.0": "80",
@ -1573,14 +1573,14 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ingress.#": "1",
"ingress.0.from": "80",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ingress.#": &terraform.ResourceAttrDiff{
Old: "1",
@ -1597,7 +1597,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"ingress.#": "2",
"ingress.0.from": "150",
@ -1619,7 +1619,7 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"config_vars.#": "2",
"config_vars.0.foo": "bar",
@ -1628,7 +1628,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"config_vars.0.bar": &terraform.ResourceAttrDiff{
NewRemoved: true,
@ -1642,7 +1642,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"config_vars.#": "2",
"config_vars.0.foo": "bar",
@ -1664,14 +1664,14 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"config_vars.#": "1",
"config_vars.0.FOO": "bar",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"config_vars.#": &terraform.ResourceAttrDiff{
Old: "1",
@ -1684,7 +1684,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{},
},
},
@ -1700,14 +1700,14 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
ID: "bar",
Attributes: map[string]string{
"id": "bar",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -1717,7 +1717,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
ID: "bar",
Attributes: map[string]string{
"id": "bar",
@ -1740,7 +1740,7 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "3",
"ports.0": "100",
@ -1751,7 +1751,7 @@ func TestResourceDataState(t *testing.T) {
Diff: nil,
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "2",
"ports.0": "80",
@ -1777,7 +1777,7 @@ func TestResourceDataState(t *testing.T) {
State: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -1789,7 +1789,7 @@ func TestResourceDataState(t *testing.T) {
Partial: []string{},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{},
},
},
@ -1804,14 +1804,14 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "1",
"ports.0": "80",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "1",
@ -1826,7 +1826,7 @@ func TestResourceDataState(t *testing.T) {
Partial: []string{},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "1",
"ports.0": "80",
@ -1851,14 +1851,14 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ingress.#": "1",
"ingress.0.from": "80",
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ingress.#": &terraform.ResourceAttrDiff{
Old: "1",
@ -1877,7 +1877,7 @@ func TestResourceDataState(t *testing.T) {
Partial: []string{},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"ingress.#": "1",
"ingress.0.from": "80",
@ -1898,7 +1898,7 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"config_vars.#": "2",
"config_vars.0.foo": "bar",
@ -1907,7 +1907,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"config_vars.0.bar": &terraform.ResourceAttrDiff{
NewRemoved: true,
@ -1923,7 +1923,7 @@ func TestResourceDataState(t *testing.T) {
Partial: []string{},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"config_vars.#": "2",
"config_vars.0.foo": "bar",
@ -1947,7 +1947,7 @@ func TestResourceDataState(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "3",
"ports.0": "100",
@ -1956,7 +1956,7 @@ func TestResourceDataState(t *testing.T) {
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.1": &terraform.ResourceAttrDiff{
New: "120",
@ -1966,7 +1966,7 @@ func TestResourceDataState(t *testing.T) {
Partial: []string{},
Result: &terraform.ResourceState{
Result: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "2",
"ports.0": "80",
@ -2029,24 +2029,7 @@ func TestResourceDataSetConnInfo(t *testing.T) {
}
actual := d.State()
if !reflect.DeepEqual(actual.ConnInfo, expected) {
t.Fatalf("bad: %#v", actual)
}
}
func TestResourceDataSetDependencies(t *testing.T) {
d := &ResourceData{}
d.SetId("foo")
d.SetDependencies([]terraform.ResourceDependency{
terraform.ResourceDependency{ID: "foo"},
})
expected := []terraform.ResourceDependency{
terraform.ResourceDependency{ID: "foo"},
}
actual := d.State()
if !reflect.DeepEqual(actual.Dependencies, expected) {
if !reflect.DeepEqual(actual.Ephemeral.ConnInfo, expected) {
t.Fatalf("bad: %#v", actual)
}
}
@ -2063,7 +2046,7 @@ func TestResourceDataSetId(t *testing.T) {
func TestResourceDataSetId_clear(t *testing.T) {
d := &ResourceData{
state: &terraform.ResourceState{ID: "bar"},
state: &terraform.InstanceState{ID: "bar"},
}
d.SetId("")
@ -2075,7 +2058,7 @@ func TestResourceDataSetId_clear(t *testing.T) {
func TestResourceDataSetId_override(t *testing.T) {
d := &ResourceData{
state: &terraform.ResourceState{ID: "bar"},
state: &terraform.InstanceState{ID: "bar"},
}
d.SetId("foo")

View File

@ -25,9 +25,9 @@ func TestResourceApply_create(t *testing.T) {
return nil
}
var s *terraform.ResourceState = nil
var s *terraform.InstanceState = nil
d := &terraform.ResourceDiff{
d := &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"foo": &terraform.ResourceAttrDiff{
New: "42",
@ -44,7 +44,7 @@ func TestResourceApply_create(t *testing.T) {
t.Fatal("not called")
}
expected := &terraform.ResourceState{
expected := &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"id": "foo",
@ -73,11 +73,11 @@ func TestResourceApply_destroy(t *testing.T) {
return nil
}
s := &terraform.ResourceState{
s := &terraform.InstanceState{
ID: "bar",
}
d := &terraform.ResourceDiff{
d := &terraform.InstanceDiff{
Destroy: true,
}
@ -110,14 +110,14 @@ func TestResourceApply_destroyPartial(t *testing.T) {
return fmt.Errorf("some error")
}
s := &terraform.ResourceState{
s := &terraform.InstanceState{
ID: "bar",
Attributes: map[string]string{
"foo": "12",
},
}
d := &terraform.ResourceDiff{
d := &terraform.InstanceDiff{
Destroy: true,
}
@ -126,7 +126,7 @@ func TestResourceApply_destroyPartial(t *testing.T) {
t.Fatal("should error")
}
expected := &terraform.ResourceState{
expected := &terraform.InstanceState{
ID: "bar",
Attributes: map[string]string{
"id": "bar",
@ -154,14 +154,14 @@ func TestResourceApply_update(t *testing.T) {
return nil
}
s := &terraform.ResourceState{
s := &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"foo": "12",
},
}
d := &terraform.ResourceDiff{
d := &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"foo": &terraform.ResourceAttrDiff{
New: "13",
@ -174,7 +174,7 @@ func TestResourceApply_update(t *testing.T) {
t.Fatalf("err: %s", err)
}
expected := &terraform.ResourceState{
expected := &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"id": "foo",
@ -199,14 +199,14 @@ func TestResourceApply_updateNoCallback(t *testing.T) {
r.Update = nil
s := &terraform.ResourceState{
s := &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"foo": "12",
},
}
d := &terraform.ResourceDiff{
d := &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"foo": &terraform.ResourceAttrDiff{
New: "13",
@ -219,7 +219,7 @@ func TestResourceApply_updateNoCallback(t *testing.T) {
t.Fatal("should error")
}
expected := &terraform.ResourceState{
expected := &terraform.InstanceState{
ID: "foo",
Attributes: map[string]string{
"foo": "12",
@ -282,14 +282,14 @@ func TestResourceRefresh(t *testing.T) {
return d.Set("foo", d.Get("foo").(int)+1)
}
s := &terraform.ResourceState{
s := &terraform.InstanceState{
ID: "bar",
Attributes: map[string]string{
"foo": "12",
},
}
expected := &terraform.ResourceState{
expected := &terraform.InstanceState{
ID: "bar",
Attributes: map[string]string{
"id": "bar",
@ -322,7 +322,7 @@ func TestResourceRefresh_delete(t *testing.T) {
return nil
}
s := &terraform.ResourceState{
s := &terraform.InstanceState{
ID: "bar",
Attributes: map[string]string{
"foo": "12",

View File

@ -162,8 +162,8 @@ type schemaMap map[string]*Schema
//
// The diff is optional.
func (m schemaMap) Data(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*ResourceData, error) {
s *terraform.InstanceState,
d *terraform.InstanceDiff) (*ResourceData, error) {
return &ResourceData{
schema: m,
state: s,
@ -174,9 +174,9 @@ func (m schemaMap) Data(
// Diff returns the diff for a resource given the schema map,
// state, and configuration.
func (m schemaMap) Diff(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
result := new(terraform.ResourceDiff)
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
result := new(terraform.InstanceDiff)
result.Attributes = make(map[string]*terraform.ResourceAttrDiff)
d := &ResourceData{
@ -199,7 +199,7 @@ func (m schemaMap) Diff(
// caused that.
if result.RequiresNew() {
// Create the new diff
result2 := new(terraform.ResourceDiff)
result2 := new(terraform.InstanceDiff)
result2.Attributes = make(map[string]*terraform.ResourceAttrDiff)
// Reset the data to not contain state
@ -344,7 +344,7 @@ func (m schemaMap) InternalValidate() error {
func (m schemaMap) diff(
k string,
schema *Schema,
diff *terraform.ResourceDiff,
diff *terraform.InstanceDiff,
d *ResourceData) error {
var err error
switch schema.Type {
@ -370,7 +370,7 @@ func (m schemaMap) diff(
func (m schemaMap) diffList(
k string,
schema *Schema,
diff *terraform.ResourceDiff,
diff *terraform.InstanceDiff,
d *ResourceData) error {
o, n, _ := d.diffChange(k)
@ -465,7 +465,7 @@ func (m schemaMap) diffList(
func (m schemaMap) diffMap(
k string,
schema *Schema,
diff *terraform.ResourceDiff,
diff *terraform.InstanceDiff,
d *ResourceData) error {
//elemSchema := &Schema{Type: TypeString}
prefix := k + "."
@ -507,7 +507,7 @@ func (m schemaMap) diffMap(
func (m schemaMap) diffSet(
k string,
schema *Schema,
diff *terraform.ResourceDiff,
diff *terraform.InstanceDiff,
d *ResourceData) error {
return m.diffList(k, schema, diff, d)
}
@ -515,7 +515,7 @@ func (m schemaMap) diffSet(
func (m schemaMap) diffString(
k string,
schema *Schema,
diff *terraform.ResourceDiff,
diff *terraform.InstanceDiff,
d *ResourceData) error {
var originalN interface{}
var os, ns string

View File

@ -11,10 +11,10 @@ import (
func TestSchemaMap_Diff(t *testing.T) {
cases := []struct {
Schema map[string]*Schema
State *terraform.ResourceState
State *terraform.InstanceState
Config map[string]interface{}
ConfigVariables map[string]string
Diff *terraform.ResourceDiff
Diff *terraform.InstanceDiff
Err bool
}{
/*
@ -37,7 +37,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"availability_zone": "foo",
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -64,7 +64,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Config: map[string]interface{}{},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -87,7 +87,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
ID: "foo",
},
@ -112,7 +112,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Config: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -140,7 +140,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Config: nil,
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -170,7 +170,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"availability_zone": "bar",
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -201,7 +201,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"availability_zone": "foo",
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -233,7 +233,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"var.foo": "bar",
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -264,7 +264,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"var.foo": config.UnknownVariableValue,
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "",
@ -296,7 +296,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"port": 27,
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"port": &terraform.ResourceAttrDiff{
Old: "",
@ -329,7 +329,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"port": false,
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"port": &terraform.ResourceAttrDiff{
Old: "",
@ -361,7 +361,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"ports": []interface{}{1, 2, 5},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "0",
@ -394,7 +394,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "3",
"ports.0": "1",
@ -421,7 +421,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "2",
"ports.0": "1",
@ -433,7 +433,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"ports": []interface{}{1, 2, 5},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "2",
@ -465,7 +465,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"ports": []interface{}{1, 2, 5},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "0",
@ -507,7 +507,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Config: map[string]interface{}{},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "",
@ -541,7 +541,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"ports": []interface{}{5, 2, 1},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "0",
@ -577,7 +577,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "2",
"ports.0": "2",
@ -589,7 +589,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"ports": []interface{}{5, 2, 1},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "2",
@ -617,7 +617,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"ports.#": "2",
"ports.0": "2",
@ -627,7 +627,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Config: map[string]interface{}{},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ports.#": &terraform.ResourceAttrDiff{
Old: "2",
@ -658,7 +658,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "bar",
"ports.#": "1",
@ -703,7 +703,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"ingress.#": &terraform.ResourceAttrDiff{
Old: "0",
@ -737,7 +737,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "foo",
"port": "80",
@ -767,7 +767,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"port": "80",
},
@ -777,7 +777,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"port": 80,
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
NewComputed: true,
@ -803,7 +803,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "foo",
"port": "80",
@ -843,7 +843,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"config_vars.#": "1",
"config_vars.0.foo": "bar",
@ -858,7 +858,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"config_vars.0.foo": &terraform.ResourceAttrDiff{
Old: "bar",
@ -882,7 +882,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"config_vars.#": "1",
"config_vars.0.foo": "bar",
@ -892,7 +892,7 @@ func TestSchemaMap_Diff(t *testing.T) {
Config: map[string]interface{}{},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"config_vars.#": &terraform.ResourceAttrDiff{
Old: "1",
@ -931,7 +931,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "bar",
"address": "foo",
@ -942,7 +942,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"availability_zone": "foo",
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "bar",
@ -979,7 +979,7 @@ func TestSchemaMap_Diff(t *testing.T) {
},
},
State: &terraform.ResourceState{
State: &terraform.InstanceState{
Attributes: map[string]string{
"availability_zone": "bar",
"ports.#": "1",
@ -991,7 +991,7 @@ func TestSchemaMap_Diff(t *testing.T) {
"availability_zone": "foo",
},
Diff: &terraform.ResourceDiff{
Diff: &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"availability_zone": &terraform.ResourceAttrDiff{
Old: "bar",

View File

@ -43,8 +43,8 @@ type SSHConfig struct {
}
// VerifySSH is used to verify the ConnInfo is usable by remote-exec
func VerifySSH(s *terraform.ResourceState) error {
connType := s.ConnInfo["type"]
func VerifySSH(s *terraform.InstanceState) error {
connType := s.Ephemeral.ConnInfo["type"]
switch connType {
case "":
case "ssh":
@ -54,9 +54,9 @@ func VerifySSH(s *terraform.ResourceState) error {
return nil
}
// ParseSSHConfig is used to convert the ConnInfo of the ResourceState into
// ParseSSHConfig is used to convert the ConnInfo of the InstanceState into
// a SSHConfig struct
func ParseSSHConfig(s *terraform.ResourceState) (*SSHConfig, error) {
func ParseSSHConfig(s *terraform.InstanceState) (*SSHConfig, error) {
sshConf := &SSHConfig{}
decConf := &mapstructure.DecoderConfig{
WeaklyTypedInput: true,
@ -66,7 +66,7 @@ func ParseSSHConfig(s *terraform.ResourceState) (*SSHConfig, error) {
if err != nil {
return nil, err
}
if err := dec.Decode(s.ConnInfo); err != nil {
if err := dec.Decode(s.Ephemeral.ConnInfo); err != nil {
return nil, err
}
if sshConf.User == "" {

View File

@ -7,30 +7,34 @@ import (
)
func TestResourceProvider_verifySSH(t *testing.T) {
r := &terraform.ResourceState{
ConnInfo: map[string]string{
"type": "telnet",
r := &terraform.InstanceState{
Ephemeral: terraform.EphemeralState{
ConnInfo: map[string]string{
"type": "telnet",
},
},
}
if err := VerifySSH(r); err == nil {
t.Fatalf("expected error with telnet")
}
r.ConnInfo["type"] = "ssh"
r.Ephemeral.ConnInfo["type"] = "ssh"
if err := VerifySSH(r); err != nil {
t.Fatalf("err: %v", err)
}
}
func TestResourceProvider_sshConfig(t *testing.T) {
r := &terraform.ResourceState{
ConnInfo: map[string]string{
"type": "ssh",
"user": "root",
"password": "supersecret",
"key_file": "/my/key/file.pem",
"host": "127.0.0.1",
"port": "22",
"timeout": "30s",
r := &terraform.InstanceState{
Ephemeral: terraform.EphemeralState{
ConnInfo: map[string]string{
"type": "ssh",
"user": "root",
"password": "supersecret",
"key_file": "/my/key/file.pem",
"host": "127.0.0.1",
"port": "22",
"timeout": "30s",
},
},
}

View File

@ -19,7 +19,7 @@ import (
// The APIVersion is outputted along with the RPC address. The plugin
// client validates this API version and will show an error if it doesn't
// know how to speak it.
const APIVersion = "1"
const APIVersion = "2"
// The "magic cookie" is used to verify that the user intended to
// actually run this binary. If this cookie isn't present as an

View File

@ -73,10 +73,12 @@ func (p *ResourceProvider) Configure(c *terraform.ResourceConfig) error {
}
func (p *ResourceProvider) Apply(
s *terraform.ResourceState,
d *terraform.ResourceDiff) (*terraform.ResourceState, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
d *terraform.InstanceDiff) (*terraform.InstanceState, error) {
var resp ResourceProviderApplyResponse
args := &ResourceProviderApplyArgs{
Info: info,
State: s,
Diff: d,
}
@ -93,10 +95,12 @@ func (p *ResourceProvider) Apply(
}
func (p *ResourceProvider) Diff(
s *terraform.ResourceState,
c *terraform.ResourceConfig) (*terraform.ResourceDiff, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState,
c *terraform.ResourceConfig) (*terraform.InstanceDiff, error) {
var resp ResourceProviderDiffResponse
args := &ResourceProviderDiffArgs{
Info: info,
State: s,
Config: c,
}
@ -112,9 +116,15 @@ func (p *ResourceProvider) Diff(
}
func (p *ResourceProvider) Refresh(
s *terraform.ResourceState) (*terraform.ResourceState, error) {
info *terraform.InstanceInfo,
s *terraform.InstanceState) (*terraform.InstanceState, error) {
var resp ResourceProviderRefreshResponse
err := p.Client.Call(p.Name+".Refresh", s, &resp)
args := &ResourceProviderRefreshArgs{
Info: info,
State: s,
}
err := p.Client.Call(p.Name+".Refresh", args, &resp)
if err != nil {
return nil, err
}
@ -148,27 +158,34 @@ type ResourceProviderConfigureResponse struct {
}
type ResourceProviderApplyArgs struct {
State *terraform.ResourceState
Diff *terraform.ResourceDiff
Info *terraform.InstanceInfo
State *terraform.InstanceState
Diff *terraform.InstanceDiff
}
type ResourceProviderApplyResponse struct {
State *terraform.ResourceState
State *terraform.InstanceState
Error *BasicError
}
type ResourceProviderDiffArgs struct {
State *terraform.ResourceState
Info *terraform.InstanceInfo
State *terraform.InstanceState
Config *terraform.ResourceConfig
}
type ResourceProviderDiffResponse struct {
Diff *terraform.ResourceDiff
Diff *terraform.InstanceDiff
Error *BasicError
}
type ResourceProviderRefreshArgs struct {
Info *terraform.InstanceInfo
State *terraform.InstanceState
}
type ResourceProviderRefreshResponse struct {
State *terraform.ResourceState
State *terraform.InstanceState
Error *BasicError
}
@ -234,7 +251,7 @@ func (s *ResourceProviderServer) Configure(
func (s *ResourceProviderServer) Apply(
args *ResourceProviderApplyArgs,
result *ResourceProviderApplyResponse) error {
state, err := s.Provider.Apply(args.State, args.Diff)
state, err := s.Provider.Apply(args.Info, args.State, args.Diff)
*result = ResourceProviderApplyResponse{
State: state,
Error: NewBasicError(err),
@ -245,7 +262,7 @@ func (s *ResourceProviderServer) Apply(
func (s *ResourceProviderServer) Diff(
args *ResourceProviderDiffArgs,
result *ResourceProviderDiffResponse) error {
diff, err := s.Provider.Diff(args.State, args.Config)
diff, err := s.Provider.Diff(args.Info, args.State, args.Config)
*result = ResourceProviderDiffResponse{
Diff: diff,
Error: NewBasicError(err),
@ -254,9 +271,9 @@ func (s *ResourceProviderServer) Diff(
}
func (s *ResourceProviderServer) Refresh(
state *terraform.ResourceState,
args *ResourceProviderRefreshArgs,
result *ResourceProviderRefreshResponse) error {
newState, err := s.Provider.Refresh(state)
newState, err := s.Provider.Refresh(args.Info, args.State)
*result = ResourceProviderRefreshResponse{
State: newState,
Error: NewBasicError(err),

View File

@ -101,14 +101,15 @@ func TestResourceProvider_apply(t *testing.T) {
}
provider := &ResourceProvider{Client: client, Name: name}
p.ApplyReturn = &terraform.ResourceState{
p.ApplyReturn = &terraform.InstanceState{
ID: "bob",
}
// Apply
state := &terraform.ResourceState{}
diff := &terraform.ResourceDiff{}
newState, err := provider.Apply(state, diff)
info := &terraform.InstanceInfo{}
state := &terraform.InstanceState{}
diff := &terraform.InstanceDiff{}
newState, err := provider.Apply(info, state, diff)
if !p.ApplyCalled {
t.Fatal("apply should be called")
}
@ -132,7 +133,7 @@ func TestResourceProvider_diff(t *testing.T) {
}
provider := &ResourceProvider{Client: client, Name: name}
p.DiffReturn = &terraform.ResourceDiff{
p.DiffReturn = &terraform.InstanceDiff{
Attributes: map[string]*terraform.ResourceAttrDiff{
"foo": &terraform.ResourceAttrDiff{
Old: "",
@ -142,11 +143,12 @@ func TestResourceProvider_diff(t *testing.T) {
}
// Diff
state := &terraform.ResourceState{}
info := &terraform.InstanceInfo{}
state := &terraform.InstanceState{}
config := &terraform.ResourceConfig{
Raw: map[string]interface{}{"foo": "bar"},
}
diff, err := provider.Diff(state, config)
diff, err := provider.Diff(info, state, config)
if !p.DiffCalled {
t.Fatal("diff should be called")
}
@ -173,11 +175,12 @@ func TestResourceProvider_diff_error(t *testing.T) {
p.DiffReturnError = errors.New("foo")
// Diff
state := &terraform.ResourceState{}
info := &terraform.InstanceInfo{}
state := &terraform.InstanceState{}
config := &terraform.ResourceConfig{
Raw: map[string]interface{}{"foo": "bar"},
}
diff, err := provider.Diff(state, config)
diff, err := provider.Diff(info, state, config)
if !p.DiffCalled {
t.Fatal("diff should be called")
}
@ -201,13 +204,14 @@ func TestResourceProvider_refresh(t *testing.T) {
}
provider := &ResourceProvider{Client: client, Name: name}
p.RefreshReturn = &terraform.ResourceState{
p.RefreshReturn = &terraform.InstanceState{
ID: "bob",
}
// Refresh
state := &terraform.ResourceState{}
newState, err := provider.Refresh(state)
info := &terraform.InstanceInfo{}
state := &terraform.InstanceState{}
newState, err := provider.Refresh(info, state)
if !p.RefreshCalled {
t.Fatal("refresh should be called")
}

View File

@ -36,7 +36,7 @@ func (p *ResourceProvisioner) Validate(c *terraform.ResourceConfig) ([]string, [
}
func (p *ResourceProvisioner) Apply(
s *terraform.ResourceState,
s *terraform.InstanceState,
c *terraform.ResourceConfig) error {
var resp ResourceProvisionerApplyResponse
args := &ResourceProvisionerApplyArgs{
@ -65,7 +65,7 @@ type ResourceProvisionerValidateResponse struct {
}
type ResourceProvisionerApplyArgs struct {
State *terraform.ResourceState
State *terraform.InstanceState
Config *terraform.ResourceConfig
}

View File

@ -22,7 +22,7 @@ func TestResourceProvisioner_apply(t *testing.T) {
provisioner := &ResourceProvisioner{Client: client, Name: name}
// Apply
state := &terraform.ResourceState{}
state := &terraform.InstanceState{}
conf := &terraform.ResourceConfig{}
err = provisioner.Apply(state, conf)
if !p.ApplyCalled {

View File

@ -121,6 +121,13 @@ func (c *Context) Apply() (*State, error) {
// Set our state right away. No matter what, this IS our new state,
// even if there is an error below.
c.state = c.state.deepcopy()
if c.state == nil {
c.state = &State{}
}
c.state.init()
// Initialize the state with all the resources
graphInitState(c.state, g)
// Walk
log.Printf("[INFO] Apply walk starting")
@ -131,15 +138,18 @@ func (c *Context) Apply() (*State, error) {
c.state.prune()
// If we have no errors, then calculate the outputs if we have any
if err == nil && len(c.config.Outputs) > 0 && len(c.state.Resources) > 0 {
c.state.Outputs = make(map[string]string)
root := c.state.RootModule()
if err == nil && len(c.config.Outputs) > 0 && len(root.Resources) > 0 {
outputs := make(map[string]string)
for _, o := range c.config.Outputs {
if err = c.computeVars(o.RawConfig); err != nil {
break
}
c.state.Outputs[o.Name] = o.RawConfig.Config()["value"].(string)
outputs[o.Name] = o.RawConfig.Config()["value"].(string)
}
// Assign the outputs to the root module
root.Outputs = outputs
}
return c.state, err
@ -188,11 +198,19 @@ func (c *Context) Plan(opts *PlanOpts) (*Plan, error) {
// the plan can update a fake state so that variables work, then
// we replace it back with our old state.
old := c.state
c.state = old.deepcopy()
if old == nil {
c.state = &State{}
c.state.init()
} else {
c.state = old.deepcopy()
}
defer func() {
c.state = old
}()
// Initialize the state with all the resources
graphInitState(c.state, g)
walkFn = c.planWalkFn(p)
}
@ -215,6 +233,9 @@ func (c *Context) Refresh() (*State, error) {
v := c.acquireRun()
defer c.releaseRun(v)
// Update our state
c.state = c.state.deepcopy()
g, err := Graph(&GraphOpts{
Config: c.config,
Providers: c.providers,
@ -225,10 +246,16 @@ func (c *Context) Refresh() (*State, error) {
return c.state, err
}
// Update our state
c.state = c.state.deepcopy()
if c.state != nil {
// Initialize the state with all the resources
graphInitState(c.state, g)
}
// Walk the graph
err = g.Walk(c.refreshWalkFn())
// Prune the state
c.state.prune()
return c.state, err
}
@ -358,7 +385,11 @@ func (c *Context) computeResourceVariable(
c.sl.RLock()
defer c.sl.RUnlock()
r, ok := c.state.Resources[id]
// Get the relevant module
// TODO: Not use only root module
module := c.state.RootModule()
r, ok := module.Resources[id]
if !ok {
return "", fmt.Errorf(
"Resource '%s' not found for variable '%s'",
@ -366,8 +397,11 @@ func (c *Context) computeResourceVariable(
v.FullKey())
}
attr, ok := r.Attributes[v.Field]
if ok {
if r.Primary == nil {
goto MISSING
}
if attr, ok := r.Primary.Attributes[v.Field]; ok {
return attr, nil
}
@ -375,16 +409,16 @@ func (c *Context) computeResourceVariable(
// and see if anything along the way is a computed set. i.e. if
// we have "foo.0.bar" as the field, check to see if "foo" is
// a computed list. If so, then the whole thing is computed.
parts := strings.Split(v.Field, ".")
if len(parts) > 1 {
if parts := strings.Split(v.Field, "."); len(parts) > 1 {
for i := 1; i < len(parts); i++ {
key := fmt.Sprintf("%s.#", strings.Join(parts[:i], "."))
if attr, ok := r.Attributes[key]; ok {
if attr, ok := r.Primary.Attributes[key]; ok {
return attr, nil
}
}
}
MISSING:
return "", fmt.Errorf(
"Resource '%s' does not have attribute '%s' "+
"for variable '%s'",
@ -414,6 +448,10 @@ func (c *Context) computeResourceMultiVariable(
v.FullKey())
}
// Get the relevant module
// TODO: Not use only root module
module := c.state.RootModule()
var values []string
for i := 0; i < cr.Count; i++ {
id := fmt.Sprintf("%s.%d", v.ResourceId(), i)
@ -424,12 +462,16 @@ func (c *Context) computeResourceMultiVariable(
id = v.ResourceId()
}
r, ok := c.state.Resources[id]
r, ok := module.Resources[id]
if !ok {
continue
}
attr, ok := r.Attributes[v.Field]
if r.Primary == nil {
continue
}
attr, ok := r.Primary.Attributes[v.Field]
if !ok {
continue
}
@ -495,13 +537,19 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
return nil
}
is := r.State
if is == nil {
is = new(InstanceState)
}
is.init()
if !diff.Destroy {
// Since we need the configuration, interpolate the variables
if err := r.Config.interpolate(c); err != nil {
return err
}
diff, err = r.Provider.Diff(r.State, r.Config)
diff, err = r.Provider.Diff(r.Info, is, r.Config)
if err != nil {
return err
}
@ -533,11 +581,6 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
}
}
// If we do not have any connection info, initialize
if r.State.ConnInfo == nil {
r.State.ConnInfo = make(map[string]string)
}
// Remove any output values from the diff
for k, ad := range diff.Attributes {
if ad.Type == DiffAttrOutput {
@ -546,12 +589,12 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
}
for _, h := range c.hooks {
handleHook(h.PreApply(r.Id, r.State, diff))
handleHook(h.PreApply(r.Id, is, diff))
}
// With the completed diff, apply!
log.Printf("[DEBUG] %s: Executing Apply", r.Id)
rs, applyerr := r.Provider.Apply(r.State, diff)
is, applyerr := r.Provider.Apply(r.Info, is, diff)
var errs []error
if applyerr != nil {
@ -559,46 +602,29 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
}
// Make sure the result is instantiated
if rs == nil {
rs = new(ResourceState)
if is == nil {
is = new(InstanceState)
}
// Force the resource state type to be our type
rs.Type = r.State.Type
is.init()
// Force the "id" attribute to be our ID
if rs.ID != "" {
if rs.Attributes == nil {
rs.Attributes = make(map[string]string)
}
rs.Attributes["id"] = rs.ID
if is.ID != "" {
is.Attributes["id"] = is.ID
}
for ak, av := range rs.Attributes {
for ak, av := range is.Attributes {
// If the value is the unknown variable value, then it is an error.
// In this case we record the error and remove it from the state
if av == config.UnknownVariableValue {
errs = append(errs, fmt.Errorf(
"Attribute with unknown value: %s", ak))
delete(rs.Attributes, ak)
delete(is.Attributes, ak)
}
}
// Update the resulting diff
c.sl.Lock()
if rs.ID == "" {
delete(c.state.Resources, r.Id)
delete(c.state.Tainted, r.Id)
} else {
c.state.Resources[r.Id] = rs
// We always mark the resource as tainted here in case a
// hook below during provisioning does HookActionStop. This
// way, we keep the resource tainted.
c.state.Tainted[r.Id] = struct{}{}
}
c.sl.Unlock()
// Set the result state
r.State = is
c.persistState(r)
// Invoke any provisioners we have defined. This is only done
// if the resource was created, as updates or deletes do not
@ -607,36 +633,32 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
// Additionally, we need to be careful to not run this if there
// was an error during the provider apply.
tainted := false
if applyerr == nil && r.State.ID == "" && len(r.Provisioners) > 0 {
if applyerr == nil && is.ID != "" && len(r.Provisioners) > 0 {
for _, h := range c.hooks {
handleHook(h.PreProvisionResource(r.Id, r.State))
handleHook(h.PreProvisionResource(r.Id, is))
}
if err := c.applyProvisioners(r, rs); err != nil {
if err := c.applyProvisioners(r, is); err != nil {
errs = append(errs, err)
tainted = true
}
for _, h := range c.hooks {
handleHook(h.PostProvisionResource(r.Id, r.State))
handleHook(h.PostProvisionResource(r.Id, is))
}
}
c.sl.Lock()
if tainted {
log.Printf("[DEBUG] %s: Marking as tainted", r.Id)
c.state.Tainted[r.Id] = struct{}{}
} else {
delete(c.state.Tainted, r.Id)
// If we're tainted then we need to update some flags
if tainted && r.Flags&FlagTainted == 0 {
r.Flags &^= FlagPrimary
r.Flags &^= FlagHasTainted
r.Flags |= FlagTainted
r.TaintedIndex = -1
c.persistState(r)
}
c.sl.Unlock()
// Update the state for the resource itself
r.State = rs
r.Tainted = tainted
for _, h := range c.hooks {
handleHook(h.PostApply(r.Id, r.State, applyerr))
handleHook(h.PostApply(r.Id, is, applyerr))
}
// Determine the new state and update variables
@ -653,11 +675,11 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc {
// applyProvisioners is used to run any provisioners a resource has
// defined after the resource creation has already completed.
func (c *Context) applyProvisioners(r *Resource, rs *ResourceState) error {
func (c *Context) applyProvisioners(r *Resource, is *InstanceState) error {
// Store the original connection info, restore later
origConnInfo := rs.ConnInfo
origConnInfo := is.Ephemeral.ConnInfo
defer func() {
rs.ConnInfo = origConnInfo
is.Ephemeral.ConnInfo = origConnInfo
}()
for _, prov := range r.Provisioners {
@ -700,14 +722,14 @@ func (c *Context) applyProvisioners(r *Resource, rs *ResourceState) error {
overlay[k] = fmt.Sprintf("%v", vt)
}
}
rs.ConnInfo = overlay
is.Ephemeral.ConnInfo = overlay
// Invoke the Provisioner
for _, h := range c.hooks {
handleHook(h.PreProvision(r.Id, prov.Type))
}
if err := prov.Provisioner.Apply(rs, prov.Config); err != nil {
if err := prov.Provisioner.Apply(is, prov.Config); err != nil {
return err
}
@ -726,17 +748,24 @@ func (c *Context) planWalkFn(result *Plan) depgraph.WalkFunc {
result.init()
cb := func(r *Resource) error {
var diff *ResourceDiff
for _, h := range c.hooks {
handleHook(h.PreDiff(r.Id, r.State))
if r.Flags&FlagTainted != 0 {
// We don't diff tainted resources.
return nil
}
if r.Config == nil {
var diff *InstanceDiff
is := r.State
for _, h := range c.hooks {
handleHook(h.PreDiff(r.Id, is))
}
if r.Flags&FlagOrphan != 0 {
log.Printf("[DEBUG] %s: Orphan, marking for destroy", r.Id)
// This is an orphan (no config), so we mark it to be destroyed
diff = &ResourceDiff{Destroy: true}
diff = &InstanceDiff{Destroy: true}
} else {
// Make sure the configuration is interpolated
if err := r.Config.interpolate(c); err != nil {
@ -746,38 +775,46 @@ func (c *Context) planWalkFn(result *Plan) depgraph.WalkFunc {
// Get a diff from the newest state
log.Printf("[DEBUG] %s: Executing diff", r.Id)
var err error
state := r.State
if r.Tainted {
diffIs := is
if diffIs == nil || r.Flags&FlagHasTainted != 0 {
// If we're tainted, we pretend to create a new thing.
state = new(ResourceState)
state.Type = r.State.Type
diffIs = new(InstanceState)
}
diff, err = r.Provider.Diff(state, r.Config)
diffIs.init()
diff, err = r.Provider.Diff(r.Info, diffIs, r.Config)
if err != nil {
return err
}
}
if diff == nil {
diff = new(ResourceDiff)
diff = new(InstanceDiff)
}
if r.Tainted {
// Tainted resources must also be destroyed
log.Printf("[DEBUG] %s: Tainted, marking for destroy", r.Id)
diff.Destroy = true
if r.Flags&FlagHasTainted != 0 {
// This primary has a tainted resource, so just mark for
// destroy...
log.Printf("[DEBUG] %s: Tainted children, marking for destroy", r.Id)
diff.DestroyTainted = true
}
if diff.RequiresNew() && r.State.ID != "" {
if diff.RequiresNew() && is != nil && is.ID != "" {
// This will also require a destroy
diff.Destroy = true
}
if diff.RequiresNew() || r.State.ID == "" {
if diff.RequiresNew() || is == nil || is.ID == "" {
var oldID string
if is != nil {
oldID = is.Attributes["id"]
}
// Add diff to compute new ID
diff.init()
diff.Attributes["id"] = &ResourceAttrDiff{
Old: r.State.Attributes["id"],
Old: oldID,
NewComputed: true,
RequiresNew: true,
Type: DiffAttrOutput,
@ -796,13 +833,12 @@ func (c *Context) planWalkFn(result *Plan) depgraph.WalkFunc {
// Determine the new state and update variables
if !diff.Empty() {
r.State = r.State.MergeDiff(diff)
is = is.MergeDiff(diff)
}
// Update our internal state so that variable computation works
c.sl.Lock()
defer c.sl.Unlock()
c.state.Resources[r.Id] = r.State
// Set it so that it can be updated
r.State = is
c.persistState(r)
return nil
}
@ -823,12 +859,12 @@ func (c *Context) planDestroyWalkFn(result *Plan) depgraph.WalkFunc {
}
r := rn.Resource
if r.State.ID != "" {
if r.State != nil && r.State.ID != "" {
log.Printf("[DEBUG] %s: Making for destroy", r.Id)
l.Lock()
defer l.Unlock()
result.Diff.Resources[r.Id] = &ResourceDiff{Destroy: true}
result.Diff.Resources[r.Id] = &InstanceDiff{Destroy: true}
} else {
log.Printf("[DEBUG] %s: Not marking for destroy, no ID", r.Id)
}
@ -839,36 +875,32 @@ func (c *Context) planDestroyWalkFn(result *Plan) depgraph.WalkFunc {
func (c *Context) refreshWalkFn() depgraph.WalkFunc {
cb := func(r *Resource) error {
if r.State.ID == "" {
is := r.State
if is == nil || is.ID == "" {
log.Printf("[DEBUG] %s: Not refreshing, ID is empty", r.Id)
return nil
}
for _, h := range c.hooks {
handleHook(h.PreRefresh(r.Id, r.State))
handleHook(h.PreRefresh(r.Id, is))
}
rs, err := r.Provider.Refresh(r.State)
is, err := r.Provider.Refresh(r.Info, is)
if err != nil {
return err
}
if rs == nil {
rs = new(ResourceState)
if is == nil {
is = new(InstanceState)
is.init()
}
// Fix the type to be the type we have
rs.Type = r.State.Type
c.sl.Lock()
if rs.ID == "" {
delete(c.state.Resources, r.Id)
} else {
c.state.Resources[r.Id] = rs
}
c.sl.Unlock()
// Set the updated state
r.State = is
c.persistState(r)
for _, h := range c.hooks {
handleHook(h.PostRefresh(r.Id, rs))
handleHook(h.PostRefresh(r.Id, is))
}
return nil
@ -898,13 +930,13 @@ func (c *Context) validateWalkFn(rws *[]string, res *[]error) depgraph.WalkFunc
}
// Don't validate orphans since they never have a config
if rn.Orphan {
if rn.Resource.Flags&FlagOrphan != 0 {
return nil
}
log.Printf("[INFO] Validating resource: %s", rn.Resource.Id)
ws, es := rn.Resource.Provider.ValidateResource(
rn.Type, rn.Resource.Config)
rn.Resource.Info.Type, rn.Resource.Config)
for i, w := range ws {
ws[i] = fmt.Sprintf("'%s' warning: %s", rn.Resource.Id, w)
}
@ -1014,14 +1046,10 @@ func (c *Context) genericWalkFn(cb genericWalkFunc) depgraph.WalkFunc {
rn := n.Meta.(*GraphNodeResource)
// Make sure that at least some resource configuration is set
if !rn.Orphan {
if rn.Config == nil {
rn.Resource.Config = new(ResourceConfig)
} else {
rn.Resource.Config = NewResourceConfig(rn.Config.RawConfig)
}
if rn.Config == nil {
rn.Resource.Config = new(ResourceConfig)
} else {
rn.Resource.Config = nil
rn.Resource.Config = NewResourceConfig(rn.Config.RawConfig)
}
// Handle recovery of special panic scenarios
@ -1048,3 +1076,43 @@ func (c *Context) genericWalkFn(cb genericWalkFunc) depgraph.WalkFunc {
return nil
}
}
func (c *Context) persistState(r *Resource) {
// Acquire a state lock around this whole thing since we're updating that
c.sl.Lock()
defer c.sl.Unlock()
// If we have no state, then we don't persist.
if c.state == nil {
return
}
// Get the state for this resource. The resource state should always
// exist because we call graphInitState before anything that could
// potentially call this.
module := c.state.RootModule()
rs := module.Resources[r.Id]
if rs == nil {
panic(fmt.Sprintf("nil ResourceState for ID: %s", r.Id))
}
// Assign the instance state to the proper location
if r.Flags&FlagTainted != 0 {
if r.TaintedIndex >= 0 {
// Tainted with a pre-existing index, just update that spot
rs.Tainted[r.TaintedIndex] = r.State
} else {
// Newly tainted, so append it to the list, update the
// index, and remove the primary.
rs.Tainted = append(rs.Tainted, r.State)
rs.Primary = nil
r.TaintedIndex = len(rs.Tainted) - 1
}
} else {
// The primary instance, so just set it directly
rs.Primary = r.State
}
// Do a pruning so that empty resources are not saved
rs.prune()
}

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@ const diffFormatByte byte = 1
// Diff tracks the differences between resources to apply.
type Diff struct {
Resources map[string]*ResourceDiff
Resources map[string]*InstanceDiff
once sync.Once
}
@ -64,7 +64,7 @@ func WriteDiff(d *Diff, dst io.Writer) error {
func (d *Diff) init() {
d.once.Do(func() {
if d.Resources == nil {
d.Resources = make(map[string]*ResourceDiff)
d.Resources = make(map[string]*InstanceDiff)
}
})
}
@ -99,7 +99,7 @@ func (d *Diff) String() string {
rdiff := d.Resources[name]
crud := "UPDATE"
if rdiff.RequiresNew() && rdiff.Destroy {
if rdiff.RequiresNew() && (rdiff.Destroy || rdiff.DestroyTainted) {
crud = "DESTROY/CREATE"
} else if rdiff.Destroy {
crud = "DESTROY"
@ -152,10 +152,11 @@ func (d *Diff) String() string {
return buf.String()
}
// ResourceDiff is the diff of a resource from some state to another.
type ResourceDiff struct {
Attributes map[string]*ResourceAttrDiff
Destroy bool
// InstanceDiff is the diff of a resource from some state to another.
type InstanceDiff struct {
Attributes map[string]*ResourceAttrDiff
Destroy bool
DestroyTainted bool
once sync.Once
}
@ -188,7 +189,7 @@ const (
DiffAttrOutput
)
func (d *ResourceDiff) init() {
func (d *InstanceDiff) init() {
d.once.Do(func() {
if d.Attributes == nil {
d.Attributes = make(map[string]*ResourceAttrDiff)
@ -197,7 +198,7 @@ func (d *ResourceDiff) init() {
}
// Empty returns true if this diff encapsulates no changes.
func (d *ResourceDiff) Empty() bool {
func (d *InstanceDiff) Empty() bool {
if d == nil {
return true
}
@ -207,7 +208,7 @@ func (d *ResourceDiff) Empty() bool {
// RequiresNew returns true if the diff requires the creation of a new
// resource (implying the destruction of the old).
func (d *ResourceDiff) RequiresNew() bool {
func (d *InstanceDiff) RequiresNew() bool {
if d == nil {
return false
}
@ -221,11 +222,11 @@ func (d *ResourceDiff) RequiresNew() bool {
return false
}
// Same checks whether or not to ResourceDiffs are the "same." When
// Same checks whether or not to InstanceDiff are the "same." When
// we say "same", it is not necessarily exactly equal. Instead, it is
// just checking that the same attributes are changing, a destroy
// isn't suddenly happening, etc.
func (d *ResourceDiff) Same(d2 *ResourceDiff) bool {
func (d *InstanceDiff) Same(d2 *InstanceDiff) bool {
if d == nil && d2 == nil {
return true
} else if d == nil || d2 == nil {

View File

@ -13,8 +13,8 @@ func TestDiff_Empty(t *testing.T) {
t.Fatal("should be empty")
}
diff.Resources = map[string]*ResourceDiff{
"nodeA": &ResourceDiff{},
diff.Resources = map[string]*InstanceDiff{
"nodeA": &InstanceDiff{},
}
if !diff.Empty() {
@ -42,8 +42,8 @@ func TestDiff_Empty(t *testing.T) {
func TestDiff_String(t *testing.T) {
diff := &Diff{
Resources: map[string]*ResourceDiff{
"nodeA": &ResourceDiff{
Resources: map[string]*InstanceDiff{
"nodeA": &InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{
Old: "foo",
@ -71,25 +71,25 @@ func TestDiff_String(t *testing.T) {
}
func TestResourceDiff_Empty(t *testing.T) {
var rd *ResourceDiff
var rd *InstanceDiff
if !rd.Empty() {
t.Fatal("should be empty")
}
rd = new(ResourceDiff)
rd = new(InstanceDiff)
if !rd.Empty() {
t.Fatal("should be empty")
}
rd = &ResourceDiff{Destroy: true}
rd = &InstanceDiff{Destroy: true}
if rd.Empty() {
t.Fatal("should not be empty")
}
rd = &ResourceDiff{
rd = &InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{
New: "bar",
@ -103,7 +103,7 @@ func TestResourceDiff_Empty(t *testing.T) {
}
func TestResourceDiff_RequiresNew(t *testing.T) {
rd := &ResourceDiff{
rd := &InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{},
},
@ -121,7 +121,7 @@ func TestResourceDiff_RequiresNew(t *testing.T) {
}
func TestResourceDiff_RequiresNew_nil(t *testing.T) {
var rd *ResourceDiff
var rd *InstanceDiff
if rd.RequiresNew() {
t.Fatal("should not require new")
@ -130,12 +130,12 @@ func TestResourceDiff_RequiresNew_nil(t *testing.T) {
func TestResourceDiffSame(t *testing.T) {
cases := []struct {
One, Two *ResourceDiff
One, Two *InstanceDiff
Same bool
}{
{
&ResourceDiff{},
&ResourceDiff{},
&InstanceDiff{},
&InstanceDiff{},
true,
},
@ -146,24 +146,24 @@ func TestResourceDiffSame(t *testing.T) {
},
{
&ResourceDiff{Destroy: false},
&ResourceDiff{Destroy: true},
&InstanceDiff{Destroy: false},
&InstanceDiff{Destroy: true},
false,
},
{
&ResourceDiff{Destroy: true},
&ResourceDiff{Destroy: true},
&InstanceDiff{Destroy: true},
&InstanceDiff{Destroy: true},
true,
},
{
&ResourceDiff{
&InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{},
},
},
&ResourceDiff{
&InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{},
},
@ -172,12 +172,12 @@ func TestResourceDiffSame(t *testing.T) {
},
{
&ResourceDiff{
&InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"bar": &ResourceAttrDiff{},
},
},
&ResourceDiff{
&InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{},
},
@ -186,12 +186,12 @@ func TestResourceDiffSame(t *testing.T) {
},
{
&ResourceDiff{
&InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{RequiresNew: true},
},
},
&ResourceDiff{
&InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{RequiresNew: false},
},
@ -210,8 +210,8 @@ func TestResourceDiffSame(t *testing.T) {
func TestReadWriteDiff(t *testing.T) {
diff := &Diff{
Resources: map[string]*ResourceDiff{
"nodeA": &ResourceDiff{
Resources: map[string]*InstanceDiff{
"nodeA": &InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{
Old: "foo",

Some files were not shown because too many files have changed in this diff Show More