From 176cfb47acda0243e0a8d2650656f3e32e7e29a5 Mon Sep 17 00:00:00 2001 From: Shane Gill Date: Wed, 18 Oct 2023 09:18:50 +1000 Subject: [PATCH] feat: spaceID support machine policies --- octopusdeploy/data_source_machine_policies.go | 7 ++++--- octopusdeploy/resource_machine_policy.go | 11 +++++++---- octopusdeploy/schema_machine_cleanup_policy.go | 8 ++++---- octopusdeploy/schema_machine_connectivity_policy.go | 8 ++++---- octopusdeploy/schema_machine_health_check_policy.go | 8 ++++---- octopusdeploy/schema_machine_policy.go | 11 ++++++----- octopusdeploy/schema_machine_script_policy.go | 8 ++++---- octopusdeploy/schema_machine_update_policy.go | 8 ++++---- 8 files changed, 37 insertions(+), 32 deletions(-) diff --git a/octopusdeploy/data_source_machine_policies.go b/octopusdeploy/data_source_machine_policies.go index 1ee7881fc..9e03a45c4 100644 --- a/octopusdeploy/data_source_machine_policies.go +++ b/octopusdeploy/data_source_machine_policies.go @@ -5,7 +5,7 @@ import ( "time" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machinepolicies" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -19,15 +19,16 @@ func dataSourceMachinePolicies() *schema.Resource { } func dataSourceMachinePoliciesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { - query := machines.MachinePoliciesQuery{ + query := machinepolicies.MachinePoliciesQuery{ IDs: expandArray(d.Get("ids").([]interface{})), PartialName: d.Get("partial_name").(string), Skip: d.Get("skip").(int), Take: d.Get("take").(int), } + spaceID := d.Get("space_id").(string) client := m.(*client.Client) - existingMachinePolicies, err := client.MachinePolicies.Get(query) + existingMachinePolicies, err := machinepolicies.Get(client, spaceID, query) if err != nil { return diag.FromErr(err) } diff --git a/octopusdeploy/resource_machine_policy.go b/octopusdeploy/resource_machine_policy.go index 0616baf5a..ab759fc7a 100644 --- a/octopusdeploy/resource_machine_policy.go +++ b/octopusdeploy/resource_machine_policy.go @@ -5,6 +5,7 @@ import ( "log" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machinepolicies" "github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -28,7 +29,7 @@ func resourceMachinePolicyCreate(ctx context.Context, d *schema.ResourceData, m log.Printf("[INFO] creating machine policy: %#v", machinePolicy) client := m.(*client.Client) - createdMachinePolicy, err := client.MachinePolicies.Add(machinePolicy) + createdMachinePolicy, err := machinepolicies.Add(client, machinePolicy) if err != nil { return diag.FromErr(err) } @@ -46,8 +47,9 @@ func resourceMachinePolicyCreate(ctx context.Context, d *schema.ResourceData, m func resourceMachinePolicyDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Printf("[INFO] deleting machine policy (%s)", d.Id()) + spaceID := d.Get("space_id").(string) client := m.(*client.Client) - if err := client.MachinePolicies.DeleteByID(d.Id()); err != nil { + if err := machinepolicies.DeleteByID(client, spaceID, d.Id()); err != nil { return diag.FromErr(err) } @@ -60,8 +62,9 @@ func resourceMachinePolicyDelete(ctx context.Context, d *schema.ResourceData, m func resourceMachinePolicyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { log.Printf("[INFO] reading machine policy (%s)", d.Id()) + spaceID := d.Get("space_id").(string) client := m.(*client.Client) - machinePolicy, err := client.MachinePolicies.GetByID(d.Id()) + machinePolicy, err := machinepolicies.GetByID(client, spaceID, d.Id()) if err != nil { return errors.ProcessApiError(ctx, d, err, "machine policy") } @@ -79,7 +82,7 @@ func resourceMachinePolicyUpdate(ctx context.Context, d *schema.ResourceData, m machinePolicy := expandMachinePolicy(d) client := m.(*client.Client) - updatedMachinePolicy, err := client.MachinePolicies.Update(machinePolicy) + updatedMachinePolicy, err := machinepolicies.Update(client, machinePolicy) if err != nil { return diag.FromErr(err) } diff --git a/octopusdeploy/schema_machine_cleanup_policy.go b/octopusdeploy/schema_machine_cleanup_policy.go index 0ddec3de9..63919acc1 100644 --- a/octopusdeploy/schema_machine_cleanup_policy.go +++ b/octopusdeploy/schema_machine_cleanup_policy.go @@ -3,12 +3,12 @@ package octopusdeploy import ( "time" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machinepolicies" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -func expandMachineCleanupPolicy(values interface{}) *machines.MachineCleanupPolicy { +func expandMachineCleanupPolicy(values interface{}) *machinepolicies.MachineCleanupPolicy { if values == nil { return nil } @@ -19,7 +19,7 @@ func expandMachineCleanupPolicy(values interface{}) *machines.MachineCleanupPoli flattenedMap := flattenedValues.List()[0].(map[string]interface{}) - machineCleanupPolicy := machines.NewMachineCleanupPolicy() + machineCleanupPolicy := machinepolicies.NewMachineCleanupPolicy() if v, ok := flattenedMap["delete_machines_behavior"]; ok { machineCleanupPolicy.DeleteMachinesBehavior = v.(string) @@ -32,7 +32,7 @@ func expandMachineCleanupPolicy(values interface{}) *machines.MachineCleanupPoli return machineCleanupPolicy } -func flattenMachineCleanupPolicy(machineCleanupPolicy *machines.MachineCleanupPolicy) []interface{} { +func flattenMachineCleanupPolicy(machineCleanupPolicy *machinepolicies.MachineCleanupPolicy) []interface{} { if machineCleanupPolicy == nil { return nil } diff --git a/octopusdeploy/schema_machine_connectivity_policy.go b/octopusdeploy/schema_machine_connectivity_policy.go index 0a1869493..fdda20c98 100644 --- a/octopusdeploy/schema_machine_connectivity_policy.go +++ b/octopusdeploy/schema_machine_connectivity_policy.go @@ -1,12 +1,12 @@ package octopusdeploy import ( - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machinepolicies" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -func expandMachineConnectivityPolicy(values interface{}) *machines.MachineConnectivityPolicy { +func expandMachineConnectivityPolicy(values interface{}) *machinepolicies.MachineConnectivityPolicy { if values == nil { return nil } @@ -17,7 +17,7 @@ func expandMachineConnectivityPolicy(values interface{}) *machines.MachineConnec flattenedMap := flattenedValues.List()[0].(map[string]interface{}) - machineConnectivityPolicy := machines.NewMachineConnectivityPolicy() + machineConnectivityPolicy := machinepolicies.NewMachineConnectivityPolicy() if v, ok := flattenedMap["machine_connectivity_behavior"]; ok { machineConnectivityPolicy.MachineConnectivityBehavior = v.(string) @@ -26,7 +26,7 @@ func expandMachineConnectivityPolicy(values interface{}) *machines.MachineConnec return machineConnectivityPolicy } -func flattenMachineConnectivityPolicy(machineConnectivityPolicy *machines.MachineConnectivityPolicy) []interface{} { +func flattenMachineConnectivityPolicy(machineConnectivityPolicy *machinepolicies.MachineConnectivityPolicy) []interface{} { if machineConnectivityPolicy == nil { return nil } diff --git a/octopusdeploy/schema_machine_health_check_policy.go b/octopusdeploy/schema_machine_health_check_policy.go index 52752650f..59a00a0a2 100644 --- a/octopusdeploy/schema_machine_health_check_policy.go +++ b/octopusdeploy/schema_machine_health_check_policy.go @@ -3,12 +3,12 @@ package octopusdeploy import ( "time" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machinepolicies" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -func expandMachineHealthCheckPolicy(values interface{}) *machines.MachineHealthCheckPolicy { +func expandMachineHealthCheckPolicy(values interface{}) *machinepolicies.MachineHealthCheckPolicy { if values == nil { return nil } @@ -19,7 +19,7 @@ func expandMachineHealthCheckPolicy(values interface{}) *machines.MachineHealthC flattenedMap := flattenedValues.List()[0].(map[string]interface{}) - machineHealthCheckPolicy := machines.NewMachineHealthCheckPolicy() + machineHealthCheckPolicy := machinepolicies.NewMachineHealthCheckPolicy() if v, ok := flattenedMap["bash_health_check_policy"]; ok { if len(v.([]interface{})) > 0 { @@ -54,7 +54,7 @@ func expandMachineHealthCheckPolicy(values interface{}) *machines.MachineHealthC return machineHealthCheckPolicy } -func flattenMachineHealthCheckPolicy(machineHealthCheckPolicy *machines.MachineHealthCheckPolicy) []interface{} { +func flattenMachineHealthCheckPolicy(machineHealthCheckPolicy *machinepolicies.MachineHealthCheckPolicy) []interface{} { if machineHealthCheckPolicy == nil { return nil } diff --git a/octopusdeploy/schema_machine_policy.go b/octopusdeploy/schema_machine_policy.go index 0aa34d422..001569350 100644 --- a/octopusdeploy/schema_machine_policy.go +++ b/octopusdeploy/schema_machine_policy.go @@ -5,14 +5,14 @@ import ( "fmt" "time" - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machinepolicies" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func expandMachinePolicy(d *schema.ResourceData) *machines.MachinePolicy { +func expandMachinePolicy(d *schema.ResourceData) *machinepolicies.MachinePolicy { name := d.Get("name").(string) - machinePolicy := machines.NewMachinePolicy(name) + machinePolicy := machinepolicies.NewMachinePolicy(name) machinePolicy.ID = d.Id() if v, ok := d.GetOk("connection_connect_timeout"); ok { @@ -83,7 +83,7 @@ func expandMachinePolicy(d *schema.ResourceData) *machines.MachinePolicy { } -func flattenMachinePolicy(machinePolicy *machines.MachinePolicy) map[string]interface{} { +func flattenMachinePolicy(machinePolicy *machinepolicies.MachinePolicy) map[string]interface{} { if machinePolicy == nil { return nil } @@ -123,6 +123,7 @@ func getMachinePolicyDataSchema() map[string]*schema.Schema { "partial_name": getQueryPartialName(), "skip": getQuerySkip(), "take": getQueryTake(), + "space_id": getSpaceIDSchema(), } } @@ -202,7 +203,7 @@ func getMachinePolicySchema() map[string]*schema.Schema { } } -func setMachinePolicy(ctx context.Context, d *schema.ResourceData, machinePolicy *machines.MachinePolicy) error { +func setMachinePolicy(ctx context.Context, d *schema.ResourceData, machinePolicy *machinepolicies.MachinePolicy) error { d.Set("connection_connect_timeout", machinePolicy.ConnectionConnectTimeout) d.Set("connection_retry_count_limit", machinePolicy.ConnectionRetryCountLimit) d.Set("connection_retry_sleep_interval", machinePolicy.ConnectionRetrySleepInterval) diff --git a/octopusdeploy/schema_machine_script_policy.go b/octopusdeploy/schema_machine_script_policy.go index d23f1adff..c1e2797cc 100644 --- a/octopusdeploy/schema_machine_script_policy.go +++ b/octopusdeploy/schema_machine_script_policy.go @@ -1,12 +1,12 @@ package octopusdeploy import ( - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machinepolicies" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -func expandMachineScriptPolicy(values interface{}) *machines.MachineScriptPolicy { +func expandMachineScriptPolicy(values interface{}) *machinepolicies.MachineScriptPolicy { if values == nil { return nil } @@ -17,7 +17,7 @@ func expandMachineScriptPolicy(values interface{}) *machines.MachineScriptPolicy flattenedMap := flattenedValues[0].(map[string]interface{}) - machineScriptPolicy := machines.NewMachineScriptPolicy() + machineScriptPolicy := machinepolicies.NewMachineScriptPolicy() if v, ok := flattenedMap["run_type"]; ok { machineScriptPolicy.RunType = v.(string) @@ -31,7 +31,7 @@ func expandMachineScriptPolicy(values interface{}) *machines.MachineScriptPolicy return machineScriptPolicy } -func flattenMachineScriptPolicy(machineScriptPolicy *machines.MachineScriptPolicy) []interface{} { +func flattenMachineScriptPolicy(machineScriptPolicy *machinepolicies.MachineScriptPolicy) []interface{} { if machineScriptPolicy == nil { return nil } diff --git a/octopusdeploy/schema_machine_update_policy.go b/octopusdeploy/schema_machine_update_policy.go index 7b726079e..ffc7d3d85 100644 --- a/octopusdeploy/schema_machine_update_policy.go +++ b/octopusdeploy/schema_machine_update_policy.go @@ -1,12 +1,12 @@ package octopusdeploy import ( - "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machinepolicies" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" ) -func expandMachineUpdatePolicy(values interface{}) *machines.MachineUpdatePolicy { +func expandMachineUpdatePolicy(values interface{}) *machinepolicies.MachineUpdatePolicy { if values == nil { return nil } @@ -17,7 +17,7 @@ func expandMachineUpdatePolicy(values interface{}) *machines.MachineUpdatePolicy flattenedMap := flattenedValues.List()[0].(map[string]interface{}) - machineUpdatePolicy := machines.NewMachineUpdatePolicy() + machineUpdatePolicy := machinepolicies.NewMachineUpdatePolicy() if v, ok := flattenedMap["calamari_update_behavior"]; ok { machineUpdatePolicy.CalamariUpdateBehavior = v.(string) @@ -34,7 +34,7 @@ func expandMachineUpdatePolicy(values interface{}) *machines.MachineUpdatePolicy return machineUpdatePolicy } -func flattenMachineUpdatePolicy(machineUpdatePolicy *machines.MachineUpdatePolicy) []interface{} { +func flattenMachineUpdatePolicy(machineUpdatePolicy *machinepolicies.MachineUpdatePolicy) []interface{} { if machineUpdatePolicy == nil { return nil }