Skip to content

Commit

Permalink
support empty lists for CBR rule contexts and zone addresses (#5058)
Browse files Browse the repository at this point in the history
* support empty lists for CBR rule contexts and zone addresses

* update resource markdown
  • Loading branch information
mtbrandy authored Jan 30, 2024
1 parent b09f65d commit e332407
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
13 changes: 7 additions & 6 deletions ibm/service/contextbasedrestrictions/resource_ibm_cbr_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func ResourceIBMCbrRule() *schema.Resource {
},
"contexts": &schema.Schema{
Type: schema.TypeList,
Required: true,
Optional: true,
Description: "The contexts this rule applies to.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -122,6 +122,7 @@ func ResourceIBMCbrRule() *schema.Resource {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Description: "The operations this rule applies to.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -144,7 +145,7 @@ func ResourceIBMCbrRule() *schema.Resource {
"enforcement_mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Default: "enabled",
Computed: true,
ValidateFunc: validate.InvokeValidator("ibm_cbr_rule", "enforcement_mode"),
Description: "The rule enforcement mode: * `enabled` - The restrictions are enforced and reported. This is the default. * `disabled` - The restrictions are disabled. Nothing is enforced or reported. * `report` - The restrictions are evaluated and reported, but not enforced.",
},
Expand Down Expand Up @@ -252,8 +253,8 @@ func resourceIBMCbrRuleCreate(context context.Context, d *schema.ResourceData, m
if _, ok := d.GetOk("description"); ok {
createRuleOptions.SetDescription(d.Get("description").(string))
}
contexts := []contextbasedrestrictionsv1.RuleContext{}
if _, ok := d.GetOk("contexts"); ok {
var contexts []contextbasedrestrictionsv1.RuleContext
for _, e := range d.Get("contexts").([]interface{}) {
value := e.(map[string]interface{})
contextsItem, err := resourceIBMCbrRuleMapToRuleContext(value)
Expand All @@ -262,8 +263,8 @@ func resourceIBMCbrRuleCreate(context context.Context, d *schema.ResourceData, m
}
contexts = append(contexts, *contextsItem)
}
createRuleOptions.SetContexts(contexts)
}
createRuleOptions.SetContexts(contexts)
if _, ok := d.GetOk("resources"); ok {
var resources []contextbasedrestrictionsv1.Resource
for _, e := range d.Get("resources").([]interface{}) {
Expand Down Expand Up @@ -408,8 +409,8 @@ func resourceIBMCbrRuleUpdate(context context.Context, d *schema.ResourceData, m
if _, ok := d.GetOk("description"); ok {
replaceRuleOptions.SetDescription(d.Get("description").(string))
}
contexts := []contextbasedrestrictionsv1.RuleContext{}
if _, ok := d.GetOk("contexts"); ok {
var contexts []contextbasedrestrictionsv1.RuleContext
for _, e := range d.Get("contexts").([]interface{}) {
value := e.(map[string]interface{})
contextsItem, err := resourceIBMCbrRuleMapToRuleContext(value)
Expand All @@ -418,8 +419,8 @@ func resourceIBMCbrRuleUpdate(context context.Context, d *schema.ResourceData, m
}
contexts = append(contexts, *contextsItem)
}
replaceRuleOptions.SetContexts(contexts)
}
replaceRuleOptions.SetContexts(contexts)
if _, ok := d.GetOk("resources"); ok {
var resources []contextbasedrestrictionsv1.Resource
for _, e := range d.Get("resources").([]interface{}) {
Expand Down
10 changes: 5 additions & 5 deletions ibm/service/contextbasedrestrictions/resource_ibm_cbr_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ResourceIBMCbrZone() *schema.Resource {
},
"addresses": &schema.Schema{
Type: schema.TypeList,
Required: true,
Optional: true,
Description: "The list of addresses in the zone.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -249,8 +249,8 @@ func resourceIBMCbrZoneCreate(context context.Context, d *schema.ResourceData, m
if _, ok := d.GetOk("description"); ok {
createZoneOptions.SetDescription(d.Get("description").(string))
}
addresses := []contextbasedrestrictionsv1.AddressIntf{}
if _, ok := d.GetOk("addresses"); ok {
var addresses []contextbasedrestrictionsv1.AddressIntf
for _, e := range d.Get("addresses").([]interface{}) {
value := e.(map[string]interface{})
addressesItem, err := resourceIBMCbrZoneMapToAddress(value)
Expand All @@ -259,8 +259,8 @@ func resourceIBMCbrZoneCreate(context context.Context, d *schema.ResourceData, m
}
addresses = append(addresses, addressesItem)
}
createZoneOptions.SetAddresses(addresses)
}
createZoneOptions.SetAddresses(addresses)
if _, ok := d.GetOk("excluded"); ok {
var excluded []contextbasedrestrictionsv1.AddressIntf
for _, e := range d.Get("excluded").([]interface{}) {
Expand Down Expand Up @@ -401,8 +401,8 @@ func resourceIBMCbrZoneUpdate(context context.Context, d *schema.ResourceData, m
if _, ok := d.GetOk("description"); ok {
replaceZoneOptions.SetDescription(d.Get("description").(string))
}
addresses := []contextbasedrestrictionsv1.AddressIntf{}
if _, ok := d.GetOk("addresses"); ok {
var addresses []contextbasedrestrictionsv1.AddressIntf
for _, e := range d.Get("addresses").([]interface{}) {
value := e.(map[string]interface{})
addressesItem, err := resourceIBMCbrZoneMapToAddress(value)
Expand All @@ -411,8 +411,8 @@ func resourceIBMCbrZoneUpdate(context context.Context, d *schema.ResourceData, m
}
addresses = append(addresses, addressesItem)
}
replaceZoneOptions.SetAddresses(addresses)
}
replaceZoneOptions.SetAddresses(addresses)
if _, ok := d.GetOk("excluded"); ok {
var excluded []contextbasedrestrictionsv1.AddressIntf
for _, e := range d.Get("excluded").([]interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/cbr_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ In addition to all argument references listed, you can access the following attr

* `id` - The unique identifier of the cbr_rule.
* `contexts` - (List) The contexts this rule applies to.
* Constraints: The maximum length is `1000` items. The minimum length is `1` item.
* Constraints: The maximum length is `1000` items. The minimum length is `0` items.
Nested scheme for **contexts**:
* `attributes` - (List) The attributes.
* Constraints: The minimum length is `1` item.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/d/cbr_zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ In addition to all argument references listed, you can access the following attr
* `address_count` - (Integer) The number of addresses in the zone.

* `addresses` - (List) The list of addresses in the zone.
* Constraints: The maximum length is `1000` items. The minimum length is `1` item.
* Constraints: The maximum length is `1000` items. The minimum length is `0` items.
Nested scheme for **addresses**:
* `ref` - (List) A service reference value.
Nested scheme for **ref**:
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/cbr_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ resource "ibm_cbr_rule" "cbr_rule" {
Review the argument reference that you can specify for your resource.

* `contexts` - (Optional, List) The contexts this rule applies to.
* Constraints: The maximum length is `1000` items. The minimum length is `1` item.
* Constraints: The maximum length is `1000` items. The minimum length is `0` items.
Nested scheme for **contexts**:
* `attributes` - (Required, List) The attributes.
* Constraints: The minimum length is `1` item.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/cbr_zone.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Review the argument reference that you can specify for your resource.
* `account_id` - (Optional, String) The id of the account owning this zone.
* Constraints: The maximum length is `128` characters. The minimum length is `1` character. The value must match regular expression `/^[a-zA-Z0-9\-]+$/`.
* `addresses` - (Optional, List) The list of addresses in the zone.
* Constraints: The maximum length is `1000` items. The minimum length is `1` item.
* Constraints: The maximum length is `1000` items. The minimum length is `0` items.
Nested scheme for **addresses**:
* `ref` - (Optional, List) A service reference value.
Nested scheme for **ref**:
Expand Down

0 comments on commit e332407

Please sign in to comment.