Skip to content

Commit

Permalink
Added locations and location_types to the output. hashicorp#15272
Browse files Browse the repository at this point in the history
  • Loading branch information
mjulianotq committed Feb 24, 2021
1 parent f7886da commit 1b1a67a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions aws/data_source_aws_ec2_instance_type_offerings.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ func dataSourceAwsEc2InstanceTypeOfferings() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"locations": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"location_type": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -29,6 +34,11 @@ func dataSourceAwsEc2InstanceTypeOfferings() *schema.Resource {
ec2.LocationTypeRegion,
}, false),
},
"location_types": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
Expand All @@ -47,6 +57,8 @@ func dataSourceAwsEc2InstanceTypeOfferingsRead(d *schema.ResourceData, meta inte
}

var instanceTypes []string
var locations []string
var locationTypes []string

for {
output, err := conn.DescribeInstanceTypeOfferings(input)
Expand All @@ -65,6 +77,8 @@ func dataSourceAwsEc2InstanceTypeOfferingsRead(d *schema.ResourceData, meta inte
}

instanceTypes = append(instanceTypes, aws.StringValue(instanceTypeOffering.InstanceType))
locations = append(locations, aws.StringValue(instanceTypeOffering.Location))
locationTypes = append(locationTypes, aws.StringValue(instanceTypeOffering.LocationType))
}

if aws.StringValue(output.NextToken) == "" {
Expand All @@ -78,6 +92,14 @@ func dataSourceAwsEc2InstanceTypeOfferingsRead(d *schema.ResourceData, meta inte
return fmt.Errorf("error setting instance_types: %w", err)
}

if err := d.Set("locations", locations); err != nil {
return fmt.Errorf("error setting locations: %w", err)
}

if err := d.Set("location_types", locationTypes); err != nil {
return fmt.Errorf("error setting location_types: %w", err)
}

d.SetId(meta.(*AWSClient).region)

return nil
Expand Down
8 changes: 8 additions & 0 deletions aws/data_source_aws_ec2_instance_type_offerings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ func testAccCheckEc2InstanceTypeOfferingsInstanceTypes(dataSourceName string) re
return fmt.Errorf("expected at least one instance_types result, got none")
}

if v := rs.Primary.Attributes["locations.#"]; v == "0" {
return fmt.Errorf("expected at least one locations result, got none")
}

if v := rs.Primary.Attributes["location_types.#"]; v == "0" {
return fmt.Errorf("expected at least one location_types result, got none")
}

return nil
}
}
Expand Down

0 comments on commit 1b1a67a

Please sign in to comment.