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

azurerm_app_configuration - support for the encrption, local_auth_enabled, public_network_access_enabled, purge_protection_enabled,and soft_delete_retention_days properties #17714

Merged
merged 9 commits into from
Oct 13, 2022
4 changes: 4 additions & 0 deletions internal/features/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ func Default() UserFeatures {
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeleted: true,
},
AppConfiguration: AppConfigurationFeatures{
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeleted: true,
},
ApplicationInsights: ApplicationInsightFeatures{
DisableGeneratedRule: false,
},
Expand Down
6 changes: 6 additions & 0 deletions internal/features/user_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package features

type UserFeatures struct {
ApiManagement ApiManagementFeatures
AppConfiguration AppConfigurationFeatures
ApplicationInsights ApplicationInsightFeatures
CognitiveAccount CognitiveAccountFeatures
VirtualMachine VirtualMachineFeatures
Expand Down Expand Up @@ -60,3 +61,8 @@ type ApiManagementFeatures struct {
type ApplicationInsightFeatures struct {
DisableGeneratedRule bool
}

type AppConfigurationFeatures struct {
PurgeSoftDeleteOnDestroy bool
RecoverSoftDeleted bool
}
34 changes: 34 additions & 0 deletions internal/provider/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ func schemaFeatures(supportLegacyTestSuite bool) *pluginsdk.Schema {
},
},

"app_configuration": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"purge_soft_delete_on_destroy": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},

"recover_soft_deleted": {
Type: pluginsdk.TypeBool,
Optional: true,
Default: true,
},
},
},
},

"application_insights": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -291,6 +312,19 @@ func expandFeatures(input []interface{}) features.UserFeatures {
}
}

if raw, ok := val["app_configuration"]; ok {
items := raw.([]interface{})
if len(items) > 0 && items[0] != nil {
appConfRaw := items[0].(map[string]interface{})
if v, ok := appConfRaw["purge_soft_delete_on_destroy"]; ok {
featuresMap.AppConfiguration.PurgeSoftDeleteOnDestroy = v.(bool)
}
if v, ok := appConfRaw["recover_soft_deleted"]; ok {
featuresMap.AppConfiguration.RecoverSoftDeleted = v.(bool)
}
}
}

if raw, ok := val["application_insights"]; ok {
items := raw.([]interface{})
if len(items) > 0 && items[0] != nil {
Expand Down
94 changes: 94 additions & 0 deletions internal/provider/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func TestExpandFeatures(t *testing.T) {
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeleted: true,
},
AppConfiguration: features.AppConfigurationFeatures{
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeleted: true,
},
ApplicationInsights: features.ApplicationInsightFeatures{
DisableGeneratedRule: false,
},
Expand Down Expand Up @@ -70,6 +74,12 @@ func TestExpandFeatures(t *testing.T) {
"recover_soft_deleted": true,
},
},
"app_configuration": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": true,
"recover_soft_deleted": true,
},
},
"application_insights": []interface{}{
map[string]interface{}{
"disable_generated_rule": true,
Expand Down Expand Up @@ -134,6 +144,10 @@ func TestExpandFeatures(t *testing.T) {
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeleted: true,
},
AppConfiguration: features.AppConfigurationFeatures{
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeleted: true,
},
ApplicationInsights: features.ApplicationInsightFeatures{
DisableGeneratedRule: true,
},
Expand Down Expand Up @@ -182,6 +196,12 @@ func TestExpandFeatures(t *testing.T) {
"recover_soft_deleted": false,
},
},
"app_configuration": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": false,
"recover_soft_deleted": false,
},
},
"application_insights": []interface{}{
map[string]interface{}{
"disable_generated_rule": false,
Expand Down Expand Up @@ -246,6 +266,10 @@ func TestExpandFeatures(t *testing.T) {
PurgeSoftDeleteOnDestroy: false,
RecoverSoftDeleted: false,
},
AppConfiguration: features.AppConfigurationFeatures{
PurgeSoftDeleteOnDestroy: false,
RecoverSoftDeleted: false,
},
ApplicationInsights: features.ApplicationInsightFeatures{
DisableGeneratedRule: false,
},
Expand Down Expand Up @@ -365,6 +389,76 @@ func TestExpandFeaturesApiManagement(t *testing.T) {
}
}

func TestExpandFeaturesAppConfiguration(t *testing.T) {
testData := []struct {
Name string
Input []interface{}
EnvVars map[string]interface{}
Expected features.UserFeatures
}{
{
Name: "Empty Block",
Input: []interface{}{
map[string]interface{}{
"app_configuration": []interface{}{},
},
},
Expected: features.UserFeatures{
AppConfiguration: features.AppConfigurationFeatures{
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeleted: true,
},
},
},
{
Name: "Purge Soft Delete On Destroy and Recover Soft Deleted App Configuration Enabled",
Input: []interface{}{
map[string]interface{}{
"app_configuration": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": true,
"recover_soft_deleted": true,
},
},
},
},
Expected: features.UserFeatures{
AppConfiguration: features.AppConfigurationFeatures{
PurgeSoftDeleteOnDestroy: true,
RecoverSoftDeleted: true,
},
},
},
{
Name: "Purge Soft Delete On Destroy and Recover Soft Deleted App Configuration Disabled",
Input: []interface{}{
map[string]interface{}{
"app_configuration": []interface{}{
map[string]interface{}{
"purge_soft_delete_on_destroy": false,
"recover_soft_deleted": false,
},
},
},
},
Expected: features.UserFeatures{
AppConfiguration: features.AppConfigurationFeatures{
PurgeSoftDeleteOnDestroy: false,
RecoverSoftDeleted: false,
},
},
},
}

for _, testCase := range testData {
t.Logf("[DEBUG] Test Case: %q", testCase.Name)
result := expandFeatures(testCase.Input)
if !reflect.DeepEqual(result.AppConfiguration, testCase.Expected.AppConfiguration) {
t.Fatalf("Expected %+v but got %+v", result.AppConfiguration, testCase.Expected.AppConfiguration)
}
}
}

func TestExpandFeaturesApplicationInsights(t *testing.T) {
testData := []struct {
Name string
Expand Down
30 changes: 30 additions & 0 deletions internal/services/appconfiguration/app_configuration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package appconfiguration

import (
"github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2022-05-01/configurationstores"
)

func flattenAppConfigurationEncryption(input *configurationstores.EncryptionProperties) []interface{} {
if input == nil || input.KeyVaultProperties == nil {
return []interface{}{}
}

return []interface{}{
map[string]interface{}{
"identity_client_id": input.KeyVaultProperties.IdentityClientId,
"key_vault_key_identifier": input.KeyVaultProperties.KeyIdentifier,
},
}
}

func flattenAppConfigurationPublicNetworkAccess(input *configurationstores.PublicNetworkAccess) bool {
if input == nil {
return false
}

result := true
if *input == configurationstores.PublicNetworkAccessDisabled {
result = false
}
return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,52 @@ func dataSourceAppConfiguration() *pluginsdk.Resource {

"location": commonschema.LocationComputed(),

"encryption": {
Type: pluginsdk.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"key_vault_key_identifier": {
Type: pluginsdk.TypeString,
Computed: true,
},
"identity_client_id": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},

"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),

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

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

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

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

"soft_delete_retention_days": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"endpoint": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -177,6 +218,22 @@ func dataSourceAppConfigurationRead(d *pluginsdk.ResourceData, meta interface{})

if props := model.Properties; props != nil {
d.Set("endpoint", props.Endpoint)
d.Set("encryption", flattenAppConfigurationEncryption(props.Encryption))
d.Set("public_network_access_enabled", flattenAppConfigurationPublicNetworkAccess(props.PublicNetworkAccess))
d.Set("soft_delete_retention_days", props.SoftDeleteRetentionInDays)

localAuthEnabled := true
if props.DisableLocalAuth != nil {
localAuthEnabled = !(*props.DisableLocalAuth)
}

d.Set("local_auth_enabled", localAuthEnabled)

purgeProtectionEnabled := false
if props.EnablePurgeProtection != nil {
purgeProtectionEnabled = *props.EnablePurgeProtection
}
d.Set("purge_protection_enabled", purgeProtectionEnabled)
}

accessKeys := flattenAppConfigurationAccessKeys(resultPage.Items)
Expand Down
Loading