Skip to content

Commit

Permalink
[src] version 1.9.0 (spotinst#81)
Browse files Browse the repository at this point in the history
## 1.9.0 (Unreleased)

ENHANCEMENTS:
* resource/spotinst_elastigroup_azure: added `additional_ip_configs` to `network`
* resource/spotinst_elastigroup_azure: added kubernetes and Multai to `integrations`
* resource/spotinst_elastigroup_azure: added `scaling policies`

BUG FIXES:
* changed the order that credentials are set. See notes.
* resource/spotinst_elastigroup_azure: `dimensions` changed to properly set `name` and `value` parameters
  • Loading branch information
alexindeed authored and kmcgrath committed Mar 18, 2019
1 parent 66cd8b0 commit 2181165
Show file tree
Hide file tree
Showing 46 changed files with 2,039 additions and 161 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
## 1.8.1 (Unreleased)
## 1.9.0 (Unreleased)

ENHANCEMENTS:
* resource/spotinst_elastigroup_azure: added `additional_ip_configs` to `network`
* resource/spotinst_elastigroup_azure: added kubernetes and Multai to `integrations`
* resource/spotinst_elastigroup_azure: added `scaling policies`

BUG FIXES:
* changed the order that credentials are set. See notes.
* resource/spotinst_elastigroup_azure: `dimensions` changed to properly set `name` and `value` parameters
* resource/spotinst_elastigroup_gcp: `dimensions` changed to properly set `name` and `value` parameters
* resource/spotinst_elastigroup_aws: rolling with `wait_for_roll_percentage` no longer times out after 5 minutes
* resource/spotinst_elastigroup_aws: removed duplicated `wait_for_roll_percentage` and `wait_for_roll_timeout`
* resource/spotinst_mrscaler_aws: `visible_to_all_users` changed to deprecated. Values will not be sent in API calls.

NOTES:
* credentials are now given the following precedence: defined in the template, defined using environment variables, defined in ~/.spotinst/credentials
* spotinst_mrscaler_aws_test: added a delay due to counter AWS rate limiting

## 1.8.0 (February 28, 2019)

Expand Down
5 changes: 3 additions & 2 deletions spotinst/commons/common_elastigroup_azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ func (res *ElastigroupAzureTerraformResource) OnUpdate(
func NewElastigroupAzureWrapper() *ElastigroupAzureWrapper {
return &ElastigroupAzureWrapper{
elastigroup: &azure.Group{
Scaling: &azure.Scaling{},
Scheduling: &azure.Scheduling{},
Scaling: &azure.Scaling{},
Scheduling: &azure.Scheduling{},
Integration: &azure.Integration{},
Compute: &azure.Compute{
LaunchSpecification: &azure.LaunchSpecification{
LoadBalancersConfig: &azure.LoadBalancersConfig{},
Expand Down
2 changes: 2 additions & 0 deletions spotinst/commons/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ const (
ElastigroupAzureLoadBalancers ResourceAffinity = "Elastigroup_Azure_Load_Balancers"
ElastigroupAzureVMSizes ResourceAffinity = "Elastigroup_Azure_VM_Sizes"
ElastigroupAzureImage ResourceAffinity = "Elastigroup_Azure_Image"
ElastigroupAzureIntegrations ResourceAffinity = "Elastigroup_Azure_Integrations"
ElastigroupAzureLaunchConfiguration ResourceAffinity = "Elastigroup_Azure_Launch_Configuration"
ElastigroupAzureHealthCheck ResourceAffinity = "Elastigroup_Azure_Health_Check"
ElastigroupAzureScalingPolicies ResourceAffinity = "Elastigroup_Azure_Scaling_Policies"
ElastigroupAzureScheduledTask ResourceAffinity = "Elastigroup_Azure_Scheduled_Task"

MRScalerAWS ResourceAffinity = "MRScaler_AWS"
Expand Down
17 changes: 9 additions & 8 deletions spotinst/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ func (c *Config) Client() (*Client, error) {
config.WithLogger(newStdLogger("DEBUG"))
config.WithUserAgent("HashiCorp-Terraform/" + terraform.VersionString() + ",spotinst-provider/v2-" + version.GetShortVersion())

// Set user credentials.
providers := []credentials.Provider{
new(credentials.EnvProvider),
new(credentials.FileProvider),
}

var static *credentials.StaticProvider
if c.Token != "" || c.Account != "" {
static = &credentials.StaticProvider{
Expand All @@ -64,9 +58,16 @@ func (c *Config) Client() (*Client, error) {
Account: c.Account,
},
}
// Static provider should be placed between Env and File providers.
providers = append(providers[:1], append([]credentials.Provider{static}, providers[1:]...)...)
}

providers := []credentials.Provider{}

if static != nil {
providers = append(providers, static)
}

providers = append(providers, new(credentials.EnvProvider), new(credentials.FileProvider))

creds := credentials.NewChainCredentials(providers...)

if _, err := creds.Get(); err != nil {
Expand Down
10 changes: 7 additions & 3 deletions spotinst/elastigroup_aws/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ const (
AutoApplyTags commons.FieldName = "auto_apply_tags"
ShouldRoll commons.FieldName = "should_roll"

RollConfig commons.FieldName = "roll_config"
BatchSizePercentage commons.FieldName = "batch_size_percentage"
GracePeriod commons.FieldName = "grace_period"
RollConfig commons.FieldName = "roll_config"
BatchSizePercentage commons.FieldName = "batch_size_percentage"
GracePeriod commons.FieldName = "grace_period"
Strategy commons.FieldName = "strategy"
Action commons.FieldName = "action"
ShouldDrainInstances commons.FieldName = "should_drain_instances"
BatchMinHealthyPercentage commons.FieldName = "batch_min_healthy_percentage"

WaitForCapacity commons.FieldName = "wait_for_capacity"
WaitForCapacityTimeout commons.FieldName = "wait_for_capacity_timeout"
Expand Down
25 changes: 25 additions & 0 deletions spotinst/elastigroup_aws/fields_spotinst_elastigroup_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,31 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
Type: schema.TypeInt,
Optional: true,
},

string(Strategy): {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
string(Action): {
Type: schema.TypeString,
Required: true,
},

string(ShouldDrainInstances): {
Type: schema.TypeBool,
Optional: true,
},

string(BatchMinHealthyPercentage): {
Type: schema.TypeInt,
Optional: true,
Default: 50,
},
},
},
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func baseScalingPolicySchema() *schema.Schema {

string(DimensionValue): {
Type: schema.TypeString,
Required: true,
Optional: true,
},
},
},
Expand Down Expand Up @@ -299,6 +299,7 @@ func upDownScalingPolicySchema() *schema.Schema {
s[string(IsEnabled)] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: true,
}

return o
Expand Down
15 changes: 15 additions & 0 deletions spotinst/elastigroup_azure_integrations/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package elastigroup_azure_integrations

import "github.com/terraform-providers/terraform-provider-spotinst/spotinst/commons"

const (
// - KUBERNETES ----------------------
IntegrationKubernetes commons.FieldName = "integration_kubernetes"
ClusterIdentifier commons.FieldName = "cluster_identifier"
// -----------------------------------

// - MULTAI-RUNTIME ------------------
IntegrationMultaiRuntime commons.FieldName = "integration_multai_runtime"
DeploymentId commons.FieldName = "deployment_id"
// -----------------------------------
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package elastigroup_azure_integrations

import "github.com/terraform-providers/terraform-provider-spotinst/spotinst/commons"

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Setup
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
SetupKubernetes(fieldsMap)
SetupMultaiRuntime(fieldsMap)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package elastigroup_azure_integrations

import (
"github.com/hashicorp/terraform/helper/schema"
"github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/terraform-providers/terraform-provider-spotinst/spotinst/commons"
)

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Setup
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
func SetupKubernetes(fieldsMap map[commons.FieldName]*commons.GenericField) {

fieldsMap[IntegrationKubernetes] = commons.NewGenericField(
commons.ElastigroupAzureIntegrations,
IntegrationKubernetes,
&schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{

string(ClusterIdentifier): {
Type: schema.TypeString,
Required: true,
},
},
},
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
egWrapper := resourceObject.(*commons.ElastigroupAzureWrapper)
elastigroup := egWrapper.GetElastigroup()
if v, ok := resourceData.GetOk(string(IntegrationKubernetes)); ok {
if integration, err := expandAzureGroupKubernetesIntegration(v); err != nil {
return err
} else {
elastigroup.Integration.SetKubernetes(integration)
}
}
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
egWrapper := resourceObject.(*commons.ElastigroupAzureWrapper)
elastigroup := egWrapper.GetElastigroup()
var value *azure.KubernetesIntegration = nil
if v, ok := resourceData.GetOk(string(IntegrationKubernetes)); ok {
if integration, err := expandAzureGroupKubernetesIntegration(v); err != nil {
return err
} else {
value = integration
}
}
elastigroup.Integration.SetKubernetes(value)
return nil
},
nil,
)
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Utils
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
func expandAzureGroupKubernetesIntegration(data interface{}) (*azure.KubernetesIntegration, error) {
integration := &azure.KubernetesIntegration{}
list := data.([]interface{})
if list == nil || list[0] == nil {
return integration, nil
}
m := list[0].(map[string]interface{})

if v, ok := m[string(ClusterIdentifier)].(string); ok && v != "" {
integration.SetClusterIdentifier(spotinst.String(v))
}

return integration, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package elastigroup_azure_integrations

import (
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure"
"github.com/spotinst/spotinst-sdk-go/spotinst"
"github.com/terraform-providers/terraform-provider-spotinst/spotinst/commons"
)

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Setup
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
func SetupMultaiRuntime(fieldsMap map[commons.FieldName]*commons.GenericField) {

fieldsMap[IntegrationMultaiRuntime] = commons.NewGenericField(
commons.ElastigroupAzureIntegrations,
IntegrationMultaiRuntime,
&schema.Schema{
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
string(DeploymentId): {
Type: schema.TypeString,
Required: true,
},
},
},
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
egWrapper := resourceObject.(*commons.ElastigroupAzureWrapper)
elastigroup := egWrapper.GetElastigroup()
var value []interface{} = nil
if elastigroup.Integration != nil && elastigroup.Integration.Multai != nil {
value = flattenAureGroupMultaiIntegration(elastigroup.Integration.Multai)
}
if value != nil {
if err := resourceData.Set(string(IntegrationMultaiRuntime), value); err != nil {
return fmt.Errorf(string(commons.FailureFieldReadPattern), string(IntegrationMultaiRuntime), err)
}
} else {
if err := resourceData.Set(string(IntegrationMultaiRuntime), []*azure.MultaiIntegration{}); err != nil {
return fmt.Errorf(string(commons.FailureFieldReadPattern), string(IntegrationMultaiRuntime), err)
}
}
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
egWrapper := resourceObject.(*commons.ElastigroupAzureWrapper)
elastigroup := egWrapper.GetElastigroup()
if v, ok := resourceData.GetOk(string(IntegrationMultaiRuntime)); ok {
if integration, err := expandAzureGroupMultaiIntegration(v); err != nil {
return err
} else {
elastigroup.Integration.SetMultai(integration)
}
}
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
egWrapper := resourceObject.(*commons.ElastigroupAzureWrapper)
elastigroup := egWrapper.GetElastigroup()
var value *azure.MultaiIntegration = nil
if v, ok := resourceData.GetOk(string(IntegrationMultaiRuntime)); ok {
if integration, err := expandAzureGroupMultaiIntegration(v); err != nil {
return err
} else {
value = integration
}
}
elastigroup.Integration.SetMultai(value)
return nil
},
nil,
)
}

//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Utils
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
func expandAzureGroupMultaiIntegration(data interface{}) (*azure.MultaiIntegration, error) {
integration := &azure.MultaiIntegration{}
list := data.([]interface{})
if list != nil && list[0] != nil {
m := list[0].(map[string]interface{})

if v, ok := m[string(DeploymentId)].(string); ok && v != "" {
integration.SetDeploymentId(spotinst.String(v))
}
}
return integration, nil
}

func flattenAureGroupMultaiIntegration(integration *azure.MultaiIntegration) []interface{} {
result := make(map[string]interface{})
result[string(DeploymentId)] = spotinst.StringValue(integration.DeploymentID)
return []interface{}{result}
}
3 changes: 2 additions & 1 deletion spotinst/elastigroup_azure_launch_configuration/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ const (
)

const (
UserData commons.FieldName = "user_data"
UserData commons.FieldName = "user_data"
ShutdownScript commons.FieldName = "shutdown_script"
)
Loading

0 comments on commit 2181165

Please sign in to comment.