Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for create update and delete #482

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## Unreleased

## 1.151.0 (December, 02 2023)
ENHANCEMENTS:
* resource/spotinst_stateful_node_azure: Added `proximity_placement_groups` object support.
*
## 1.150.1 (November, 21 2023)
BUG FIXES:
* resource/spotinst_ocean_ecs_launch_spec: Fixed deletion of `images` object.
Expand Down
24 changes: 19 additions & 5 deletions docs/resources/stateful_node_azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ resource "spotinst_stateful_node_azure" "test_stateful_node_azure" {
private_ip_address_version = "IPv4"
}
public_ips {
resource_group_name = "resourceGroup"
name = "test"
network_resource_group_name = "resourceGroup"
name = "test"
}
application_security_groups {
resource_group_name = "AsgResourceGroup"
name = "AsgName"
network_resource_group_name = "AsgResourceGroup"
name = "AsgName"
}
}
}
Expand Down Expand Up @@ -239,7 +239,13 @@ resource "spotinst_stateful_node_azure" "test_stateful_node_azure" {
type = "vmReady"
timeout = 40
}
}
// -------------------------------------------------------------------

// --- PROMXIMITY PLACEMENTS GROUPS -----------------------------------
proximity_placement_groups {
name = "TestPPG"
resource_group_name = "TestResourceGroup"
}
// -------------------------------------------------------------------

// ---DELETE----------------------------------------------------------
Expand All @@ -254,6 +260,7 @@ resource "spotinst_stateful_node_azure" "test_stateful_node_azure" {
public_ip_should_deallocate = true
public_ip_ttl_in_hours = 0
}
}
// -------------------------------------------------------------------

```
Expand Down Expand Up @@ -373,6 +380,13 @@ The following arguments are supported:
* `name` - (Required) name of the managed identity.
* `resource_group_name` - (Required) The Resource Group that the user-assigned managed identity resides in.

<a id="proximity_placement_groups"></a>
## Proximity Placement Groups

* `proximity_placement_groups` - (Optional) Defines the proximity placement group in which the VM will be launched.
* `name` - (Required) name of the proximity placement group.
* `resource_group_name` - (Required) The Resource Group name of the proximity placement group.

<a id="network"></a>
## Network

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ require (
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-plugin-docs v0.5.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.5.0
github.com/spotinst/spotinst-sdk-go v1.185.0
github.com/spotinst/spotinst-sdk-go v1.186.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spotinst/spotinst-sdk-go v1.185.0 h1:9QVIEySbCCPPVZuOtFvEyw6xkgrENM26JTfmdIFoP/E=
github.com/spotinst/spotinst-sdk-go v1.185.0/go.mod h1:DP/y998hi551EWIR6t4mbohMMMKjp1IE0K+eJztaFGc=
github.com/spotinst/spotinst-sdk-go v1.186.0 h1:/zV19Q2gn5HElpTH1bOxPDQKhs5HXh7dWRsB5pf0+OY=
github.com/spotinst/spotinst-sdk-go v1.186.0/go.mod h1:DP/y998hi551EWIR6t4mbohMMMKjp1IE0K+eJztaFGc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
Expand Down
7 changes: 7 additions & 0 deletions spotinst/azure_v3/stateful_node_azure_launch_spec/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ const (
ResourceGroupName commons.FieldName = "resource_group_name"
)

// Proximity Placement Groups
const (
ProximityPlacementGroups commons.FieldName = "proximity_placement_groups"
PPGName commons.FieldName = "name"
PPGResourceGroupName commons.FieldName = "resource_group_name"
)

// OS disk
const (
OSDisk commons.FieldName = "os_disk"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,70 @@ func Setup(fieldsMap map[commons.FieldName]*commons.GenericField) {
nil,
)

fieldsMap[ProximityPlacementGroups] = commons.NewGenericField(
commons.StatefulNodeAzureLaunchSpecification,
ProximityPlacementGroups,
&schema.Schema{
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
string(PPGName): {
Type: schema.TypeString,
Required: true,
},
string(PPGResourceGroupName): {
Type: schema.TypeString,
Required: true,
},
},
},
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
stWrapper := resourceObject.(*commons.StatefulNodeAzureV3Wrapper)
st := stWrapper.GetStatefulNode()
var value []interface{}
if st.Compute != nil && st.Compute.LaunchSpecification != nil && st.Compute.LaunchSpecification.ProximityPlacementGroups != nil {
value = flattenProximityPlacementGroups(st.Compute.LaunchSpecification.ProximityPlacementGroups)
}
if err := resourceData.Set(string(ProximityPlacementGroups), value); err != nil {
return fmt.Errorf(commons.FailureFieldReadPattern, string(ProximityPlacementGroups), err)
}
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
stWrapper := resourceObject.(*commons.StatefulNodeAzureV3Wrapper)
st := stWrapper.GetStatefulNode()
if v, ok := resourceData.GetOk(string(ProximityPlacementGroups)); ok {
if ppgs, err := expandProximityPlacementGroups(v); err != nil {
return err
} else {
st.Compute.LaunchSpecification.SetProximityPlacementGroups(ppgs)
}
}
return nil
},
func(resourceObject interface{}, resourceData *schema.ResourceData, meta interface{}) error {
stWrapper := resourceObject.(*commons.StatefulNodeAzureV3Wrapper)
st := stWrapper.GetStatefulNode()
var value []*azure.ProximityPlacementGroups = nil

if v, ok := resourceData.GetOk(string(ProximityPlacementGroups)); ok {
if ppgs, err := expandProximityPlacementGroups(v); err != nil {
return err
} else {
value = ppgs
}
st.Compute.LaunchSpecification.SetProximityPlacementGroups(value)
} else {
st.Compute.LaunchSpecification.SetProximityPlacementGroups(nil)
}
return nil
},
nil,
)

fieldsMap[OSDisk] = commons.NewGenericField(
commons.StatefulNodeAzureLaunchSpecification,
OSDisk,
Expand Down Expand Up @@ -664,6 +728,39 @@ func flattenManagedServiceIdentities(msis []*azure.ManagedServiceIdentity) []int
return result
}

func expandProximityPlacementGroups(data interface{}) ([]*azure.ProximityPlacementGroups, error) {
list := data.(*schema.Set).List()
ppgs := make([]*azure.ProximityPlacementGroups, 0, len(list))
for _, v := range list {
attr, ok := v.(map[string]interface{})
if !ok {
continue
}

ProximityPlacementGroup := &azure.ProximityPlacementGroups{}
if v, ok := attr[string(PPGName)].(string); ok && v != "" {
ProximityPlacementGroup.SetName(spotinst.String(v))
}

if v, ok := attr[string(PPGResourceGroupName)].(string); ok && v != "" {
ProximityPlacementGroup.SetResourceGroupName(spotinst.String(v))
}
ppgs = append(ppgs, ProximityPlacementGroup)
}
return ppgs, nil
}

func flattenProximityPlacementGroups(ppgs []*azure.ProximityPlacementGroups) []interface{} {
result := make([]interface{}, 0, len(ppgs))
for _, ppg := range ppgs {
m := make(map[string]interface{})
m[string(PPGResourceGroupName)] = spotinst.StringValue(ppg.ResourceGroupName)
m[string(PPGName)] = spotinst.StringValue(ppg.Name)
result = append(result, m)
}
return result
}

func flattenOSDisk(osd *azure.OSDisk) []interface{} {
osDisk := make(map[string]interface{})
osDisk[string(OSDiskSizeGB)] = spotinst.IntValue(osd.SizeGB)
Expand Down