Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ebaas) enterprise BaaS #4845

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/github.com/IBM/vpc-go-sdk/vpcv1/vpc_v1.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* (C) Copyright IBM Corp. 2023.
* (C) Copyright IBM Corp. 2021, 2022, 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
14 changes: 14 additions & 0 deletions examples/ibm-is-ng/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,20 @@ data "ibm_is_backup_policy_plan" "is_backup_policy_plan" {
name = "my-backup-policy-plan"
}

//backup policies for enterprise

resource "ibm_is_backup_policy" "ent-baas-example" {
match_user_tags = ["tag1"]
name = "example-enterprise-backup-policy"
scope {
crn = "crn:v1:bluemix:public:is:us-south:a/123456::reservation:7187-ba49df72-37b8-43ac-98da-f8e029de0e63"
}
}

data "ibm_is_backup_policy" "enterprise_backup" {
name = ibm_is_backup_policy.ent-baas-example.name
}

// Vpn Server
resource "ibm_is_vpn_server" "is_vpn_server" {
certificate_crn = var.is_certificate_crn
Expand Down
6 changes: 6 additions & 0 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var (
UpdatedCertCRN string
SecretCRN string
SecretCRN2 string
EnterpriseCRN string
InstanceCRN string
SecretGroupID string
RegionName string
Expand Down Expand Up @@ -1444,6 +1445,11 @@ func init() {
fmt.Println("[WARN] Set the environment variable IES_API_KEY for testing Event streams targets, the tests will fail if this is not set")
}

EnterpriseCRN = os.Getenv("ENTERPRISE_CRN")
if EnterpriseCRN == "" {
fmt.Println("[WARN] Set the environment variable ENTERPRISE_CRN for testing enterprise backup policy, the tests will fail if this is not set")
}

CeResourceGroupID = os.Getenv("IBM_CODE_ENGINE_RESOURCE_GROUP_ID")
if CeResourceGroupID == "" {
CeResourceGroupID = ""
Expand Down
101 changes: 101 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_backup_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,59 @@ func DataSourceIBMIsBackupPolicies() *schema.Resource {
Computed: true,
Description: "The type of resource referenced.",
},
"health_reasons": {
Type: schema.TypeList,
Computed: true,
Description: "The reasons for the current health_state (if any).",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"code": {
Type: schema.TypeString,
Computed: true,
Description: "A snake case string succinctly identifying the reason for this health state.",
},
"message": {
Type: schema.TypeString,
Computed: true,
Description: "An explanation of the reason for this health state.",
},
"more_info": {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about the reason for this health state.",
},
},
},
},
"health_state": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The health of this resource",
},
"scope": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The scope for this backup policy.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this enterprise.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this enterprise or account.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -298,10 +351,58 @@ func dataSourceBackupPolicyCollectionBackupPoliciesToMap(backupPoliciesItem vpcv
if backupPoliciesItem.ResourceType != nil {
backupPoliciesMap["resource_type"] = backupPoliciesItem.ResourceType
}
if backupPoliciesItem.HealthReasons != nil {
healthReasonsList := []map[string]interface{}{}
for _, healthReasonsItem := range backupPoliciesItem.HealthReasons {
healthReasonsList = append(healthReasonsList, dataSourceBackupPolicyCollectionPoliciesHealthReasonsToMap(healthReasonsItem))
}
backupPoliciesMap["health_reasons"] = healthReasonsList
}
if backupPoliciesItem.HealthState != nil {
backupPoliciesMap["health_state"] = backupPoliciesItem.HealthState
}
if backupPoliciesItem.Scope != nil {
scopeList := []map[string]interface{}{}
scopeMap := dataSourceBackupPolicyCollectionBackupPoliciesScopeToMap(*backupPoliciesItem.Scope.(*vpcv1.BackupPolicyScope))
scopeList = append(scopeList, scopeMap)
backupPoliciesMap["scope"] = scopeList
}

return backupPoliciesMap
}

func dataSourceBackupPolicyCollectionPoliciesHealthReasonsToMap(statusReasonsItem vpcv1.BackupPolicyHealthReason) (healthReasonsMap map[string]interface{}) {
healthReasonsMap = map[string]interface{}{}

if statusReasonsItem.Code != nil {
healthReasonsMap["code"] = statusReasonsItem.Code
}
if statusReasonsItem.Message != nil {
healthReasonsMap["message"] = statusReasonsItem.Message
}
if statusReasonsItem.MoreInfo != nil {
healthReasonsMap["more_info"] = statusReasonsItem.MoreInfo
}

return healthReasonsMap
}

func dataSourceBackupPolicyCollectionBackupPoliciesScopeToMap(scopeItem vpcv1.BackupPolicyScope) (scopeMap map[string]interface{}) {
scopeMap = map[string]interface{}{}

if scopeItem.CRN != nil {
scopeMap["crn"] = scopeItem.CRN
}
if scopeItem.ID != nil {
scopeMap["id"] = scopeItem.ID
}
if scopeItem.ResourceType != nil {
scopeMap["resource_type"] = scopeItem.ResourceType
}

return scopeMap
}

func dataSourceBackupPolicyCollectionBackupPoliciesPlansToMap(plansItem vpcv1.BackupPolicyPlanReference) (plansMap map[string]interface{}) {
plansMap = map[string]interface{}{}

Expand Down
102 changes: 102 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_backup_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,59 @@ func DataSourceIBMIsBackupPolicy() *schema.Resource {
Computed: true,
Description: "The type of resource referenced.",
},
"health_reasons": {
Type: schema.TypeList,
Computed: true,
Description: "The reasons for the current health_state (if any).",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"code": {
Type: schema.TypeString,
Computed: true,
Description: "A snake case string succinctly identifying the reason for this health state.",
},
"message": {
Type: schema.TypeString,
Computed: true,
Description: "An explanation of the reason for this health state.",
},
"more_info": {
Type: schema.TypeString,
Computed: true,
Description: "Link to documentation about the reason for this health state.",
},
},
},
},
"health_state": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The health of this resource",
},
"scope": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The scope for this backup policy.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"crn": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The CRN for this enterprise.",
},
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The unique identifier for this enterprise or account.",
},
"resource_type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The resource type.",
},
},
},
},
},
}
}
Expand Down Expand Up @@ -237,6 +290,32 @@ func dataSourceIBMIsBackupPolicyRead(context context.Context, d *schema.Resource
}
}

if backupPolicy.HealthReasons != nil {
healthReasonsList := make([]map[string]interface{}, 0)
for _, sr := range backupPolicy.HealthReasons {
currentSR := map[string]interface{}{}
if sr.Code != nil && sr.Message != nil {
currentSR["code"] = *sr.Code
currentSR["message"] = *sr.Message
if sr.MoreInfo != nil {
currentSR["more_info"] = *sr.Message
}
healthReasonsList = append(healthReasonsList, currentSR)
}
}
d.Set("health_reasons", healthReasonsList)
}
if err = d.Set("health_state", backupPolicy.HealthState); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting health_state: %s", err))
}

if backupPolicy.Scope != nil {
err = d.Set("scope", dataSourceBackupPolicyFlattenScope(*backupPolicy.Scope.(*vpcv1.BackupPolicyScope)))
if err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error setting scope: %s", err))
}
}

matchResourceType := make([]string, 0)
if backupPolicy.MatchResourceTypes != nil {
for _, matchResourceTyp := range backupPolicy.MatchResourceTypes {
Expand Down Expand Up @@ -266,6 +345,29 @@ func dataSourceIBMIsBackupPolicyRead(context context.Context, d *schema.Resource
return nil
}

func dataSourceBackupPolicyFlattenScope(result vpcv1.BackupPolicyScope) (finalList []map[string]interface{}) {
finalList = []map[string]interface{}{}
finalMap := dataSourceBackupPolicyScopeToMap(result)
finalList = append(finalList, finalMap)

return finalList
}
func dataSourceBackupPolicyScopeToMap(scopeItem vpcv1.BackupPolicyScope) (scopeMap map[string]interface{}) {
scopeMap = map[string]interface{}{}

if scopeItem.CRN != nil {
scopeMap["crn"] = scopeItem.CRN
}
if scopeItem.ID != nil {
scopeMap["id"] = scopeItem.ID
}
if scopeItem.ResourceType != nil {
scopeMap["resource_type"] = scopeItem.ResourceType
}

return scopeMap
}

func dataSourceBackupPolicyFlattenPlans(result []vpcv1.BackupPolicyPlanReference) (plans []map[string]interface{}) {
for _, plansItem := range result {
plans = append(plans, dataSourceBackupPolicyPlansToMap(plansItem))
Expand Down