Merge pull request #1210 from hashicorp/b-add-guards-aws-instance

provider/aws: Add additional guards for Tenancy, SourceDestCheck
This commit is contained in:
Clint 2015-03-19 11:20:14 -05:00
commit 21fa3d1fc9
1 changed files with 19 additions and 10 deletions

View File

@ -319,11 +319,21 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
userData = base64.StdEncoding.EncodeToString([]byte(v.(string))) 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{ placement := &ec2.Placement{
AvailabilityZone: aws.String(d.Get("availability_zone").(string)), 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{ iam := &ec2.IAMInstanceProfileSpecification{
@ -347,11 +357,6 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error {
associatePublicIPAddress = v.(bool) 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 var groups []string
if v := d.Get("security_groups"); v != nil { if v := d.Get("security_groups"); v != nil {
// Security group names. // Security group names.
@ -570,13 +575,18 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
return nil 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("key_name", instance.KeyName)
d.Set("public_dns", instance.PublicDNSName) d.Set("public_dns", instance.PublicDNSName)
d.Set("public_ip", instance.PublicIPAddress) d.Set("public_ip", instance.PublicIPAddress)
d.Set("private_dns", instance.PrivateDNSName) d.Set("private_dns", instance.PrivateDNSName)
d.Set("private_ip", instance.PrivateIPAddress) d.Set("private_ip", instance.PrivateIPAddress)
d.Set("subnet_id", instance.SubnetID)
if len(instance.NetworkInterfaces) > 0 { if len(instance.NetworkInterfaces) > 0 {
d.Set("subnet_id", instance.NetworkInterfaces[0].SubnetID) d.Set("subnet_id", instance.NetworkInterfaces[0].SubnetID)
} else { } else {
@ -584,7 +594,6 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error {
} }
d.Set("ebs_optimized", instance.EBSOptimized) d.Set("ebs_optimized", instance.EBSOptimized)
d.Set("tags", tagsToMap(instance.Tags)) d.Set("tags", tagsToMap(instance.Tags))
d.Set("tenancy", instance.Placement.Tenancy)
// Determine whether we're referring to security groups with // Determine whether we're referring to security groups with
// IDs or names. We use a heuristic to figure this out. By default, // IDs or names. We use a heuristic to figure this out. By default,