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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CBR regenerate provider #5724

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

zhenwan
Copy link
Contributor

@zhenwan zhenwan commented Oct 14, 2024

Per request from https://ibm-cloudplatform.slack.com/archives/C05CL2TVBC6/p1712696668957339

Acceptance Tests:

=== RUN   TestAccIBMCbrRuleDataSourceBasic
--- PASS: TestAccIBMCbrRuleDataSourceBasic (15.30s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        17.060s
=== RUN   TestAccIBMCbrRuleDataSourceAllArgs
--- PASS: TestAccIBMCbrRuleDataSourceAllArgs (14.56s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        16.372s
=== RUN   TestAccIBMCbrZoneAddressesDataSourceBasic
--- PASS: TestAccIBMCbrZoneAddressesDataSourceBasic (14.24s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        16.019s

=== RUN   TestAccIBMCbrZoneAddressesDataSourceMultiple
--- PASS: TestAccIBMCbrZoneAddressesDataSourceMultiple (16.91s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        18.723s
=== RUN   TestAccIBMCbrZoneDataSourceBasic
--- PASS: TestAccIBMCbrZoneDataSourceBasic (16.08s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        (cached)
=== RUN   TestAccIBMCbrRuleBasic
--- PASS: TestAccIBMCbrRuleBasic (12.66s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        14.449s
=== RUN   TestAccIBMCbrRuleAllArgs
--- PASS: TestAccIBMCbrRuleAllArgs (28.25s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        30.003s
=== RUN   TestAccIBMCbrZoneAddressesBasic
--- PASS: TestAccIBMCbrZoneAddressesBasic (34.39s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        36.193s
=== RUN   TestAccIBMCbrZoneAddressesUpdate
--- PASS: TestAccIBMCbrZoneAddressesUpdate (48.98s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        50.796s
=== RUN   TestAccIBMCbrZoneBasic
--- PASS: TestAccIBMCbrZoneBasic (14.40s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        16.186s
=== RUN   TestAccIBMCbrZoneAllArgs
--- PASS: TestAccIBMCbrZoneAllArgs (24.97s)
PASS
ok      github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/contextbasedrestrictions        26.747s

Copy link
Contributor

@mtbrandy mtbrandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial feedback.

}

d.SetId(fmt.Sprintf("%s", *getRuleOptions.RuleID))

if err = d.Set("crn", rule.CRN); err != nil {
return diag.FromErr(fmt.Errorf("Error setting crn: %s", err))
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting crn: %s", err), "(Data) ibm_cbr_rule", "read", "set-crn").GetDiag()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not log the debug message for this error? What determines when a debug message is logged vs when it is not?

This comment/question applies to everywhere you construct a TerraformProblem and had to decide whether or not to log the value of GetDebugMessage().

}

var zone *contextbasedrestrictionsv1.Zone
var found bool
zone, _, found, err = getZone(contextBasedRestrictionsClient, context, zoneId)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("getZone failed: %s", err.Error()), "(Data) ibm_cbr_zone_addresses", "read")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels wrong to include the local function (getZone) in the error message.

@@ -152,7 +153,9 @@ func resourceIBMCbrZoneAddressesCreate(context context.Context, d *schema.Resour
addressesId := fmt.Sprintf("TF-%s", newUuid)
err := resourceReplaceZoneAddresses(context, d, meta, zoneId, addressesId, false)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf(" resourceReplaceZoneAddresses failed: %s", err.Error()), "ibm_cbr_zone_addresses", "create")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels wrong to include the local function (resourceReplaceZoneAddresses) in the error message.

@@ -171,29 +176,31 @@ func resourceIBMCbrZoneAddressesRead(context context.Context, d *schema.Resource
var found bool
zone, _, found, err = getZone(contextBasedRestrictionsClient, context, zoneId)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("getZone failed: %s", err.Error()), "ibm_cbr_zone_addresses", "read")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels wrong to include the local function (getZone) in the error message.

@@ -203,7 +210,9 @@ func resourceIBMCbrZoneAddressesUpdate(context context.Context, d *schema.Resour
zoneId, addressesId := decomposeZoneAddressesId(d.Id())
err := resourceReplaceZoneAddresses(context, d, meta, zoneId, addressesId, false)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceReplaceZoneAddresses failed: %s", err.Error()), "ibm_cbr_zone_addresses", "update")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels wrong to include the local function (resourceReplaceZoneAddresses) in the error message.

}
contexts = append(contexts, *contextsItem)
}
replaceRuleOptions.SetContexts(contexts)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change? The API won't accept a zone create with missing contexts. The previous code ensured that it is present (and empty) if no contexts are specified.

}

zone, response, found, err := getZone(contextBasedRestrictionsClient, context, d.Id())
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("getZone failed: %s", err.Error()), "ibm_cbr_zone", "read")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels wrong to include the local function (getZone) in the error message.

@@ -412,7 +364,9 @@ func resourceIBMCbrZoneUpdate(context context.Context, d *schema.ResourceData, m

currentZone, response, found, err := getZone(contextBasedRestrictionsClient, context, zoneId)
if err != nil {
return diag.FromErr(err)
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("getZone failed: %s", err.Error()), "ibm_cbr_zone", "update")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels wrong to include the local function (getZone) in the error message.

}

if err := ResourceIBMCbrZoneSetData(zone, response, d); err != nil {
return diag.FromErr(fmt.Errorf("Error setting zone's resource data: %s", err))
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_cbr_zone", "read", "ResourceIBMCbrZoneSetData").GetDiag()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be "update"

if err = d.Set("etag", response.Headers.Get("Etag")); err != nil {
return fmt.Errorf("Error setting etag: %s", err)
}
if err = d.Set("etag", response.Headers.Get("Etag")); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"etag" is set twice here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants