Skip to content

Commit

Permalink
Merge pull request hashicorp#17 from pmoust/sync/upstream
Browse files Browse the repository at this point in the history
Sync/upstream
  • Loading branch information
pmoust committed Mar 20, 2015
2 parents 6fe316b + 7354c00 commit 9ffb681
Show file tree
Hide file tree
Showing 15 changed files with 1,391 additions and 35 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FEATURES:
* **New provider: `dme` (DNSMadeEasy)** [GH-855]
* **New command: `taint`** - Manually mark a resource as tainted, causing
a destroy and recreate on the next plan/apply.
* **New resource: `aws_vpn_gateway`** [GH-1137]
* **Self-variables** can be used to reference the current resource's
attributes within a provisioner. Ex. `${self.private_ip_address}` [GH-1033]
* **Continous state** saving during `terraform apply`. The state file is
Expand All @@ -33,6 +34,7 @@ IMPROVEMENTS:
* **New config function: `split`** - Split a value based on a delimiter.
This is useful for faking lists as parameters to modules.
* **New resource: `digitalocean_ssh_key`** [GH-1074]
* **New resource: `aws_elastic_network_interfaces`** [GH-1149]
* core: The serial of the state is only updated if there is an actual
change. This will lower the amount of state changing on things
like refresh.
Expand Down
2 changes: 2 additions & 0 deletions builtin/providers/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func Provider() terraform.ResourceProvider {
"aws_launch_configuration": resourceAwsLaunchConfiguration(),
"aws_main_route_table_association": resourceAwsMainRouteTableAssociation(),
"aws_network_acl": resourceAwsNetworkAcl(),
"aws_network_interface": resourceAwsNetworkInterface(),
"aws_route53_record": resourceAwsRoute53Record(),
"aws_route53_zone": resourceAwsRoute53Zone(),
"aws_route_table": resourceAwsRouteTable(),
Expand All @@ -67,6 +68,7 @@ func Provider() terraform.ResourceProvider {
"aws_subnet": resourceAwsSubnet(),
"aws_vpc": resourceAwsVpc(),
"aws_vpc_peering_connection": resourceAwsVpcPeeringConnection(),
"aws_vpn_gateway": resourceAwsVpnGateway(),
},

ConfigureFunc: providerConfigure,
Expand Down
36 changes: 23 additions & 13 deletions builtin/providers/aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,21 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
userData = base64.StdEncoding.EncodeToString([]byte(v.(string)))
}

// check for non-default Subnet, and cast it to a String
var hasSubnet bool
subnet, hasSubnet := d.GetOk("subnet_id")
subnetID := subnet.(string)

placement := &ec2.Placement{
AvailabilityZone: aws.String(d.Get("availability_zone").(string)),
}
if v := d.Get("tenancy").(string); v != "" {
placement.Tenancy = aws.String(v)

if hasSubnet {
// Tenancy is only valid inside a VPC
// See http://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_Placement.html
if v := d.Get("tenancy").(string); v != "" {
placement.Tenancy = aws.String(v)
}
}

iam := &ec2.IAMInstanceProfileSpecification{
Expand All @@ -347,11 +357,6 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
associatePublicIPAddress = v.(bool)
}

// check for non-default Subnet, and cast it to a String
var hasSubnet bool
subnet, hasSubnet := d.GetOk("subnet_id")
subnetID := subnet.(string)

var groups []string
if v := d.Get("security_groups"); v != nil {
// Security group names.
Expand Down Expand Up @@ -448,9 +453,6 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
VirtualName: aws.String(bd["virtual_name"].(string)),
})
}
// if err := d.Set("ephemeral_block_device", vL); err != nil {
// return err
// }
}

if v, ok := d.GetOk("root_block_device"); ok {
Expand Down Expand Up @@ -573,21 +575,25 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

d.Set("availability_zone", instance.Placement.AvailabilityZone)
if instance.Placement != nil {
d.Set("availability_zone", instance.Placement.AvailabilityZone)
}
if instance.Placement.Tenancy != nil {
d.Set("tenancy", instance.Placement.Tenancy)
}

d.Set("key_name", instance.KeyName)
d.Set("public_dns", instance.PublicDNSName)
d.Set("public_ip", instance.PublicIPAddress)
d.Set("private_dns", instance.PrivateDNSName)
d.Set("private_ip", instance.PrivateIPAddress)
d.Set("subnet_id", instance.SubnetID)
if len(instance.NetworkInterfaces) > 0 {
d.Set("subnet_id", instance.NetworkInterfaces[0].SubnetID)
} else {
d.Set("subnet_id", instance.SubnetID)
}
d.Set("ebs_optimized", instance.EBSOptimized)
d.Set("tags", tagsToMap(instance.Tags))
d.Set("tenancy", instance.Placement.Tenancy)

// Determine whether we're referring to security groups with
// IDs or names. We use a heuristic to figure this out. By default,
Expand Down Expand Up @@ -747,6 +753,10 @@ func readBlockDevicesFromInstance(instance *ec2.Instance, ec2conn *ec2.EC2) (map
}
}

if len(instanceBlockDevices) == 0 {
return nil, nil
}

volIDs := make([]string, 0, len(instanceBlockDevices))
for volID := range instanceBlockDevices {
volIDs = append(volIDs, volID)
Expand Down
67 changes: 55 additions & 12 deletions builtin/providers/aws/resource_aws_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

func TestAccAWSInstance_normal(t *testing.T) {
var v ec2.Instance
var vol *ec2.Volume

testCheck := func(*terraform.State) error {
if *v.Placement.AvailabilityZone != "us-west-2a" {
Expand All @@ -35,6 +36,21 @@ func TestAccAWSInstance_normal(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
// Create a volume to cover #1249
resource.TestStep{
// Need a resource in this config so the provisioner will be available
Config: testAccInstanceConfig_pre,
Check: func(*terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
var err error
vol, err = conn.CreateVolume(&ec2.CreateVolumeRequest{
AvailabilityZone: aws.String("us-west-2a"),
Size: aws.Integer(5),
})
return err
},
},

resource.TestStep{
Config: testAccInstanceConfig,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -45,6 +61,8 @@ func TestAccAWSInstance_normal(t *testing.T) {
"aws_instance.foo",
"user_data",
"3dc39dda39be1205215e776bad998da361a5955d"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.#", "0"),
),
},

Expand All @@ -61,8 +79,19 @@ func TestAccAWSInstance_normal(t *testing.T) {
"aws_instance.foo",
"user_data",
"3dc39dda39be1205215e776bad998da361a5955d"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.#", "0"),
),
},

// Clean up volume created above
resource.TestStep{
Config: testAccInstanceConfig,
Check: func(*terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
return conn.DeleteVolume(&ec2.DeleteVolumeRequest{VolumeID: vol.VolumeID})
},
},
},
})
}
Expand Down Expand Up @@ -111,33 +140,33 @@ func TestAccAWSInstance_blockDevices(t *testing.T) {
resource.TestCheckResourceAttr(
"aws_instance.foo", "root_block_device.#", "1"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "root_block_device.3018388612.device_name", "/dev/sda1"),
"aws_instance.foo", "root_block_device.1246122048.device_name", "/dev/sda1"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "root_block_device.3018388612.volume_size", "11"),
"aws_instance.foo", "root_block_device.1246122048.volume_size", "11"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "root_block_device.3018388612.volume_type", "gp2"),
"aws_instance.foo", "root_block_device.1246122048.volume_type", "gp2"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.#", "2"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.418220885.device_name", "/dev/sdb"),
"aws_instance.foo", "ebs_block_device.2225977507.device_name", "/dev/sdb"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.418220885.volume_size", "9"),
"aws_instance.foo", "ebs_block_device.2225977507.volume_size", "9"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.418220885.volume_type", "standard"),
"aws_instance.foo", "ebs_block_device.2225977507.volume_type", "standard"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.1877654467.device_name", "/dev/sdc"),
"aws_instance.foo", "ebs_block_device.1977224956.device_name", "/dev/sdc"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.1877654467.volume_size", "10"),
"aws_instance.foo", "ebs_block_device.1977224956.volume_size", "10"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.1877654467.volume_type", "io1"),
"aws_instance.foo", "ebs_block_device.1977224956.volume_type", "io1"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ebs_block_device.1877654467.iops", "100"),
"aws_instance.foo", "ebs_block_device.1977224956.iops", "100"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ephemeral_block_device.#", "1"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ephemeral_block_device.2087552357.device_name", "/dev/sde"),
"aws_instance.foo", "ephemeral_block_device.1692014856.device_name", "/dev/sde"),
resource.TestCheckResourceAttr(
"aws_instance.foo", "ephemeral_block_device.2087552357.virtual_name", "ephemeral0"),
"aws_instance.foo", "ephemeral_block_device.1692014856.virtual_name", "ephemeral0"),
testCheck(),
),
},
Expand Down Expand Up @@ -393,6 +422,20 @@ func TestInstanceTenancySchema(t *testing.T) {
}
}

const testAccInstanceConfig_pre = `
resource "aws_security_group" "tf_test_foo" {
name = "tf_test_foo"
description = "foo"
ingress {
protocol = "icmp"
from_port = -1
to_port = -1
cidr_blocks = ["0.0.0.0/0"]
}
}
`

const testAccInstanceConfig = `
resource "aws_security_group" "tf_test_foo" {
name = "tf_test_foo"
Expand Down
Loading

0 comments on commit 9ffb681

Please sign in to comment.