-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for
scheduling
, health
, load_balancer
, secrets
,…
… `security` blocks. (#594)
- Loading branch information
1 parent
f52f19b
commit d295dbf
Showing
25 changed files
with
2,671 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package elastigroup_azure_health | ||
|
||
import "github.com/spotinst/terraform-provider-spotinst/spotinst/commons" | ||
|
||
const ( | ||
Health commons.FieldName = "health" | ||
HealthCheckTypes commons.FieldName = "health_check_types" | ||
GracePeriod commons.FieldName = "grace_period" | ||
UnhealthyDuration commons.FieldName = "unhealthy_duration" | ||
AutoHealing commons.FieldName = "auto_healing" | ||
) |
174 changes: 174 additions & 0 deletions
174
spotinst/azure_v3/elastigroup_azure_health/fields_spotinst_elastigroup_azure_health.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package elastigroup_azure_health | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
azurev3 "github.com/spotinst/spotinst-sdk-go/service/elastigroup/providers/azure/v3" | ||
"github.com/spotinst/spotinst-sdk-go/spotinst" | ||
"github.com/spotinst/terraform-provider-spotinst/spotinst/commons" | ||
) | ||
|
||
func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) { | ||
|
||
fieldsMap[Health] = commons.NewGenericField( | ||
commons.ElastigroupAzureHealth, | ||
Health, | ||
&schema.Schema{ | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
string(HealthCheckTypes): { | ||
Type: schema.TypeList, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString}, | ||
Optional: true, | ||
}, | ||
string(GracePeriod): { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
}, | ||
string(UnhealthyDuration): { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Default: -1, | ||
}, | ||
string(AutoHealing): { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error { | ||
egWrapper := resourceObject.(*commons.ElastigroupAzureV3Wrapper) | ||
elastigroup := egWrapper.GetElastigroup() | ||
var result []interface{} = nil | ||
if elastigroup.Health != nil { | ||
result = flattenHealth(elastigroup.Health) | ||
} | ||
if len(result) > 0 { | ||
if err := resourceData.Set(string(Health), result); err != nil { | ||
return fmt.Errorf(string(commons.FailureFieldReadPattern), string(Health), err) | ||
} | ||
} | ||
return nil | ||
}, | ||
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error { | ||
egWrapper := resourceObject.(*commons.ElastigroupAzureV3Wrapper) | ||
elastigroup := egWrapper.GetElastigroup() | ||
|
||
if v, ok := resourceData.GetOk(string(Health)); ok { | ||
if health, err := expandHealth(v); err != nil { | ||
return err | ||
} else { | ||
elastigroup.SetHealth(health) | ||
} | ||
} | ||
return nil | ||
}, | ||
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error { | ||
egWrapper := resourceObject.(*commons.ElastigroupAzureV3Wrapper) | ||
elastigroup := egWrapper.GetElastigroup() | ||
var value *azurev3.Health = nil | ||
|
||
if v, ok := resourceData.GetOk(string(Health)); ok { | ||
if health, err := expandHealth(v); err != nil { | ||
return err | ||
} else { | ||
value = health | ||
} | ||
} | ||
elastigroup.SetHealth(value) | ||
return nil | ||
}, | ||
nil, | ||
) | ||
} | ||
|
||
func flattenHealth(health *azurev3.Health) []interface{} { | ||
var out []interface{} | ||
|
||
if health != nil { | ||
result := make(map[string]interface{}) | ||
value := spotinst.Int(-1) | ||
result[string(UnhealthyDuration)] = value | ||
if health.HealthCheckTypes != nil { | ||
result[string(HealthCheckTypes)] = spotinst.StringSlice(health.HealthCheckTypes) | ||
} | ||
|
||
if health.GracePeriod != nil { | ||
result[string(GracePeriod)] = spotinst.IntValue(health.GracePeriod) | ||
} | ||
|
||
if health.UnhealthyDuration != nil { | ||
result[string(UnhealthyDuration)] = spotinst.IntValue(health.UnhealthyDuration) | ||
} | ||
|
||
if health.AutoHealing != nil { | ||
result[string(AutoHealing)] = spotinst.BoolValue(health.AutoHealing) | ||
} | ||
|
||
if len(result) > 0 { | ||
out = append(out, result) | ||
} | ||
} | ||
return out | ||
} | ||
|
||
func expandHealth(data interface{}) (*azurev3.Health, error) { | ||
health := &azurev3.Health{} | ||
list := data.([]interface{}) | ||
if list == nil || list[0] == nil { | ||
return health, nil | ||
} | ||
m := list[0].(map[string]interface{}) | ||
|
||
if v, ok := m[string(HealthCheckTypes)]; ok { | ||
htc, err := expandHealthCheckTypes(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if htc != nil { | ||
health.SetHealthCheckTypes(htc) | ||
} | ||
} else { | ||
health.SetHealthCheckTypes(nil) | ||
} | ||
|
||
if v, ok := m[string(GracePeriod)].(int); ok && v >= 0 { | ||
health.SetGracePeriod(spotinst.Int(v)) | ||
} else { | ||
health.SetGracePeriod(nil) | ||
} | ||
|
||
if v, ok := m[string(UnhealthyDuration)].(int); ok { | ||
if v == -1 { | ||
health.SetUnhealthyDuration(nil) | ||
} else { | ||
health.SetUnhealthyDuration(spotinst.Int(v)) | ||
} | ||
} | ||
|
||
if v, ok := m[string(AutoHealing)].(bool); ok { | ||
health.SetAutoHealing(spotinst.Bool(v)) | ||
} else { | ||
health.SetAutoHealing(nil) | ||
} | ||
return health, nil | ||
} | ||
|
||
func expandHealthCheckTypes(data interface{}) ([]string, error) { | ||
list := data.([]interface{}) | ||
result := make([]string, 0, len(list)) | ||
|
||
for _, v := range list { | ||
if healthCheckType, ok := v.(string); ok && healthCheckType != "" { | ||
result = append(result, healthCheckType) | ||
} | ||
} | ||
|
||
return result, nil | ||
} |
Oops, something went wrong.