Skip to content

Commit

Permalink
fix(elastigroup/aws): minor bug fixes (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lironrad authored Jan 5, 2022
1 parent 7c954ea commit cc6b354
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Unreleased

NOTES:
* documentation: resource/spotinst_ocean_aws: Add usage example for `utilize_commitments`
* documentation: resource/spotinst_ocean_ecs: Add usage example for `utilize_commitments`

BUG FIXES:
* resource/spotinst_elastigroup_aws: resolved errors with `ebs_block_device`

## 1.64.1 (December 14, 2021)

BUG FIXES:
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/ocean_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ resource "spotinst_ocean_aws" "example" {
utilize_reserved_instances = false
grace_period = 600
spot_percentage = 100
utilize_commitments = false
// endregion
tags {
Expand Down Expand Up @@ -138,6 +139,7 @@ The following arguments are supported:
* `draining_timeout` - (Optional) The time in seconds, the instance is allowed to run while detached from the ELB. This is to allow the instance time to be drained from incoming TCP connections before terminating it, during a scale down operation.
* `grace_period` - (Optional, Default: 600) The amount of time, in seconds, after the instance has launched to start checking its health.
* `spot_percentage` - (Optional; Required if not using `ondemand_count`) The percentage of Spot instances that would spin up from the `desired_capacity` number.
* `utilize_commitments` - (Optional, Default false) If savings plans exist, Ocean will utilize them before launching Spot instances.
* `instance_metadata_options` - (Optional) Ocean instance metadata options object for IMDSv2.
* `http_tokens` - (Required) Determines if a signed token is required or not. Valid values: `optional` or `required`.
* `http_put_response_hop_limit` - (Optional) An integer from 1 through 64. The desired HTTP PUT response hop limit for instance metadata requests. The larger the number, the further the instance metadata requests can travel.
Expand Down
4 changes: 3 additions & 1 deletion docs/resources/ocean_ecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ resource "spotinst_ocean_ecs" "example" {
monitoring = true
ebs_optimized = true
spot_percentage = 100
spot_percentage = 100
utilize_commitments = false
instance_metadata_options {
http_tokens = "required"
Expand Down Expand Up @@ -106,6 +107,7 @@ The following arguments are supported:
* `monitoring` - (Optional) Enable detailed monitoring for cluster. Flag will enable Cloud Watch detailed monitoring (one minute increments). Note: there are additional hourly costs for this service based on the region used.
* `ebs_optimized` - (Optional) Enable EBS optimized for cluster. Flag will enable optimized capacity for high bandwidth connectivity to the EB service for non EBS optimized instance types. For instances that are EBS optimized this flag will be ignored.
* `spot_percentage` - (Optional) The percentage of Spot instances that would spin up from the `desired_capacity` number.
* `utilize_commitments` - (Optional, Default false) If savings plans exist, Ocean will utilize them before launching Spot instances.
* `instance_metadata_options` - (Optional) Ocean instance metadata options object for IMDSv2.
* `http_tokens` - (Required) Determines if a signed token is required or not. Valid values: `optional` or `required`.
* `http_put_response_hop_limit` - (Optional) An integer from 1 through 64. The desired HTTP PUT response hop limit for instance metadata requests. The larger the number, the further the instance metadata requests can travel.
Expand Down
44 changes: 15 additions & 29 deletions spotinst/resource_spotinst_elastigroup_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (
"github.com/spotinst/terraform-provider-spotinst/spotinst/elastigroup_aws_strategy"
)

var IsEBSVolumeTypeCapitalSlice []bool

func resourceSpotinstElastigroupAWS() *schema.Resource {
setupElastigroupResource()

Expand Down Expand Up @@ -763,35 +761,23 @@ func isUpper(s string) bool {
}

func updateCapitalSlice(resourceData *schema.ResourceData, groupResponse *aws.Group) {
v := resourceData.Get(string(elastigroup_aws_block_devices.EbsBlockDevice))
list := v.(*schema.Set).List()
for _, item := range list {
m := item.(map[string]interface{})

if v, ok := m[string(elastigroup_aws_block_devices.VolumeType)].(string); ok && v != "" {
if isUpper(v) == false {
IsEBSVolumeTypeCapitalSlice = append(IsEBSVolumeTypeCapitalSlice, false)
} else {
IsEBSVolumeTypeCapitalSlice = append(IsEBSVolumeTypeCapitalSlice, true)
}

}
}

for index, isEBSVolumeTypeCapital := range IsEBSVolumeTypeCapitalSlice {

if isEBSVolumeTypeCapital == false {

if groupResponse.Compute != nil && groupResponse.Compute.LaunchSpecification != nil && groupResponse.Compute.LaunchSpecification.BlockDeviceMappings != nil {
blockDeviceMappings := groupResponse.Compute.LaunchSpecification.BlockDeviceMappings

if blockDeviceMappings[index] != nil {
vol := blockDeviceMappings[index].EBS.VolumeType
*vol = strings.ToLower(*vol)
blockDeviceMappings[index].EBS.SetVolumeType(vol)
if groupResponse.Compute != nil && groupResponse.Compute.LaunchSpecification != nil && groupResponse.Compute.LaunchSpecification.BlockDeviceMappings != nil {
blockDeviceMappingsAPIResponse := groupResponse.Compute.LaunchSpecification.BlockDeviceMappings
ebsBlockDevicesResourceData := resourceData.Get(string(elastigroup_aws_block_devices.EbsBlockDevice))
ebsBlockDevicesInput := ebsBlockDevicesResourceData.(*schema.Set).List()

for index, blockDeviceInput := range ebsBlockDevicesInput {
blockDevice := blockDeviceInput.(map[string]interface{})

if volumeTypeInput, ok := blockDevice[string(elastigroup_aws_block_devices.VolumeType)].(string); ok && volumeTypeInput != "" {
if isUpper(volumeTypeInput) == false {
volumeTypeAPIResponse := blockDeviceMappingsAPIResponse[index].EBS.VolumeType
if volumeTypeAPIResponse != nil {
*volumeTypeAPIResponse = strings.ToLower(*volumeTypeAPIResponse)
blockDeviceMappingsAPIResponse[index].EBS.SetVolumeType(volumeTypeAPIResponse)
}
}
}

}
}
}

0 comments on commit cc6b354

Please sign in to comment.