Skip to content

Commit

Permalink
Feature is snapshot consistency group and Migration PR (#4973)
Browse files Browse the repository at this point in the history
* GO-SDK Updated

* ibm_is_snapshot_consistency_group development

* Consistency Group changes to Snapshot

* Documentation changes for snapshot

* SDK changes

* Bankup Policy Jobs Changes

* included_content  development

* match_resource_type development

* Implemented Documentation Fix

* PR review comments incorporated

* SDK update

* Updated to released SDK
  • Loading branch information
SunithaGudisagarIBM1 authored Dec 13, 2023
1 parent d98953d commit dfb68f8
Show file tree
Hide file tree
Showing 31 changed files with 3,197 additions and 67 deletions.
39 changes: 37 additions & 2 deletions examples/ibm-is-ng/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,16 @@ data "ibm_is_volumes" "example" {

## Backup Policy
resource "ibm_is_backup_policy" "is_backup_policy" {
match_user_tags = ["tag1"]
name = "my-backup-policy"
match_user_tags = ["tag1"]
name = "my-backup-policy"
match_resource_type = "volume"
}

resource "ibm_is_backup_policy" "is_backup_policy" {
match_user_tags = ["tag1"]
name = "my-backup-policy-instance"
match_resource_type = "instance"
included_content = ["boot_volume", "data_volumes"]
}

resource "ibm_is_backup_policy_plan" "is_backup_policy_plan" {
Expand Down Expand Up @@ -1399,3 +1407,30 @@ resource "ibm_is_image_deprecate" "example" {
resource "ibm_is_image_obsolete" "example" {
image = ibm_is_image.image1.id
}


//snapshot consistency group

resource "ibm_is_snapshot_consistency_group" "is_snapshot_consistency_group_instance" {
delete_snapshots_on_delete = true
snapshots {
name = "exmaple-snapshot"
source_volume = ibm_is_instance.instance.volume_attachments[0].volume_id
}
snapshots {
name = "example-snapshot-1"
source_volume = ibm_is_instance.instance.volume_attachments[1].volume_id
}
name = "example-snapshot-consistency-group"
}

data "ibm_is_snapshot_consistency_group" "is_snapshot_consistency_group_instance" {
identifier = ibm_is_snapshot_consistency_group.is_snapshot_consistency_group_instance.id
}
data "ibm_is_snapshot_consistency_group" "is_snapshot_consistency_group_instance" {
name = "example-snapshot-consistency-group"
}
data "ibm_is_snapshot_consistency_groups" "is_snapshot_consistency_group_instance" {
depends_on = [ibm_is_snapshot_consistency_group.is_snapshot_consistency_group_instance]
name = "example-snapshot-consistency-group"
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
github.com/IBM/schematics-go-sdk v0.2.2
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.2
github.com/IBM/vpc-beta-go-sdk v0.6.0
github.com/IBM/vpc-go-sdk v0.43.0
github.com/IBM/vpc-go-sdk v0.45.0
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2
github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0
Expand Down Expand Up @@ -241,4 +241,4 @@ exclude (
github.com/kubernetes-incubator/external-storage v0.20.4-openstorage-rc2
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/client-go v12.0.0+incompatible
)
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ github.com/IBM/vpc-beta-go-sdk v0.6.0 h1:wfM3AcW3zOM3xsRtZ+EA6+sESlGUjQ6Yf4n5QQy
github.com/IBM/vpc-beta-go-sdk v0.6.0/go.mod h1:fzHDAQIqH/5yJmYsKodKHLcqxMDT+yfH6vZjdiw8CQA=
github.com/IBM/vpc-go-sdk v0.43.0 h1:uy/qWIqETCXraUG2cq5sjScr6pZ79ZteY1v5iLUVQ3Q=
github.com/IBM/vpc-go-sdk v0.43.0/go.mod h1:kRz9tqPvpHoA/qGrC/qVjTbi4ICuTChpG76L89liGL4=
github.com/IBM/vpc-go-sdk v0.45.0 h1:RFbUZH5vBRGAEW5+jRzbDlxB+a+GvG9EBhyYO52Tvrs=
github.com/IBM/vpc-go-sdk v0.45.0/go.mod h1:4Hs5d/aClmsxAzwDQkwG+ri0vW2ykPJdpM6hDLRwKcA=
github.com/Jeffail/gabs v1.1.1 h1:V0uzR08Hj22EX8+8QMhyI9sX2hwRu+/RJhJUmnwda/E=
github.com/Jeffail/gabs v1.1.1/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
Expand Down Expand Up @@ -1273,6 +1275,7 @@ github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAl
github.com/onsi/gomega v1.18.0/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/onsi/gomega v1.20.1/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeREyVo=
github.com/onsi/gomega v1.21.1/go.mod h1:iYAIXgPSaDHak0LCMA+AWBpIKBr8WZicMxnE8luStNc=
github.com/onsi/gomega v1.22.1/go.mod h1:x6n7VNe4hw0vkyYUM4mjIXx3JbLiPaBPNgB7PRQ1tuM=
Expand Down
21 changes: 13 additions & 8 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ func Provider() *schema.Provider {
"ibm_is_snapshot_clone": vpc.DataSourceSnapshotClone(),
"ibm_is_snapshot_clones": vpc.DataSourceSnapshotClones(),
"ibm_is_snapshot": vpc.DataSourceSnapshot(),
"ibm_is_snapshot_consistency_group": vpc.DataSourceIBMIsSnapshotConsistencyGroup(),
"ibm_is_snapshot_consistency_groups": vpc.DataSourceIBMIsSnapshotConsistencyGroups(),
"ibm_is_snapshots": vpc.DataSourceSnapshots(),
"ibm_is_share": vpc.DataSourceIbmIsShare(),
"ibm_is_source_share": vpc.DataSourceIbmIsSourceShare(),
Expand Down Expand Up @@ -1091,6 +1093,7 @@ func Provider() *schema.Provider {
"ibm_is_subnet_routing_table_attachment": vpc.ResourceIBMISSubnetRoutingTableAttachment(),
"ibm_is_ssh_key": vpc.ResourceIBMISSSHKey(),
"ibm_is_snapshot": vpc.ResourceIBMSnapshot(),
"ibm_is_snapshot_consistency_group": vpc.ResourceIBMIsSnapshotConsistencyGroup(),
"ibm_is_volume": vpc.ResourceIBMISVolume(),
"ibm_is_vpn_gateway": vpc.ResourceIBMISVPNGateway(),
"ibm_is_vpn_gateway_connection": vpc.ResourceIBMISVPNGatewayConnection(),
Expand Down Expand Up @@ -1532,6 +1535,7 @@ func Validator() validate.ValidatorDict {
"ibm_is_share_replica_operations": vpc.ResourceIbmIsShareReplicaOperationsValidator(),
"ibm_is_share_mount_target": vpc.ResourceIBMIsShareMountTargetValidator(),
"ibm_is_snapshot": vpc.ResourceIBMISSnapshotValidator(),
"ibm_is_snapshot_consistency_group": vpc.ResourceIBMIsSnapshotConsistencyGroupValidator(),
"ibm_is_ssh_key": vpc.ResourceIBMISSHKeyValidator(),
"ibm_is_subnet": vpc.ResourceIBMISSubnetValidator(),
"ibm_is_subnet_reserved_ip": vpc.ResourceIBMISSubnetReservedIPValidator(),
Expand Down Expand Up @@ -1664,14 +1668,15 @@ func Validator() validate.ValidatorDict {
"ibm_project_environment": project.ResourceIbmProjectEnvironmentValidator(),
},
DataSourceValidatorDictionary: map[string]*validate.ResourceValidator{
"ibm_is_subnet": vpc.DataSourceIBMISSubnetValidator(),
"ibm_is_snapshot": vpc.DataSourceIBMISSnapshotValidator(),
"ibm_is_images": vpc.DataSourceIBMISImagesValidator(),
"ibm_dl_offering_speeds": directlink.DataSourceIBMDLOfferingSpeedsValidator(),
"ibm_dl_routers": directlink.DataSourceIBMDLRoutersValidator(),
"ibm_resource_instance": resourcecontroller.DataSourceIBMResourceInstanceValidator(),
"ibm_resource_key": resourcecontroller.DataSourceIBMResourceKeyValidator(),
"ibm_resource_group": resourcemanager.DataSourceIBMResourceGroupValidator(),
"ibm_is_subnet": vpc.DataSourceIBMISSubnetValidator(),
"ibm_is_snapshot_consistency_group": vpc.DataSourceIBMISSnapshotConsistencyGroupValidator(),
"ibm_is_snapshot": vpc.DataSourceIBMISSnapshotValidator(),
"ibm_is_images": vpc.DataSourceIBMISImagesValidator(),
"ibm_dl_offering_speeds": directlink.DataSourceIBMDLOfferingSpeedsValidator(),
"ibm_dl_routers": directlink.DataSourceIBMDLRoutersValidator(),
"ibm_resource_instance": resourcecontroller.DataSourceIBMResourceInstanceValidator(),
"ibm_resource_key": resourcecontroller.DataSourceIBMResourceKeyValidator(),
"ibm_resource_group": resourcemanager.DataSourceIBMResourceGroupValidator(),

// bare_metal_server
"ibm_is_bare_metal_server": vpc.DataSourceIBMIsBareMetalServerValidator(),
Expand Down
24 changes: 21 additions & 3 deletions ibm/service/vpc/data_source_ibm_is_backup_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ func DataSourceIBMIsBackupPolicies() *schema.Resource {
Type: schema.TypeString,
},
},
"match_resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type this backup policy will apply to. Resources that have both a matching type and a matching user tag will be subject to the backup policy.",
},
"included_content": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The included content for backups created using this policy",
Elem: &schema.Schema{Type: schema.TypeString},
},
"match_user_tags": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -273,7 +284,10 @@ func dataSourceIBMIsBackupPoliciesRead(context context.Context, d *schema.Resour
break
}
start = flex.GetNext(backupPolicyCollection.Next)
matchBackupPolicies = append(matchBackupPolicies, backupPolicyCollection.BackupPolicies...)
for _, backupPolicyInfo := range backupPolicyCollection.BackupPolicies {
backupPolicies := backupPolicyInfo.(*vpcv1.BackupPolicy)
matchBackupPolicies = append(matchBackupPolicies, *backupPolicies)
}
if start == "" {
break
}
Expand Down Expand Up @@ -326,12 +340,16 @@ func dataSourceBackupPolicyCollectionBackupPoliciesToMap(backupPoliciesItem vpcv
if backupPoliciesItem.LastJobCompletedAt != nil {
backupPoliciesMap["last_job_completed_at"] = flex.DateTimeToString(backupPoliciesItem.LastJobCompletedAt)
}
if backupPoliciesItem.MatchResourceTypes != nil {
backupPoliciesMap["match_resource_types"] = backupPoliciesItem.MatchResourceTypes
if backupPoliciesItem.MatchResourceType != nil {
backupPoliciesMap["match_resource_types"] = []string{*backupPoliciesItem.MatchResourceType}
backupPoliciesMap["match_resource_type"] = *backupPoliciesItem.MatchResourceType
}
if backupPoliciesItem.MatchUserTags != nil {
backupPoliciesMap["match_user_tags"] = backupPoliciesItem.MatchUserTags
}
if backupPoliciesItem.IncludedContent != nil {
backupPoliciesMap["included_content"] = backupPoliciesItem.IncludedContent
}
if backupPoliciesItem.Name != nil {
backupPoliciesMap["name"] = backupPoliciesItem.Name
}
Expand Down
35 changes: 28 additions & 7 deletions ibm/service/vpc/data_source_ibm_is_backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ func DataSourceIBMIsBackupPolicy() *schema.Resource {
Type: schema.TypeString,
},
},
"match_resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type this backup policy will apply to. Resources that have both a matching type and a matching user tag will be subject to the backup policy.",
},
"included_content": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The included content for backups created using this policy",
Elem: &schema.Schema{Type: schema.TypeString},
},
"match_user_tags": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -223,7 +234,7 @@ func dataSourceIBMIsBackupPolicyRead(context context.Context, d *schema.Resource
log.Printf("[DEBUG] GetBackupPolicyWithContext failed %s\n%s", err, response)
return diag.FromErr(fmt.Errorf("[ERROR] GetBackupPolicyWithContext failed %s\n%s", err, response))
}
backupPolicy = backupPolicyInfo
backupPolicy = backupPolicyInfo.(*vpcv1.BackupPolicy)

} else if v, ok := d.GetOk("name"); ok {

Expand All @@ -244,7 +255,10 @@ func dataSourceIBMIsBackupPolicyRead(context context.Context, d *schema.Resource
break
}
start = flex.GetNext(backupPolicyCollection.Next)
allrecs = append(allrecs, backupPolicyCollection.BackupPolicies...)
for _, backupPolicyInfo := range backupPolicyCollection.BackupPolicies {
backupPolicies := backupPolicyInfo.(*vpcv1.BackupPolicy)
allrecs = append(allrecs, *backupPolicies)
}
if start == "" {
break
}
Expand Down Expand Up @@ -316,13 +330,20 @@ func dataSourceIBMIsBackupPolicyRead(context context.Context, d *schema.Resource
}
}

matchResourceType := make([]string, 0)
if backupPolicy.MatchResourceTypes != nil {
for _, matchResourceTyp := range backupPolicy.MatchResourceTypes {
matchResourceType = append(matchResourceType, matchResourceTyp)
if backupPolicy.MatchResourceType != nil {
if err = d.Set("match_resource_types", []string{*backupPolicy.MatchResourceType}); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting match_resource_types: %s", err))
}
if err = d.Set("match_resource_type", *backupPolicy.MatchResourceType); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting match_resource_type: %s", err))
}
}

if backupPolicy.IncludedContent != nil {
if err = d.Set("included_content", backupPolicy.IncludedContent); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting included_content: %s", err))
}
}
d.Set("match_resource_types", matchResourceType)

matchUserTags := make([]string, 0)
if backupPolicy.MatchUserTags != nil {
Expand Down
Loading

0 comments on commit dfb68f8

Please sign in to comment.