From 5b27f106bbfe731c83f71be6f057b8528b8a062d Mon Sep 17 00:00:00 2001 From: Marcin Swiderski Date: Thu, 26 Oct 2023 12:20:37 +0200 Subject: [PATCH] OAS-7760 | Add support for setting drop_vst_support field --- go.mod | 2 +- go.sum | 4 +- internal/resource_deployment.go | 16 ++++ internal/resource_deployment_test.go | 130 +++++++++++++++++++++++++++ 4 files changed, 149 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 819a367..fd27092 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/arangodb-managed/terraform-provider-oasis go 1.20 require ( - github.com/arangodb-managed/apis v0.81.4 + github.com/arangodb-managed/apis v0.83.1 github.com/arangodb-managed/log-helper v0.2.5 github.com/gogo/protobuf v1.3.2 github.com/hashicorp/terraform-plugin-docs v0.8.1 diff --git a/go.sum b/go.sum index 987d8e5..dac725a 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/ github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= -github.com/arangodb-managed/apis v0.81.4 h1:KGB4XHRSXIhdmKkIqwcL+OFTUG48CIQENinoHdArOqA= -github.com/arangodb-managed/apis v0.81.4/go.mod h1:ZlvA803MmUI3m6ijvaAYKKaWgLJq8bBZZuq8uyZo2PY= +github.com/arangodb-managed/apis v0.83.1 h1:Os+gxplikZDRFcpuO4Lk60qfrYHj8BInuOj955I3W2o= +github.com/arangodb-managed/apis v0.83.1/go.mod h1:ZlvA803MmUI3m6ijvaAYKKaWgLJq8bBZZuq8uyZo2PY= github.com/arangodb-managed/log-helper v0.2.5 h1:Kg3+0bDVFhEgyjMhIbCIj9hejgN2VaD4Cw/JQ4ARsd4= github.com/arangodb-managed/log-helper v0.2.5/go.mod h1:G17ASSd3Edday3i1QREGefyLJ2TduHxxFsOaqoigurE= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= diff --git a/internal/resource_deployment.go b/internal/resource_deployment.go index ceafc58..74e4596 100644 --- a/internal/resource_deployment.go +++ b/internal/resource_deployment.go @@ -61,6 +61,7 @@ const ( deplLockedFieldName = "locked" deplDeploymentProfileIDFieldName = "deployment_profile_id" deplIsPlatformAuthEnabled = "is_platform_authentication_enabled" + deplDropVSTSupportFieldName = "drop_vst_support" ) func resourceDeployment() *schema.Resource { @@ -265,6 +266,12 @@ func resourceDeployment() *schema.Resource { Optional: true, Default: false, }, + deplDropVSTSupportFieldName: { + Type: schema.TypeBool, + Description: "Deployment Resource Deployment Drop VST Support field", + Optional: true, + Default: false, + }, }, } } @@ -440,6 +447,7 @@ func expandDeploymentResource(d *schema.ResourceData, defaultProject string) (*d locked bool deploymentProfileID string isPlatformAuthenticationEnabled bool + dropVSTSupport bool ) if v, ok := d.GetOk(deplNameFieldName); ok { name = v.(string) @@ -504,6 +512,9 @@ func expandDeploymentResource(d *schema.ResourceData, defaultProject string) (*d if v, ok := d.GetOk(deplIsPlatformAuthEnabled); ok { isPlatformAuthenticationEnabled = v.(bool) } + if v, ok := d.GetOk(deplDropVSTSupportFieldName); ok { + dropVSTSupport = v.(bool) + } return &data.Deployment{ Name: name, @@ -527,6 +538,7 @@ func expandDeploymentResource(d *schema.ResourceData, defaultProject string) (*d Locked: locked, DeploymentProfileId: deploymentProfileID, IsPlatformAuthenticationEnabled: isPlatformAuthenticationEnabled, + DropVstSupport: dropVSTSupport, }, nil } @@ -663,6 +675,7 @@ func flattenDeployment(depl *data.Deployment) map[string]interface{} { deplDisableScheduledRootPasswordRotationFieldName: !depl.GetIsScheduledRootPasswordRotationEnabled(), deplLockedFieldName: depl.GetLocked(), deplIsPlatformAuthEnabled: depl.GetIsPlatformAuthenticationEnabled(), + deplDropVSTSupportFieldName: depl.GetDropVstSupport(), } if notificationSetting != nil { result[deplNotificationConfigurationFieldName] = notificationSetting @@ -808,6 +821,9 @@ func resourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, m int if d.HasChange(deplLockedFieldName) { depl.Locked = d.Get(deplLockedFieldName).(bool) } + if d.HasChange(deplDropVSTSupportFieldName) { + depl.DropVstSupport = d.Get(deplDropVSTSupportFieldName).(bool) + } if d.HasChange(deplDeploymentProfileIDFieldName) { return diag.FromErr(errors.New("deployment profile id cannot be changed")) diff --git a/internal/resource_deployment_test.go b/internal/resource_deployment_test.go index 277679b..d5f2599 100644 --- a/internal/resource_deployment_test.go +++ b/internal/resource_deployment_test.go @@ -130,6 +130,7 @@ func TestFlattenDeploymentResource(t *testing.T) { deplLockedFieldName: false, deplDeploymentProfileIDFieldName: deploymentProfileTestID, deplIsPlatformAuthEnabled: false, + deplDropVSTSupportFieldName: false, } assert.Equal(t, expected, flattened) } @@ -191,6 +192,69 @@ func TestFlattenDeploymentResourcePlatformAuthentication(t *testing.T) { deplDisableScheduledRootPasswordRotationFieldName: false, deplLockedFieldName: true, deplIsPlatformAuthEnabled: true, + deplDropVSTSupportFieldName: false, + } + assert.Equal(t, expected, flattened) +} + +// TestFlattenDeploymentResourceDropVSTSupport tests the Oasis Deployment flattening with DropVSTSupport set to true. +func TestFlattenDeploymentResourceDropVSTSupport(t *testing.T) { + depl := &data.Deployment{ + Name: "test-name", + Description: "test-desc", + ProjectId: "123456789", + RegionId: "gcp-europe-west4", + Version: "3.9.1", + Certificates: &data.Deployment_CertificateSpec{ + CaCertificateId: "certificate-id", + }, + IpallowlistId: "ip-allowlist", + DisableFoxxAuthentication: true, + Model: &data.Deployment_ModelSpec{ + Model: "oneshard", + NodeSizeId: "a8", + NodeCount: 3, + NodeDiskSize: 32, + }, + IsScheduledRootPasswordRotationEnabled: true, + Locked: true, + DropVstSupport: true, + } + flattened := flattenDeployment(depl) + expected := map[string]interface{}{ + deplProjectFieldName: "123456789", + deplNameFieldName: "test-name", + deplDescriptionFieldName: "test-desc", + deplLocationFieldName: []interface{}{ + map[string]interface{}{ + deplLocationRegionFieldName: "gcp-europe-west4", + }, + }, + deplVersionFieldName: []interface{}{ + map[string]interface{}{ + deplVersionDbVersionFieldName: "3.9.1", + }, + }, + deplSecurityFieldName: []interface{}{ + map[string]interface{}{ + deplSecurityCaCertificateFieldName: "certificate-id", + deplSecurityIpAllowlistFieldName: "ip-allowlist", + deplSecurityDisableFoxxAuthenticationFieldName: true, + }, + }, + deplConfigurationFieldName: []interface{}{ + map[string]interface{}{ + deplConfigurationModelFieldName: "oneshard", + deplConfigurationNodeSizeIdFieldName: "a8", + deplConfigurationNodeCountFieldName: 3, + deplConfigurationNodeDiskSizeFieldName: 32, + }, + }, + deplDiskPerformanceFieldName: "", // Not set + deplDisableScheduledRootPasswordRotationFieldName: false, + deplLockedFieldName: true, + deplIsPlatformAuthEnabled: false, + deplDropVSTSupportFieldName: true, } assert.Equal(t, expected, flattened) } @@ -251,6 +315,7 @@ func TestFlattenDeploymentResourceDisableFoxxAuth(t *testing.T) { deplDisableScheduledRootPasswordRotationFieldName: false, deplLockedFieldName: true, deplIsPlatformAuthEnabled: false, + deplDropVSTSupportFieldName: false, } assert.Equal(t, expected, flattened) } @@ -319,6 +384,7 @@ func TestFlattenDeploymentResourceNotificationSettings(t *testing.T) { deplDisableScheduledRootPasswordRotationFieldName: true, deplLockedFieldName: true, deplIsPlatformAuthEnabled: false, + deplDropVSTSupportFieldName: false, } assert.Equal(t, expected, flattened) } @@ -393,6 +459,70 @@ func TestExpandingDeploymentResource(t *testing.T) { assert.Equal(t, depl, expandedDepl) } +// TestExpandingDeploymentResourceDropVSTSupport tests the Oasis Deployment expansion with DropVSTSupport set to true. +func TestExpandingDeploymentResourceDropVSTSupport(t *testing.T) { + depl := &data.Deployment{ + Name: "test-name", + Description: "test-desc", + ProjectId: "123456789", + RegionId: "gcp-europe-west4", + Version: "3.9.1", + Certificates: &data.Deployment_CertificateSpec{ + CaCertificateId: "certificate-id", + }, + IpallowlistId: "ip-allowlist", + DisableFoxxAuthentication: true, + Model: &data.Deployment_ModelSpec{ + Model: "oneshard", + NodeSizeId: "a8", + NodeCount: 3, + NodeDiskSize: 32, + }, + IsScheduledRootPasswordRotationEnabled: true, + Locked: true, + DropVstSupport: true, + } + raw := map[string]interface{}{ + deplProjectFieldName: "123456789", + deplNameFieldName: "test-name", + deplDescriptionFieldName: "test-desc", + deplLocationFieldName: []interface{}{ + map[string]interface{}{ + deplLocationRegionFieldName: "gcp-europe-west4", + }, + }, + deplVersionFieldName: []interface{}{ + map[string]interface{}{ + deplVersionDbVersionFieldName: "3.9.1", + }, + }, + deplSecurityFieldName: []interface{}{ + map[string]interface{}{ + deplSecurityCaCertificateFieldName: "certificate-id", + deplSecurityIpAllowlistFieldName: "ip-allowlist", + deplSecurityDisableFoxxAuthenticationFieldName: true, + }, + }, + deplConfigurationFieldName: []interface{}{ + map[string]interface{}{ + deplConfigurationModelFieldName: "oneshard", + deplConfigurationNodeSizeIdFieldName: "a8", + deplConfigurationNodeCountFieldName: 3, + deplConfigurationNodeDiskSizeFieldName: 32, + }, + }, + deplDisableScheduledRootPasswordRotationFieldName: false, + deplLockedFieldName: true, + deplIsPlatformAuthEnabled: false, + deplDropVSTSupportFieldName: true, + } + s := resourceDeployment().Schema + resourceData := schema.TestResourceDataRaw(t, s, raw) + expandedDepl, err := expandDeploymentResource(resourceData, "123456789") + assert.NoError(t, err) + assert.Equal(t, depl, expandedDepl) +} + // TestExpandingDeploymentResourceDisableFoxxAuth tests the Oasis Deployment expansion with DisableFoxxAuthentication set to true. func TestExpandingDeploymentResourceDisableFoxxAuth(t *testing.T) { depl := &data.Deployment{