Skip to content

Commit

Permalink
fix(partner center sell): fix patch nested fields (#5785)
Browse files Browse the repository at this point in the history
* fix(partner center sell): fix patch nested fields

Signed-off-by: Peter Harasztia <[email protected]>

* fix(partner center sell): fix composite children

Signed-off-by: Peter Harasztia <[email protected]>

* fix(partner center sell): fix nil checks

Signed-off-by: Peter Harasztia <[email protected]>

---------

Signed-off-by: Peter Harasztia <[email protected]>
  • Loading branch information
HarasztiaPeter authored Nov 14, 2024
1 parent ec49311 commit 89a24e6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ func ResourceIbmOnboardingCatalogDeploymentMapToGlobalCatalogDeploymentMetadata(
}
model.Service = ServiceModel
}
if modelMap["deployment"] != nil && len(modelMap["deployment"].([]interface{})) > 0 {
if modelMap["deployment"] != nil && len(modelMap["deployment"].([]interface{})) > 0 && modelMap["deployment"].([]interface{})[0] != nil {
DeploymentModel, err := ResourceIbmOnboardingCatalogDeploymentMapToGlobalCatalogMetadataDeployment(modelMap["deployment"].([]interface{})[0].(map[string]interface{}))
if err != nil {
return model, err
Expand Down Expand Up @@ -1021,7 +1021,7 @@ func ResourceIbmOnboardingCatalogDeploymentMapToGlobalCatalogMetadataService(mod

func ResourceIbmOnboardingCatalogDeploymentMapToGlobalCatalogMetadataDeployment(modelMap map[string]interface{}) (*partnercentersellv1.GlobalCatalogMetadataDeployment, error) {
model := &partnercentersellv1.GlobalCatalogMetadataDeployment{}
if modelMap["broker"] != nil && len(modelMap["broker"].([]interface{})) > 0 {
if modelMap["broker"] != nil && len(modelMap["broker"].([]interface{})) > 0 && modelMap["broker"].([]interface{})[0] != nil {
BrokerModel, err := ResourceIbmOnboardingCatalogDeploymentMapToGlobalCatalogMetadataDeploymentBroker(modelMap["broker"].([]interface{})[0].(map[string]interface{}))
if err != nil {
return model, err
Expand Down Expand Up @@ -1507,13 +1507,13 @@ func ResourceIbmOnboardingCatalogDeploymentGlobalCatalogMetadataUIStringsContent
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["bullets"] = nil
} else if exists && patch["bullets"] != nil {
ResourceIbmOnboardingCatalogDeploymentCatalogHighlightItemAsPatch(patch["bullets"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingCatalogDeploymentCatalogHighlightItemAsPatch(patch["bullets"].([]map[string]interface{})[0], d)
}
path = "metadata.0.ui.0.strings.0.en.0.media"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["media"] = nil
} else if exists && patch["media"] != nil {
ResourceIbmOnboardingCatalogDeploymentCatalogProductMediaItemAsPatch(patch["media"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingCatalogDeploymentCatalogProductMediaItemAsPatch(patch["media"].([]map[string]interface{})[0], d)
}
path = "metadata.0.ui.0.strings.0.en.0.embeddable_dashboard"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ func ResourceIbmOnboardingCatalogPlanMapToGlobalCatalogPlanMetadata(modelMap map
}
model.Pricing = PricingModel
}
if modelMap["plan"] != nil && len(modelMap["plan"].([]interface{})) > 0 {
if modelMap["plan"] != nil && len(modelMap["plan"].([]interface{})) > 0 && modelMap["plan"].([]interface{})[0] != nil {
PlanModel, err := ResourceIbmOnboardingCatalogPlanMapToGlobalCatalogPlanMetadataPlan(modelMap["plan"].([]interface{})[0].(map[string]interface{}))
if err != nil {
return model, err
Expand Down Expand Up @@ -1458,13 +1458,13 @@ func ResourceIbmOnboardingCatalogPlanGlobalCatalogMetadataUIStringsContentAsPatc
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["bullets"] = nil
} else if exists && patch["bullets"] != nil {
ResourceIbmOnboardingCatalogPlanCatalogHighlightItemAsPatch(patch["bullets"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingCatalogPlanCatalogHighlightItemAsPatch(patch["bullets"].([]map[string]interface{})[0], d)
}
path = "metadata.0.ui.0.strings.0.en.0.media"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["media"] = nil
} else if exists && patch["media"] != nil {
ResourceIbmOnboardingCatalogPlanCatalogProductMediaItemAsPatch(patch["media"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingCatalogPlanCatalogProductMediaItemAsPatch(patch["media"].([]map[string]interface{})[0], d)
}
path = "metadata.0.ui.0.strings.0.en.0.embeddable_dashboard"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ func ResourceIbmOnboardingCatalogProductMapToGlobalCatalogProductMetadataOther(m
}
model.PC = PCModel
}
if modelMap["composite"] != nil && len(modelMap["composite"].([]interface{})) > 0 {
if modelMap["composite"] != nil && len(modelMap["composite"].([]interface{})) > 0 && modelMap["composite"].([]interface{})[0] != nil {
CompositeModel, err := ResourceIbmOnboardingCatalogProductMapToGlobalCatalogProductMetadataOtherComposite(modelMap["composite"].([]interface{})[0].(map[string]interface{}))
if err != nil {
return model, err
Expand Down Expand Up @@ -1955,7 +1955,7 @@ func ResourceIbmOnboardingCatalogProductGlobalCatalogProductMetadataOtherComposi
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["children"] = nil
} else if exists && patch["children"] != nil {
ResourceIbmOnboardingCatalogProductGlobalCatalogProductMetadataOtherCompositeChildAsPatch(patch["children"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingCatalogProductGlobalCatalogProductMetadataOtherCompositeChildAsPatch(patch["children"].([]map[string]interface{})[0], d)
}
}

Expand Down Expand Up @@ -2024,7 +2024,7 @@ func ResourceIbmOnboardingCatalogProductGlobalCatalogProductMetadataOtherPCSuppo
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["support_details"] = nil
} else if exists && patch["support_details"] != nil {
ResourceIbmOnboardingCatalogProductSupportDetailsItemAsPatch(patch["support_details"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingCatalogProductSupportDetailsItemAsPatch(patch["support_details"].([]map[string]interface{})[0], d)
}
}

Expand Down Expand Up @@ -2060,7 +2060,7 @@ func ResourceIbmOnboardingCatalogProductSupportDetailsItemAvailabilityAsPatch(pa
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["times"] = nil
} else if exists && patch["times"] != nil {
ResourceIbmOnboardingCatalogProductSupportDetailsItemAvailabilityTimeAsPatch(patch["times"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingCatalogProductSupportDetailsItemAvailabilityTimeAsPatch(patch["times"].([]map[string]interface{})[0], d)
}
path = "metadata.0.other.0.pc.0.support.0.support_details.0.availability.0.timezone"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
Expand Down Expand Up @@ -2222,13 +2222,13 @@ func ResourceIbmOnboardingCatalogProductGlobalCatalogMetadataUIStringsContentAsP
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["bullets"] = nil
} else if exists && patch["bullets"] != nil {
ResourceIbmOnboardingCatalogProductCatalogHighlightItemAsPatch(patch["bullets"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingCatalogProductCatalogHighlightItemAsPatch(patch["bullets"].([]map[string]interface{})[0], d)
}
path = "metadata.0.ui.0.strings.0.en.0.media"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["media"] = nil
} else if exists && patch["media"] != nil {
ResourceIbmOnboardingCatalogProductCatalogProductMediaItemAsPatch(patch["media"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingCatalogProductCatalogProductMediaItemAsPatch(patch["media"].([]map[string]interface{})[0], d)
}
path = "metadata.0.ui.0.strings.0.en.0.embeddable_dashboard"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2527,7 +2527,7 @@ func ResourceIbmOnboardingIamRegistrationIamServiceRegistrationPatchAsPatch(patc
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["actions"] = nil
} else if exists && patch["actions"] != nil {
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationActionAsPatch(patch["actions"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationActionAsPatch(patch["actions"].([]map[string]interface{})[0], d)
}
path = "additional_policy_scopes"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
Expand All @@ -2551,25 +2551,25 @@ func ResourceIbmOnboardingIamRegistrationIamServiceRegistrationPatchAsPatch(patc
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["supported_anonymous_accesses"] = nil
} else if exists && patch["supported_anonymous_accesses"] != nil {
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationSupportedAnonymousAccessAsPatch(patch["supported_anonymous_accesses"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationSupportedAnonymousAccessAsPatch(patch["supported_anonymous_accesses"].([]map[string]interface{})[0], d)
}
path = "supported_attributes"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["supported_attributes"] = nil
} else if exists && patch["supported_attributes"] != nil {
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationSupportedAttributeAsPatch(patch["supported_attributes"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationSupportedAttributeAsPatch(patch["supported_attributes"].([]map[string]interface{})[0], d)
}
path = "supported_authorization_subjects"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["supported_authorization_subjects"] = nil
} else if exists && patch["supported_authorization_subjects"] != nil {
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationSupportedAuthorizationSubjectAsPatch(patch["supported_authorization_subjects"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationSupportedAuthorizationSubjectAsPatch(patch["supported_authorization_subjects"].([]map[string]interface{})[0], d)
}
path = "supported_roles"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["supported_roles"] = nil
} else if exists && patch["supported_roles"] != nil {
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationSupportedRoleAsPatch(patch["supported_roles"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingIamRegistrationIamServiceRegistrationSupportedRoleAsPatch(patch["supported_roles"].([]map[string]interface{})[0], d)
}
path = "supported_network"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
Expand All @@ -2588,7 +2588,7 @@ func ResourceIbmOnboardingIamRegistrationIamServiceRegistrationSupportedNetworkA
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["environment_attributes"] = nil
} else if exists && patch["environment_attributes"] != nil {
ResourceIbmOnboardingIamRegistrationEnvironmentAttributeAsPatch(patch["environment_attributes"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingIamRegistrationEnvironmentAttributeAsPatch(patch["environment_attributes"].([]map[string]interface{})[0], d)
}
}

Expand Down Expand Up @@ -2747,7 +2747,7 @@ func ResourceIbmOnboardingIamRegistrationSupportedAttributeUiInputDetailsAsPatch
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["values"] = nil
} else if exists && patch["values"] != nil {
ResourceIbmOnboardingIamRegistrationSupportedAttributeUiInputValueAsPatch(patch["values"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingIamRegistrationSupportedAttributeUiInputValueAsPatch(patch["values"].([]map[string]interface{})[0], d)
}
path = "supported_attributes.0.ui.0.input_details.0.gst"
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestAccIbmOnboardingIamRegistrationAllArgs(t *testing.T) {
enabled := "true"
serviceType := "platform_service"
envUpdate := "current"
roleDisplayNameUpdate := fmt.Sprintf("random-%d", acctest.RandIntRange(10, 100))
nameUpdate := acc.PcsIamServiceRegistrationId
enabledUpdate := "true"
serviceTypeUpdate := "service"
Expand All @@ -72,7 +73,7 @@ func TestAccIbmOnboardingIamRegistrationAllArgs(t *testing.T) {
),
},
resource.TestStep{
Config: testAccCheckIbmOnboardingIamRegistrationConfig(productID, envUpdate, nameUpdate, enabledUpdate, serviceTypeUpdate, iamRegistrationRole, roleDisplayName, acc.PcsIamServiceRegistrationId),
Config: testAccCheckIbmOnboardingIamRegistrationConfig(productID, envUpdate, nameUpdate, enabledUpdate, serviceTypeUpdate, iamRegistrationRole, roleDisplayNameUpdate, acc.PcsIamServiceRegistrationId),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("ibm_onboarding_iam_registration.onboarding_iam_registration_instance", "product_id", productID),
resource.TestCheckResourceAttr("ibm_onboarding_iam_registration.onboarding_iam_registration_instance", "env", envUpdate),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ func ResourceIbmOnboardingProductOnboardingProductSupportAsPatch(patch map[strin
if _, exists := d.GetOk(path); d.HasChange(path) && !exists {
patch["escalation_contacts"] = nil
} else if exists && patch["escalation_contacts"] != nil {
ResourceIbmOnboardingProductOnboardingProductSupportEscalationContactItemsAsPatch(patch["escalation_contacts"].([]interface{})[0].(map[string]interface{}), d)
ResourceIbmOnboardingProductOnboardingProductSupportEscalationContactItemsAsPatch(patch["escalation_contacts"].([]map[string]interface{})[0], d)
}
}

Expand Down

0 comments on commit 89a24e6

Please sign in to comment.