Skip to content

Commit 78e76e8

Browse files
feat(ebaas): Enterprise BaaS (IBM-Cloud#4845)
Co-authored-by: SunithaGudisagar <[email protected]>
1 parent d94fb51 commit 78e76e8

File tree

11 files changed

+429
-5
lines changed

11 files changed

+429
-5
lines changed

common/github.com/IBM/vpc-go-sdk/vpcv1/vpc_v1.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* (C) Copyright IBM Corp. 2023.
2+
* (C) Copyright IBM Corp. 2021, 2022, 2023.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

examples/ibm-is-ng/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,20 @@ data "ibm_is_backup_policy_plan" "is_backup_policy_plan" {
11431143
name = "my-backup-policy-plan"
11441144
}
11451145

1146+
//backup policies for enterprise
1147+
1148+
resource "ibm_is_backup_policy" "ent-baas-example" {
1149+
match_user_tags = ["tag1"]
1150+
name = "example-enterprise-backup-policy"
1151+
scope {
1152+
crn = "crn:v1:bluemix:public:is:us-south:a/123456::reservation:7187-ba49df72-37b8-43ac-98da-f8e029de0e63"
1153+
}
1154+
}
1155+
1156+
data "ibm_is_backup_policy" "enterprise_backup" {
1157+
name = ibm_is_backup_policy.ent-baas-example.name
1158+
}
1159+
11461160
// Vpn Server
11471161
resource "ibm_is_vpn_server" "is_vpn_server" {
11481162
certificate_crn = var.is_certificate_crn

ibm/acctest/acctest.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ var (
6868
UpdatedCertCRN string
6969
SecretCRN string
7070
SecretCRN2 string
71+
EnterpriseCRN string
7172
InstanceCRN string
7273
SecretGroupID string
7374
RegionName string
@@ -1444,6 +1445,11 @@ func init() {
14441445
fmt.Println("[WARN] Set the environment variable IES_API_KEY for testing Event streams targets, the tests will fail if this is not set")
14451446
}
14461447

1448+
EnterpriseCRN = os.Getenv("ENTERPRISE_CRN")
1449+
if EnterpriseCRN == "" {
1450+
fmt.Println("[WARN] Set the environment variable ENTERPRISE_CRN for testing enterprise backup policy, the tests will fail if this is not set")
1451+
}
1452+
14471453
CeResourceGroupID = os.Getenv("IBM_CODE_ENGINE_RESOURCE_GROUP_ID")
14481454
if CeResourceGroupID == "" {
14491455
CeResourceGroupID = ""

ibm/service/vpc/data_source_ibm_is_backup_policies.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,59 @@ func DataSourceIBMIsBackupPolicies() *schema.Resource {
166166
Computed: true,
167167
Description: "The type of resource referenced.",
168168
},
169+
"health_reasons": {
170+
Type: schema.TypeList,
171+
Computed: true,
172+
Description: "The reasons for the current health_state (if any).",
173+
Elem: &schema.Resource{
174+
Schema: map[string]*schema.Schema{
175+
"code": {
176+
Type: schema.TypeString,
177+
Computed: true,
178+
Description: "A snake case string succinctly identifying the reason for this health state.",
179+
},
180+
"message": {
181+
Type: schema.TypeString,
182+
Computed: true,
183+
Description: "An explanation of the reason for this health state.",
184+
},
185+
"more_info": {
186+
Type: schema.TypeString,
187+
Computed: true,
188+
Description: "Link to documentation about the reason for this health state.",
189+
},
190+
},
191+
},
192+
},
193+
"health_state": &schema.Schema{
194+
Type: schema.TypeString,
195+
Computed: true,
196+
Description: "The health of this resource",
197+
},
198+
"scope": &schema.Schema{
199+
Type: schema.TypeList,
200+
Computed: true,
201+
Description: "The scope for this backup policy.",
202+
Elem: &schema.Resource{
203+
Schema: map[string]*schema.Schema{
204+
"crn": &schema.Schema{
205+
Type: schema.TypeString,
206+
Computed: true,
207+
Description: "The CRN for this enterprise.",
208+
},
209+
"id": &schema.Schema{
210+
Type: schema.TypeString,
211+
Computed: true,
212+
Description: "The unique identifier for this enterprise or account.",
213+
},
214+
"resource_type": &schema.Schema{
215+
Type: schema.TypeString,
216+
Computed: true,
217+
Description: "The resource type.",
218+
},
219+
},
220+
},
221+
},
169222
},
170223
},
171224
},
@@ -298,10 +351,58 @@ func dataSourceBackupPolicyCollectionBackupPoliciesToMap(backupPoliciesItem vpcv
298351
if backupPoliciesItem.ResourceType != nil {
299352
backupPoliciesMap["resource_type"] = backupPoliciesItem.ResourceType
300353
}
354+
if backupPoliciesItem.HealthReasons != nil {
355+
healthReasonsList := []map[string]interface{}{}
356+
for _, healthReasonsItem := range backupPoliciesItem.HealthReasons {
357+
healthReasonsList = append(healthReasonsList, dataSourceBackupPolicyCollectionPoliciesHealthReasonsToMap(healthReasonsItem))
358+
}
359+
backupPoliciesMap["health_reasons"] = healthReasonsList
360+
}
361+
if backupPoliciesItem.HealthState != nil {
362+
backupPoliciesMap["health_state"] = backupPoliciesItem.HealthState
363+
}
364+
if backupPoliciesItem.Scope != nil {
365+
scopeList := []map[string]interface{}{}
366+
scopeMap := dataSourceBackupPolicyCollectionBackupPoliciesScopeToMap(*backupPoliciesItem.Scope.(*vpcv1.BackupPolicyScope))
367+
scopeList = append(scopeList, scopeMap)
368+
backupPoliciesMap["scope"] = scopeList
369+
}
301370

302371
return backupPoliciesMap
303372
}
304373

374+
func dataSourceBackupPolicyCollectionPoliciesHealthReasonsToMap(statusReasonsItem vpcv1.BackupPolicyHealthReason) (healthReasonsMap map[string]interface{}) {
375+
healthReasonsMap = map[string]interface{}{}
376+
377+
if statusReasonsItem.Code != nil {
378+
healthReasonsMap["code"] = statusReasonsItem.Code
379+
}
380+
if statusReasonsItem.Message != nil {
381+
healthReasonsMap["message"] = statusReasonsItem.Message
382+
}
383+
if statusReasonsItem.MoreInfo != nil {
384+
healthReasonsMap["more_info"] = statusReasonsItem.MoreInfo
385+
}
386+
387+
return healthReasonsMap
388+
}
389+
390+
func dataSourceBackupPolicyCollectionBackupPoliciesScopeToMap(scopeItem vpcv1.BackupPolicyScope) (scopeMap map[string]interface{}) {
391+
scopeMap = map[string]interface{}{}
392+
393+
if scopeItem.CRN != nil {
394+
scopeMap["crn"] = scopeItem.CRN
395+
}
396+
if scopeItem.ID != nil {
397+
scopeMap["id"] = scopeItem.ID
398+
}
399+
if scopeItem.ResourceType != nil {
400+
scopeMap["resource_type"] = scopeItem.ResourceType
401+
}
402+
403+
return scopeMap
404+
}
405+
305406
func dataSourceBackupPolicyCollectionBackupPoliciesPlansToMap(plansItem vpcv1.BackupPolicyPlanReference) (plansMap map[string]interface{}) {
306407
plansMap = map[string]interface{}{}
307408

ibm/service/vpc/data_source_ibm_is_backup_policy.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,59 @@ func DataSourceIBMIsBackupPolicy() *schema.Resource {
149149
Computed: true,
150150
Description: "The type of resource referenced.",
151151
},
152+
"health_reasons": {
153+
Type: schema.TypeList,
154+
Computed: true,
155+
Description: "The reasons for the current health_state (if any).",
156+
Elem: &schema.Resource{
157+
Schema: map[string]*schema.Schema{
158+
"code": {
159+
Type: schema.TypeString,
160+
Computed: true,
161+
Description: "A snake case string succinctly identifying the reason for this health state.",
162+
},
163+
"message": {
164+
Type: schema.TypeString,
165+
Computed: true,
166+
Description: "An explanation of the reason for this health state.",
167+
},
168+
"more_info": {
169+
Type: schema.TypeString,
170+
Computed: true,
171+
Description: "Link to documentation about the reason for this health state.",
172+
},
173+
},
174+
},
175+
},
176+
"health_state": &schema.Schema{
177+
Type: schema.TypeString,
178+
Computed: true,
179+
Description: "The health of this resource",
180+
},
181+
"scope": &schema.Schema{
182+
Type: schema.TypeList,
183+
Computed: true,
184+
Description: "The scope for this backup policy.",
185+
Elem: &schema.Resource{
186+
Schema: map[string]*schema.Schema{
187+
"crn": &schema.Schema{
188+
Type: schema.TypeString,
189+
Computed: true,
190+
Description: "The CRN for this enterprise.",
191+
},
192+
"id": &schema.Schema{
193+
Type: schema.TypeString,
194+
Computed: true,
195+
Description: "The unique identifier for this enterprise or account.",
196+
},
197+
"resource_type": &schema.Schema{
198+
Type: schema.TypeString,
199+
Computed: true,
200+
Description: "The resource type.",
201+
},
202+
},
203+
},
204+
},
152205
},
153206
}
154207
}
@@ -237,6 +290,32 @@ func dataSourceIBMIsBackupPolicyRead(context context.Context, d *schema.Resource
237290
}
238291
}
239292

293+
if backupPolicy.HealthReasons != nil {
294+
healthReasonsList := make([]map[string]interface{}, 0)
295+
for _, sr := range backupPolicy.HealthReasons {
296+
currentSR := map[string]interface{}{}
297+
if sr.Code != nil && sr.Message != nil {
298+
currentSR["code"] = *sr.Code
299+
currentSR["message"] = *sr.Message
300+
if sr.MoreInfo != nil {
301+
currentSR["more_info"] = *sr.Message
302+
}
303+
healthReasonsList = append(healthReasonsList, currentSR)
304+
}
305+
}
306+
d.Set("health_reasons", healthReasonsList)
307+
}
308+
if err = d.Set("health_state", backupPolicy.HealthState); err != nil {
309+
return diag.FromErr(fmt.Errorf("[ERROR] Error setting health_state: %s", err))
310+
}
311+
312+
if backupPolicy.Scope != nil {
313+
err = d.Set("scope", dataSourceBackupPolicyFlattenScope(*backupPolicy.Scope.(*vpcv1.BackupPolicyScope)))
314+
if err != nil {
315+
return diag.FromErr(fmt.Errorf("[ERROR] Error setting scope: %s", err))
316+
}
317+
}
318+
240319
matchResourceType := make([]string, 0)
241320
if backupPolicy.MatchResourceTypes != nil {
242321
for _, matchResourceTyp := range backupPolicy.MatchResourceTypes {
@@ -266,6 +345,29 @@ func dataSourceIBMIsBackupPolicyRead(context context.Context, d *schema.Resource
266345
return nil
267346
}
268347

348+
func dataSourceBackupPolicyFlattenScope(result vpcv1.BackupPolicyScope) (finalList []map[string]interface{}) {
349+
finalList = []map[string]interface{}{}
350+
finalMap := dataSourceBackupPolicyScopeToMap(result)
351+
finalList = append(finalList, finalMap)
352+
353+
return finalList
354+
}
355+
func dataSourceBackupPolicyScopeToMap(scopeItem vpcv1.BackupPolicyScope) (scopeMap map[string]interface{}) {
356+
scopeMap = map[string]interface{}{}
357+
358+
if scopeItem.CRN != nil {
359+
scopeMap["crn"] = scopeItem.CRN
360+
}
361+
if scopeItem.ID != nil {
362+
scopeMap["id"] = scopeItem.ID
363+
}
364+
if scopeItem.ResourceType != nil {
365+
scopeMap["resource_type"] = scopeItem.ResourceType
366+
}
367+
368+
return scopeMap
369+
}
370+
269371
func dataSourceBackupPolicyFlattenPlans(result []vpcv1.BackupPolicyPlanReference) (plans []map[string]interface{}) {
270372
for _, plansItem := range result {
271373
plans = append(plans, dataSourceBackupPolicyPlansToMap(plansItem))

0 commit comments

Comments
 (0)