Skip to content

Commit

Permalink
Merge pull request hashicorp#1210 from hashicorp/b-add-guards-aws-ins…
Browse files Browse the repository at this point in the history
…tance

provider/aws: Add additional guards for Tenancy, SourceDestCheck
  • Loading branch information
catsby committed Mar 19, 2015
2 parents a063ebe + c1ccbb5 commit 21fa3d1
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 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 @@ -570,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

0 comments on commit 21fa3d1

Please sign in to comment.