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

fsx/ontap_storeage_virtulal_mcahine: Remove deprecadted distinguidshed #22915

Merged
merged 13 commits into from
Feb 3, 2022
3 changes: 3 additions & 0 deletions .changelog/22915.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:breaking-change
resource/aws_fsx_ontap_storage_virtual_machine: Remove deprecated `active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguidshed_name`, migrating value to `active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguished_name`
```
3 changes: 3 additions & 0 deletions .github/workflows/terraform_provider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ jobs:
if [[ "${pkg}" == */test-fixtures ]]; then
continue
fi
if [[ "${pkg}" == internal/generate/* ]]; then
continue
fi
while read file; do
if [ "${file}" = "" ]; then
continue
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing/contribution-checklists.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ More details about this code generation can be found in the [namevaluesfilters d

### Resource Filter Code Implementation

- In the resource's equivalent data source Go file (e.g., `internal/service/ec2/internet_gateway_data_source.go`), add the following Go import: `"github.com/hashicorp/terraform-provider-aws/internal/namevaluesfilters"`
- In the resource's equivalent data source Go file (e.g., `internal/service/ec2/internet_gateway_data_source.go`), add the following Go import: `"github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfilters"`
- In the resource schema, add `"filter": namevaluesfilters.Schema(),`
- Implement the logic to build the list of filters:

Expand Down
34 changes: 15 additions & 19 deletions internal/service/fsx/ontap_storage_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ func ResourceOntapStorageVirtualMachine() *schema.Resource {
Delete: schema.DefaultTimeout(30 * time.Minute),
},

SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: ResourceOntapStorageVirtualMachineV0().CoreConfigSchema().ImpliedType(),
Upgrade: ResourceOntapStorageVirtualMachineStateUpgradeV0,
Version: 0,
},
},

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Expand Down Expand Up @@ -82,20 +91,11 @@ func ResourceOntapStorageVirtualMachine() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 256),
},
"organizational_unit_distinguidshed_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 2000),
Deprecated: "use 'organizational_unit_distinguished_name' instead",
ConflictsWith: []string{"active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguished_name"},
},
"organizational_unit_distinguished_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 2000),
ConflictsWith: []string{"active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguidshed_name"},
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 2000),
},
"password": {
Type: schema.TypeString,
Expand Down Expand Up @@ -430,9 +430,7 @@ func expandFsxOntapSvmSelfManagedActiveDirectoryConfiguration(cfg []interface{})
out.FileSystemAdministratorsGroup = aws.String(v)
}

if v, ok := conf["organizational_unit_distinguidshed_name"].(string); ok && len(v) > 0 {
out.OrganizationalUnitDistinguishedName = aws.String(v)
} else if v, ok := conf["organizational_unit_distinguished_name"].(string); ok && len(v) > 0 {
if v, ok := conf["organizational_unit_distinguished_name"].(string); ok && len(v) > 0 {
out.OrganizationalUnitDistinguishedName = aws.String(v)
}

Expand Down Expand Up @@ -523,9 +521,7 @@ func flattenFsxOntapSelfManagedActiveDirectoryConfiguration(d *schema.ResourceDa
}

if rs.OrganizationalUnitDistinguishedName != nil {
if _, ok := d.GetOk("active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguidshed_name"); ok {
m["organizational_unit_distinguidshed_name"] = aws.StringValue(rs.OrganizationalUnitDistinguishedName)
} else {
if _, ok := d.GetOk("active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguished_name"); ok {
m["organizational_unit_distinguished_name"] = aws.StringValue(rs.OrganizationalUnitDistinguishedName)
}
}
Expand Down
217 changes: 217 additions & 0 deletions internal/service/fsx/ontap_storage_virtual_machine_migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
package fsx

import (
"context"
"log"
"strings"

"github.com/aws/aws-sdk-go/service/fsx"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
)

func ResourceOntapStorageVirtualMachineV0() *schema.Resource {
return &schema.Resource{
SchemaVersion: 0,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"active_directory_configuration": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"netbios_name": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.EqualFold(old, new)
},
ValidateFunc: validation.StringLenBetween(1, 15),
},
"self_managed_active_directory_configuration": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dns_ips": {
Type: schema.TypeSet,
Required: true,
MinItems: 1,
MaxItems: 3,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.IsIPAddress,
},
},
"domain_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
"file_system_administrators_group": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 256),
},
"organizational_unit_distinguidshed_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 2000),
Deprecated: "use 'organizational_unit_distinguished_name' instead",
ConflictsWith: []string{"active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguished_name"},
},
"organizational_unit_distinguished_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 2000),
ConflictsWith: []string{"active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguidshed_name"},
},
"password": {
Type: schema.TypeString,
Sensitive: true,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 256),
},
"username": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 256),
},
},
},
},
},
},
},
"endpoints": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"iscsi": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dns_name": {
Type: schema.TypeString,
Computed: true,
},
"ip_addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"management": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dns_name": {
Type: schema.TypeString,
Computed: true,
},
"ip_addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"nfs": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dns_name": {
Type: schema.TypeString,
Computed: true,
},
"ip_addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
"smb": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"dns_name": {
Type: schema.TypeString,
Computed: true,
},
"ip_addresses": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
},
},
},
},
},
"file_system_id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(11, 21),
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 47),
},
"root_volume_security_style": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(fsx.StorageVirtualMachineRootVolumeSecurityStyle_Values(), false),
},
"subtype": {
Type: schema.TypeString,
Computed: true,
},
"svm_admin_password": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringLenBetween(8, 50),
},
"tags": tftags.TagsSchema(),
"tags_all": tftags.TagsSchemaComputed(),
"uuid": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func ResourceOntapStorageVirtualMachineStateUpgradeV0(_ context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
log.Printf("[DEBUG] Attributes before migration: %#v", rawState)

rawState["active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguished_name"] = rawState["active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguidshed_name"]
delete(rawState, "active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguidshed_name")

log.Printf("[DEBUG] Attributes after migration: %#v", rawState)
return rawState, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package fsx_test

import (
"context"
"reflect"
"testing"

tffsx "github.com/hashicorp/terraform-provider-aws/internal/service/fsx"
)

func testOntapStorageVirtualMachineStateDataV0() map[string]interface{} {
return map[string]interface{}{
"active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguidshed_name": "MeArrugoDerrito",
}
}

func testOntapStorageVirtualMachineStateDataV1() map[string]interface{} {
v0 := testOntapStorageVirtualMachineStateDataV0()
return map[string]interface{}{
"active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguished_name": v0["active_directory_configuration.0.self_managed_active_directory_configuration.0.organizational_unit_distinguidshed_name"],
}
}

func TestOntapStorageVirtualMachineStateUpgradeV0(t *testing.T) {
expected := testOntapStorageVirtualMachineStateDataV1()
actual, err := tffsx.ResourceOntapStorageVirtualMachineStateUpgradeV0(context.Background(), testOntapStorageVirtualMachineStateDataV0(), nil)

if err != nil {
t.Fatalf("error migrating state: %s", err)
}

if !reflect.DeepEqual(expected, actual) {
t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", expected, actual)
}
}
Loading