Skip to content

Commit

Permalink
support incremental backups with feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
posriniv committed Jan 30, 2024
1 parent 66d3bc7 commit 9bca93c
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 152 deletions.
97 changes: 57 additions & 40 deletions managed/data_source_cluster_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/yugabyte/terraform-provider-ybm/managed/fflags"
//"github.com/hashicorp/terraform-plugin-log/tflog"
//"fmt"
)
Expand Down Expand Up @@ -79,46 +80,8 @@ func (r dataClusterNameType) GetSchema(_ context.Context) (tfsdk.Schema, diag.Di
}),
},
"backup_schedules": {
Computed: true,
Attributes: tfsdk.ListNestedAttributes(map[string]tfsdk.Attribute{

"state": {

Description: "The state of the backup schedule. Used to pause or resume the backup schedule. Valid values are ACTIVE or PAUSED.",
Type: types.StringType,
Computed: true,
},

"cron_expression": {
Description: "The cron expression for the backup schedule.",
Type: types.StringType,
Computed: true,
},

"time_interval_in_days": {
Description: "The time interval in days for the backup schedule.",
Type: types.Int64Type,
Computed: true,
},

"retention_period_in_days": {
Description: "The retention period of the backup schedule.",
Type: types.Int64Type,
Computed: true,
},

"backup_description": {
Description: "The description of the backup schedule.",
Type: types.StringType,
Computed: true,
},

"schedule_id": {
Description: "The ID of the backup schedule. Created automatically when the backup schedule is created. Used to get a specific backup schedule.",
Type: types.StringType,
Computed: true,
},
}),
Computed: true,
Attributes: tfsdk.ListNestedAttributes(getBackupScheduleAttributes()),
},
"cmk_spec": {
Description: "KMS Provider Configuration.",
Expand Down Expand Up @@ -516,3 +479,57 @@ func (r dataClusterName) Read(ctx context.Context, req tfsdk.ReadDataSourceReque
}

}

func getBackupScheduleDsAttributes() map[string]tfsdk.Attribute {

backupScheduleAttributes := map[string]tfsdk.Attribute{

"state": {

Description: "The state of the backup schedule. Used to pause or resume the backup schedule. Valid values are ACTIVE or PAUSED.",
Type: types.StringType,
Computed: true,
},

"cron_expression": {
Description: "The cron expression for the backup schedule.",
Type: types.StringType,
Computed: true,
},

"time_interval_in_days": {
Description: "The time interval in days for the backup schedule.",
Type: types.Int64Type,
Computed: true,
},

"retention_period_in_days": {
Description: "The retention period of the backup schedule.",
Type: types.Int64Type,
Computed: true,
},

"backup_description": {
Description: "The description of the backup schedule.",
Type: types.StringType,
Computed: true,
},

"schedule_id": {
Description: "The ID of the backup schedule. Created automatically when the backup schedule is created. Used to get a specific backup schedule.",
Type: types.StringType,
Computed: true,
},
}

if fflags.IsFeatureFlagEnabled(fflags.INCREMENTAL_BACKUP) {
backupScheduleAttributes["incremental_interval_in_mins"] = tfsdk.Attribute{
Description: "The time interval in minutes for the incremental backup schedule.",
Type: types.Int64Type,
Computed: true,
}
}

return backupScheduleAttributes

}
26 changes: 26 additions & 0 deletions managed/fflags/feature_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright © 2022-present Yugabyte, Inc. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package fflags

import (
"os"
"strings"
)

type FeatureFlag string

const (
INCREMENTAL_BACKUP FeatureFlag = "INCREMENTAL_BACKUP"
)

func (f FeatureFlag) String() string {
return string(f)
}

func IsFeatureFlagEnabled(featureFlag FeatureFlag) bool {
envVarName := "YBM_FF_" + featureFlag.String()
return strings.ToLower(os.Getenv(envVarName)) == "true"
}
24 changes: 13 additions & 11 deletions managed/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package managed

import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/yugabyte/terraform-provider-ybm/managed/util"
)

type Cluster struct {
Expand Down Expand Up @@ -85,12 +86,13 @@ type GCPServiceAccount struct {
}

type BackupScheduleInfo struct {
State types.String `tfsdk:"state"`
RetentionPeriodInDays types.Int64 `tfsdk:"retention_period_in_days"`
ScheduleID types.String `tfsdk:"schedule_id"`
BackupDescription types.String `tfsdk:"backup_description"`
CronExpression types.String `tfsdk:"cron_expression"`
TimeIntervalInDays types.Int64 `tfsdk:"time_interval_in_days"`
State types.String `tfsdk:"state"`
RetentionPeriodInDays types.Int64 `tfsdk:"retention_period_in_days"`
ScheduleID types.String `tfsdk:"schedule_id"`
BackupDescription types.String `tfsdk:"backup_description"`
CronExpression types.String `tfsdk:"cron_expression"`
TimeIntervalInDays types.Int64 `tfsdk:"time_interval_in_days"`
IncrementalIntervalInMins types.Int64 `tfsdk:"incremental_interval_in_mins"`
}
type RegionInfo struct {
Region types.String `tfsdk:"region"`
Expand Down Expand Up @@ -285,22 +287,22 @@ type SumoLogicSpec struct {
}

func (d DataDogSpec) EncryptedKey() string {
return obfuscateString(d.ApiKey.Value)
return util.ObfuscateString(d.ApiKey.Value)
}

func (g GrafanaSpec) EncryptedKey() string {
return obfuscateStringLenght(g.AccessTokenPolicy.Value, 5)
return util.ObfuscateStringLenght(g.AccessTokenPolicy.Value, 5)
}

func (s SumoLogicSpec) EncryptedKey(key string) string {
switch key {

case "access_key":
return obfuscateString(s.AccessKey.Value)
return util.ObfuscateString(s.AccessKey.Value)
case "access_id":
return obfuscateString(s.AccessId.Value)
return util.ObfuscateString(s.AccessId.Value)
case "installation_token":
return obfuscateString(s.InstallationToken.Value)
return util.ObfuscateString(s.InstallationToken.Value)
}
return ""
}
Expand Down
5 changes: 3 additions & 2 deletions managed/resource_allow_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
retry "github.com/sethvargo/go-retry"
"github.com/yugabyte/terraform-provider-ybm/managed/util"
openapiclient "github.com/yugabyte/yugabytedb-managed-go-client-internal"
)

Expand Down Expand Up @@ -284,7 +285,7 @@ func (r resourceAllowList) Delete(ctx context.Context, req tfsdk.DeleteResourceR
accountId := state.AccountID.Value
projectId := state.ProjectID.Value
allowListId := state.AllowListID.Value
clusterIds := SliceTypesStringToSliceString(state.ClusterIDs)
clusterIds := util.SliceTypesStringToSliceString(state.ClusterIDs)

apiClient := r.p.client

Expand Down Expand Up @@ -370,7 +371,7 @@ func removeAllowListFromCluster(ctx context.Context, accountId string, projectId
}
return fmt.Errorf("unable to check network allow list for cluster %s: %s", clusterId, GetApiErrorDetails(err))
}
allowList := Filter(clusterNalResp.GetData(), func(ep openapiclient.NetworkAllowListData) bool {
allowList := util.Filter(clusterNalResp.GetData(), func(ep openapiclient.NetworkAllowListData) bool {
return ep.GetInfo().Id != allowListId
})

Expand Down
Loading

0 comments on commit 9bca93c

Please sign in to comment.