Skip to content

Commit

Permalink
Add longtermpolicies...
Browse files Browse the repository at this point in the history
  • Loading branch information
WodansSon committed Nov 4, 2023
1 parent 29761c1 commit e8df8cf
Show file tree
Hide file tree
Showing 14 changed files with 531 additions and 15 deletions.
8 changes: 4 additions & 4 deletions internal/services/mssql/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/databases" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/databasesecurityalertpolicies" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/geobackuppolicies" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/longtermretentionbackups" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/longtermretentionpolicies" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/replicationlinks" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/restorabledroppeddatabases" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/serverazureadadministrators" // nolint: staticcheck
Expand All @@ -27,7 +27,7 @@ import (
)

type Client struct {
BackupShortTermRetentionPoliciesClient *backupshorttermretentionpolicies.LongTermRetentionPoliciesClient
BackupShortTermRetentionPoliciesClient *backupshorttermretentionpolicies.BackupShortTermRetentionPoliciesClient
DatabaseExtendedBlobAuditingPoliciesClient *sql.ExtendedDatabaseBlobAuditingPoliciesClient
DatabaseSecurityAlertPoliciesClient *databasesecurityalertpolicies.DatabaseSecurityAlertPoliciesClient
DatabaseVulnerabilityAssessmentRuleBaselinesClient *sql.DatabaseVulnerabilityAssessmentRuleBaselinesClient
Expand All @@ -39,7 +39,7 @@ type Client struct {
GeoBackupPoliciesClient *geobackuppolicies.GeoBackupPoliciesClient
JobAgentsClient *sql.JobAgentsClient
JobCredentialsClient *sql.JobCredentialsClient
LongTermRetentionPoliciesClient *longtermretentionbackups.LongTermRetentionPoliciesClient
LongTermRetentionPoliciesClient *longtermretentionpolicies.LongTermRetentionPoliciesClient
OutboundFirewallRulesClient *sql.OutboundFirewallRulesClient
ReplicationLinksClient *replicationlinks.ReplicationLinksClient
RestorableDroppedDatabasesClient *restorabledroppeddatabases.RestorableDroppedDatabasesClient
Expand Down Expand Up @@ -109,7 +109,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
jobCredentialsClient := sql.NewJobCredentialsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&jobCredentialsClient.Client, o.ResourceManagerAuthorizer)

longTermRetentionPoliciesClient, err := longtermretentionbackups.NewLongTermRetentionPoliciesClientWithBaseURI(o.Environment.ResourceManager)
longTermRetentionPoliciesClient, err := longtermretentionpolicies.NewLongTermRetentionPoliciesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Long Term Retention Policies Client: %+v", err)
}
Expand Down
20 changes: 11 additions & 9 deletions internal/services/mssql/helper/sql_retention_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"strconv"
"strings"

"github.com/Azure/azure-sdk-for-go/services/preview/sql/mgmt/v5.0/sql" // nolint: staticcheck
// nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/backupshorttermretentionpolicies" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/longtermretentionpolicies" // nolint: staticcheck
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -98,14 +100,14 @@ func ShortTermRetentionPolicySchema() *pluginsdk.Schema {
}
}

func ExpandLongTermRetentionPolicy(input []interface{}) *sql.BaseLongTermRetentionPolicyProperties {
func ExpandLongTermRetentionPolicy(input []interface{}) *longtermretentionpolicies.LongTermRetentionPolicyProperties {
if len(input) == 0 || input[0] == nil {
return nil
}

longTermRetentionPolicy := input[0].(map[string]interface{})

longTermPolicyProperties := sql.BaseLongTermRetentionPolicyProperties{
longTermPolicyProperties := longtermretentionpolicies.LongTermRetentionPolicyProperties{
WeeklyRetention: utils.String("PT0S"),
MonthlyRetention: utils.String("PT0S"),
YearlyRetention: utils.String("PT0S"),
Expand All @@ -131,7 +133,7 @@ func ExpandLongTermRetentionPolicy(input []interface{}) *sql.BaseLongTermRetenti
return &longTermPolicyProperties
}

func FlattenLongTermRetentionPolicy(longTermRetentionPolicy *sql.LongTermRetentionPolicy, d *pluginsdk.ResourceData) []interface{} {
func FlattenLongTermRetentionPolicy(longTermRetentionPolicy *longtermretentionpolicies.LongTermRetentionPolicy, d *pluginsdk.ResourceData) []interface{} {
if longTermRetentionPolicy == nil {
return []interface{}{}
}
Expand Down Expand Up @@ -166,14 +168,14 @@ func FlattenLongTermRetentionPolicy(longTermRetentionPolicy *sql.LongTermRetenti
}
}

func ExpandShortTermRetentionPolicy(input []interface{}) *sql.BackupShortTermRetentionPolicyProperties {
func ExpandShortTermRetentionPolicy(input []interface{}) *backupshorttermretentionpolicies.BackupShortTermRetentionPolicyProperties {
if len(input) == 0 || input[0] == nil {
return nil
}

shortTermRetentionPolicy := input[0].(map[string]interface{})

shortTermPolicyProperties := sql.BackupShortTermRetentionPolicyProperties{
shortTermPolicyProperties := backupshorttermretentionpolicies.BackupShortTermRetentionPolicyProperties{
RetentionDays: utils.Int32(7),
}

Expand All @@ -188,7 +190,7 @@ func ExpandShortTermRetentionPolicy(input []interface{}) *sql.BackupShortTermRet
return &shortTermPolicyProperties
}

func FlattenShortTermRetentionPolicy(shortTermRetentionPolicy *sql.BackupShortTermRetentionPolicy, d *pluginsdk.ResourceData) []interface{} {
func FlattenShortTermRetentionPolicy(shortTermRetentionPolicy *backupshorttermretentionpolicies.BackupShortTermRetentionPolicy, d *pluginsdk.ResourceData) []interface{} {
result := make([]interface{}, 0)

if shortTermRetentionPolicy == nil {
Expand All @@ -199,11 +201,11 @@ func FlattenShortTermRetentionPolicy(shortTermRetentionPolicy *sql.BackupShortTe

flattenShortTermRetentionPolicy["retention_days"] = int32(7)
if shortTermRetentionPolicy.RetentionDays != nil {
flattenShortTermRetentionPolicy["retention_days"] = *shortTermRetentionPolicy.RetentionDays
flattenShortTermRetentionPolicy["retention_days"] = *backupshorttermretentionpolicies.RetentionDays
}

if shortTermRetentionPolicy.DiffBackupIntervalInHours != nil {
flattenShortTermRetentionPolicy["backup_interval_in_hours"] = *shortTermRetentionPolicy.DiffBackupIntervalInHours
flattenShortTermRetentionPolicy["backup_interval_in_hours"] = *backupshorttermretentionpolicies.DiffBackupIntervalInHours
}
result = append(result, flattenShortTermRetentionPolicy)
return result
Expand Down
4 changes: 2 additions & 2 deletions internal/services/mssql/mssql_database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/databases" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/databasesecurityalertpolicies" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/geobackuppolicies" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/longtermretentionbackups" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/longtermretentionpolicies" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/replicationlinks" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/servers" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/sql/2023-02-01-preview/serversecurityalertpolicies" // nolint: staticcheck
Expand Down Expand Up @@ -462,7 +462,7 @@ func resourceMsSqlDatabaseCreate(d *pluginsdk.ResourceData, meta interface{}) er

longTermRetentionProps := helper.ExpandLongTermRetentionPolicy(d.Get("long_term_retention_policy").([]interface{}))
if longTermRetentionProps != nil {
longTermRetentionPolicy := longtermretentionbackups.LongTermRetentionPolicy{}
longTermRetentionPolicy := longtermretentionpolicies.LongTermRetentionPolicy{}

// DataWarehouse SKU's do not support LRP currently
if !strings.HasPrefix(skuName.(string), "DW") {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e8df8cf

Please sign in to comment.