@@ -94,6 +94,35 @@ func ResourceNetappVolume() *schema.Resource {
94
94
Required : true ,
95
95
Description : `Name of the storage pool to create the volume in. Pool needs enough spare capacity to accomodate the volume.` ,
96
96
},
97
+ "backup_config" : {
98
+ Type : schema .TypeList ,
99
+ Optional : true ,
100
+ Description : `Backup configuration for the volume.` ,
101
+ MaxItems : 1 ,
102
+ Elem : & schema.Resource {
103
+ Schema : map [string ]* schema.Schema {
104
+ "backup_policies" : {
105
+ Type : schema .TypeList ,
106
+ Optional : true ,
107
+ Description : `Specify a single backup policy ID for scheduled backups. Format: 'projects/{{projectId}}/locations/{{location}}/backupPolicies/{{backupPolicyName}}'` ,
108
+ Elem : & schema.Schema {
109
+ Type : schema .TypeString ,
110
+ },
111
+ },
112
+ "backup_vault" : {
113
+ Type : schema .TypeString ,
114
+ Optional : true ,
115
+ Description : `ID of the backup vault to use. A backup vault is reqired to create manual or scheduled backups.
116
+ Format: 'projects/{{projectId}}/locations/{{location}}/backupVaults/{{backupVaultName}}'` ,
117
+ },
118
+ "scheduled_backup_enabled" : {
119
+ Type : schema .TypeBool ,
120
+ Optional : true ,
121
+ Description : `When set to true, scheduled backup is enabled on the volume. Omit if no backup_policy is specified.` ,
122
+ },
123
+ },
124
+ },
125
+ },
97
126
"description" : {
98
127
Type : schema .TypeString ,
99
128
Optional : true ,
@@ -607,6 +636,12 @@ func resourceNetappVolumeCreate(d *schema.ResourceData, meta interface{}) error
607
636
} else if v , ok := d .GetOkExists ("snapshot_policy" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (snapshotPolicyProp )) && (ok || ! reflect .DeepEqual (v , snapshotPolicyProp )) {
608
637
obj ["snapshotPolicy" ] = snapshotPolicyProp
609
638
}
639
+ backupConfigProp , err := expandNetappVolumeBackupConfig (d .Get ("backup_config" ), d , config )
640
+ if err != nil {
641
+ return err
642
+ } else if v , ok := d .GetOkExists ("backup_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (backupConfigProp )) && (ok || ! reflect .DeepEqual (v , backupConfigProp )) {
643
+ obj ["backupConfig" ] = backupConfigProp
644
+ }
610
645
labelsProp , err := expandNetappVolumeEffectiveLabels (d .Get ("effective_labels" ), d , config )
611
646
if err != nil {
612
647
return err
@@ -799,6 +834,9 @@ func resourceNetappVolumeRead(d *schema.ResourceData, meta interface{}) error {
799
834
if err := d .Set ("snapshot_policy" , flattenNetappVolumeSnapshotPolicy (res ["snapshotPolicy" ], d , config )); err != nil {
800
835
return fmt .Errorf ("Error reading Volume: %s" , err )
801
836
}
837
+ if err := d .Set ("backup_config" , flattenNetappVolumeBackupConfig (res ["backupConfig" ], d , config )); err != nil {
838
+ return fmt .Errorf ("Error reading Volume: %s" , err )
839
+ }
802
840
if err := d .Set ("terraform_labels" , flattenNetappVolumeTerraformLabels (res ["labels" ], d , config )); err != nil {
803
841
return fmt .Errorf ("Error reading Volume: %s" , err )
804
842
}
@@ -879,6 +917,12 @@ func resourceNetappVolumeUpdate(d *schema.ResourceData, meta interface{}) error
879
917
} else if v , ok := d .GetOkExists ("snapshot_policy" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , snapshotPolicyProp )) {
880
918
obj ["snapshotPolicy" ] = snapshotPolicyProp
881
919
}
920
+ backupConfigProp , err := expandNetappVolumeBackupConfig (d .Get ("backup_config" ), d , config )
921
+ if err != nil {
922
+ return err
923
+ } else if v , ok := d .GetOkExists ("backup_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , backupConfigProp )) {
924
+ obj ["backupConfig" ] = backupConfigProp
925
+ }
882
926
labelsProp , err := expandNetappVolumeEffectiveLabels (d .Get ("effective_labels" ), d , config )
883
927
if err != nil {
884
928
return err
@@ -931,6 +975,12 @@ func resourceNetappVolumeUpdate(d *schema.ResourceData, meta interface{}) error
931
975
updateMask = append (updateMask , "snapshotPolicy" )
932
976
}
933
977
978
+ if d .HasChange ("backup_config" ) {
979
+ updateMask = append (updateMask , "backup_config.backup_policies" ,
980
+ "backup_config.backup_vault" ,
981
+ "backup_config.scheduled_backup_enabled" )
982
+ }
983
+
934
984
if d .HasChange ("effective_labels" ) {
935
985
updateMask = append (updateMask , "labels" )
936
986
}
@@ -1581,6 +1631,35 @@ func flattenNetappVolumeSnapshotPolicyMonthlyScheduleDaysOfMonth(v interface{},
1581
1631
return v
1582
1632
}
1583
1633
1634
+ func flattenNetappVolumeBackupConfig (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1635
+ if v == nil {
1636
+ return nil
1637
+ }
1638
+ original := v .(map [string ]interface {})
1639
+ if len (original ) == 0 {
1640
+ return nil
1641
+ }
1642
+ transformed := make (map [string ]interface {})
1643
+ transformed ["backup_policies" ] =
1644
+ flattenNetappVolumeBackupConfigBackupPolicies (original ["backupPolicies" ], d , config )
1645
+ transformed ["backup_vault" ] =
1646
+ flattenNetappVolumeBackupConfigBackupVault (original ["backupVault" ], d , config )
1647
+ transformed ["scheduled_backup_enabled" ] =
1648
+ flattenNetappVolumeBackupConfigScheduledBackupEnabled (original ["scheduledBackupEnabled" ], d , config )
1649
+ return []interface {}{transformed }
1650
+ }
1651
+ func flattenNetappVolumeBackupConfigBackupPolicies (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1652
+ return v
1653
+ }
1654
+
1655
+ func flattenNetappVolumeBackupConfigBackupVault (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1656
+ return v
1657
+ }
1658
+
1659
+ func flattenNetappVolumeBackupConfigScheduledBackupEnabled (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1660
+ return v
1661
+ }
1662
+
1584
1663
func flattenNetappVolumeTerraformLabels (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
1585
1664
if v == nil {
1586
1665
return v
@@ -2075,6 +2154,51 @@ func expandNetappVolumeSnapshotPolicyMonthlyScheduleDaysOfMonth(v interface{}, d
2075
2154
return v , nil
2076
2155
}
2077
2156
2157
+ func expandNetappVolumeBackupConfig (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2158
+ l := v .([]interface {})
2159
+ if len (l ) == 0 || l [0 ] == nil {
2160
+ return nil , nil
2161
+ }
2162
+ raw := l [0 ]
2163
+ original := raw .(map [string ]interface {})
2164
+ transformed := make (map [string ]interface {})
2165
+
2166
+ transformedBackupPolicies , err := expandNetappVolumeBackupConfigBackupPolicies (original ["backup_policies" ], d , config )
2167
+ if err != nil {
2168
+ return nil , err
2169
+ } else if val := reflect .ValueOf (transformedBackupPolicies ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2170
+ transformed ["backupPolicies" ] = transformedBackupPolicies
2171
+ }
2172
+
2173
+ transformedBackupVault , err := expandNetappVolumeBackupConfigBackupVault (original ["backup_vault" ], d , config )
2174
+ if err != nil {
2175
+ return nil , err
2176
+ } else if val := reflect .ValueOf (transformedBackupVault ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2177
+ transformed ["backupVault" ] = transformedBackupVault
2178
+ }
2179
+
2180
+ transformedScheduledBackupEnabled , err := expandNetappVolumeBackupConfigScheduledBackupEnabled (original ["scheduled_backup_enabled" ], d , config )
2181
+ if err != nil {
2182
+ return nil , err
2183
+ } else if val := reflect .ValueOf (transformedScheduledBackupEnabled ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
2184
+ transformed ["scheduledBackupEnabled" ] = transformedScheduledBackupEnabled
2185
+ }
2186
+
2187
+ return transformed , nil
2188
+ }
2189
+
2190
+ func expandNetappVolumeBackupConfigBackupPolicies (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2191
+ return v , nil
2192
+ }
2193
+
2194
+ func expandNetappVolumeBackupConfigBackupVault (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2195
+ return v , nil
2196
+ }
2197
+
2198
+ func expandNetappVolumeBackupConfigScheduledBackupEnabled (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
2199
+ return v , nil
2200
+ }
2201
+
2078
2202
func expandNetappVolumeEffectiveLabels (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (map [string ]string , error ) {
2079
2203
if v == nil {
2080
2204
return map [string ]string {}, nil
0 commit comments