-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
azurerm_sql_database
blob auditing error under online secondary…
… create mode (#6402)
- Loading branch information
Showing
7 changed files
with
363 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
azurerm/internal/services/mssql/helper/sql_extended_auditing.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package helper | ||
|
||
import ( | ||
"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/v3.0/sql" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func ExtendedAuditingSchema() *schema.Schema { | ||
return &schema.Schema{ | ||
Type: schema.TypeList, | ||
Optional: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"storage_account_access_key": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Sensitive: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"storage_endpoint": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.IsURLWithHTTPS, | ||
}, | ||
|
||
"storage_account_access_key_is_secondary": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
}, | ||
|
||
"retention_in_days": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
ValidateFunc: validation.IntBetween(0, 3285), | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func ExpandAzureRmMsSqlDBBlobAuditingPolicies(input []interface{}) *sql.ExtendedDatabaseBlobAuditingPolicyProperties { | ||
if len(input) == 0 { | ||
return &sql.ExtendedDatabaseBlobAuditingPolicyProperties{ | ||
State: sql.BlobAuditingPolicyStateDisabled, | ||
} | ||
} | ||
dbBlobAuditingPolicies := input[0].(map[string]interface{}) | ||
|
||
ExtendedDatabaseBlobAuditingPolicyProperties := sql.ExtendedDatabaseBlobAuditingPolicyProperties{ | ||
State: sql.BlobAuditingPolicyStateEnabled, | ||
StorageAccountAccessKey: utils.String(dbBlobAuditingPolicies["storage_account_access_key"].(string)), | ||
StorageEndpoint: utils.String(dbBlobAuditingPolicies["storage_endpoint"].(string)), | ||
} | ||
if v, ok := dbBlobAuditingPolicies["storage_account_access_key_is_secondary"]; ok { | ||
ExtendedDatabaseBlobAuditingPolicyProperties.IsStorageSecondaryKeyInUse = utils.Bool(v.(bool)) | ||
} | ||
if v, ok := dbBlobAuditingPolicies["retention_in_days"]; ok { | ||
ExtendedDatabaseBlobAuditingPolicyProperties.RetentionDays = utils.Int32(int32(v.(int))) | ||
} | ||
|
||
return &ExtendedDatabaseBlobAuditingPolicyProperties | ||
} | ||
|
||
func FlattenAzureRmMsSqlDBBlobAuditingPolicies(extendedDatabaseBlobAuditingPolicy *sql.ExtendedDatabaseBlobAuditingPolicy, d *schema.ResourceData) []interface{} { | ||
if extendedDatabaseBlobAuditingPolicy == nil || extendedDatabaseBlobAuditingPolicy.State == sql.BlobAuditingPolicyStateDisabled { | ||
return []interface{}{} | ||
} | ||
var storageAccessKey, storageEndpoint string | ||
// storage_account_access_key will not be returned, so we transfer the schema value | ||
if v, ok := d.GetOk("extended_auditing_policy.0.storage_account_access_key"); ok { | ||
storageAccessKey = v.(string) | ||
} | ||
|
||
if extendedDatabaseBlobAuditingPolicy.StorageEndpoint != nil { | ||
storageEndpoint = *extendedDatabaseBlobAuditingPolicy.StorageEndpoint | ||
} | ||
var secondKeyInUse bool | ||
if extendedDatabaseBlobAuditingPolicy.IsStorageSecondaryKeyInUse != nil { | ||
secondKeyInUse = *extendedDatabaseBlobAuditingPolicy.IsStorageSecondaryKeyInUse | ||
} | ||
var retentionDays int32 | ||
if extendedDatabaseBlobAuditingPolicy.RetentionDays != nil { | ||
retentionDays = *extendedDatabaseBlobAuditingPolicy.RetentionDays | ||
} | ||
|
||
return []interface{}{ | ||
map[string]interface{}{ | ||
"storage_account_access_key": storageAccessKey, | ||
"storage_endpoint": storageEndpoint, | ||
"storage_account_access_key_is_secondary": secondKeyInUse, | ||
"retention_in_days": retentionDays, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.