Skip to content

Commit

Permalink
Refactor: Remove ThreePointOhBeta from k service packages (#16670)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfrahry authored May 6, 2022
1 parent 34e0788 commit 29e5835
Show file tree
Hide file tree
Showing 10 changed files with 465 additions and 716 deletions.
22 changes: 8 additions & 14 deletions internal/services/keyvault/access_policy_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (

"github.com/Azure/azure-sdk-for-go/services/preview/keyvault/mgmt/2020-04-01-preview/keyvault"
"github.com/gofrs/uuid"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

Expand Down Expand Up @@ -130,9 +128,8 @@ func schemaCertificatePermissions() *pluginsdk.Schema {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(certificatePermissions(), !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(certificatePermissions(), false),
},
}
}
Expand All @@ -142,9 +139,8 @@ func schemaKeyPermissions() *pluginsdk.Schema {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(keyPermissions(), !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(keyPermissions(), false),
},
}
}
Expand All @@ -154,9 +150,8 @@ func schemaSecretPermissions() *pluginsdk.Schema {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(secretPermissions(), !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(secretPermissions(), false),
},
}
}
Expand All @@ -166,9 +161,8 @@ func schemaStoragePermissions() *pluginsdk.Schema {
Type: pluginsdk.TypeList,
Optional: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(storagePermissions(), !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
Type: pluginsdk.TypeString,
ValidateFunc: validation.StringInSlice(storagePermissions(), false),
},
}
}
Expand Down
5 changes: 1 addition & 4 deletions internal/services/keyvault/key_vault_certificate_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse"
keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/set"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
Expand Down Expand Up @@ -164,8 +162,7 @@ func resourceKeyVaultCertificate() *pluginsdk.Resource {
string(keyvault.RSA),
string(keyvault.RSAHSM),
string(keyvault.Oct),
}, !features.ThreePointOhBeta()),
DiffSuppressFunc: suppress.CaseDifferenceV2Only,
}, false),
},
"reuse_key": {
Type: pluginsdk.TypeBool,
Expand Down
255 changes: 120 additions & 135 deletions internal/services/keyvault/key_vault_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
Expand All @@ -26,148 +25,138 @@ func dataSourceKeyVault() *pluginsdk.Resource {
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},

Schema: func() map[string]*pluginsdk.Schema {
dsSchema := map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.VaultName,
},

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

"location": commonschema.LocationComputed(),

"sku_name": {
Type: pluginsdk.TypeString,
Computed: true,
},

"vault_uri": {
Type: pluginsdk.TypeString,
Computed: true,
},

"tenant_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"access_policy": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"tenant_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"object_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"application_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"certificate_permissions": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validate.VaultName,
},

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

"location": commonschema.LocationComputed(),

"sku_name": {
Type: pluginsdk.TypeString,
Computed: true,
},

"vault_uri": {
Type: pluginsdk.TypeString,
Computed: true,
},

"tenant_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

"access_policy": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"tenant_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"object_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"application_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
"certificate_permissions": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
"key_permissions": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
"key_permissions": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
"secret_permissions": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
"secret_permissions": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
"storage_permissions": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
"storage_permissions": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
},
},

"enabled_for_deployment": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"enabled_for_disk_encryption": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"enabled_for_template_deployment": {
Type: pluginsdk.TypeBool,
Computed: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_rbac_authorization": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"network_acls": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"default_action": {
Type: pluginsdk.TypeString,
Computed: true,
},
"bypass": {
Type: pluginsdk.TypeString,
Computed: true,
},
"ip_rules": {
Type: pluginsdk.TypeSet,
Computed: true,
Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString},
Set: pluginsdk.HashString,
},
"virtual_network_subnet_ids": {
Type: pluginsdk.TypeSet,
Computed: true,
Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString},
Set: set.HashStringIgnoreCase,
},
},

"enabled_for_deployment": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"enabled_for_disk_encryption": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"enabled_for_template_deployment": {
Type: pluginsdk.TypeBool,
Computed: true,
},

// TODO 4.0: change this from enable_* to *_enabled
"enable_rbac_authorization": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"network_acls": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"default_action": {
Type: pluginsdk.TypeString,
Computed: true,
},
"bypass": {
Type: pluginsdk.TypeString,
Computed: true,
},
"ip_rules": {
Type: pluginsdk.TypeSet,
Computed: true,
Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString},
Set: pluginsdk.HashString,
},
"virtual_network_subnet_ids": {
Type: pluginsdk.TypeSet,
Computed: true,
Elem: &pluginsdk.Schema{Type: pluginsdk.TypeString},
Set: set.HashStringIgnoreCase,
},
},
},
},

"purge_protection_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},
"purge_protection_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"tags": tags.SchemaDataSource(),
}
if !features.ThreePointOhBeta() {
dsSchema["soft_delete_enabled"] = &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Computed: true,
Deprecated: `Azure has removed support for disabling Soft Delete as of 2020-12-15, as such this field will always return 'true' and will be removed in version 3.0 of the Azure Provider.`,
}
}
return dsSchema
}(),
"tags": tags.SchemaDataSource(),
},
}
}

Expand Down Expand Up @@ -203,10 +192,6 @@ func dataSourceKeyVaultRead(d *pluginsdk.ResourceData, meta interface{}) error {
d.Set("purge_protection_enabled", props.EnablePurgeProtection)
d.Set("vault_uri", props.VaultURI)

if !features.ThreePointOhBeta() {
d.Set("soft_delete_enabled", true)
}

if sku := props.Sku; sku != nil {
if err := d.Set("sku_name", string(sku.Name)); err != nil {
return fmt.Errorf("setting `sku_name` for KeyVault %q: %+v", *resp.Name, err)
Expand Down
Loading

0 comments on commit 29e5835

Please sign in to comment.