Skip to content

Commit

Permalink
Add check for google_compute_router bgp.advertise_mode. (#3144) (#5718)
Browse files Browse the repository at this point in the history
* Add check for google_compute_router bgp.advertise_mode.

* Update templates/terraform/constants/router.go.erb

Co-Authored-By: Dana Hoffman <[email protected]>

Co-authored-by: Dana Hoffman <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Co-authored-by: Dana Hoffman <[email protected]>
  • Loading branch information
modular-magician and danawillow authored Feb 19, 2020
1 parent 72542de commit 3446165
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/3144.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added check on `google_compute_router` for non-empty advertised_groups or advertised_ip_ranges values when advertise_mode is DEFAULT in the bgp block.
```
20 changes: 20 additions & 0 deletions google/resource_compute_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
)

// customizeDiff func for additional checks on google_compute_router properties:
func resourceComputeRouterCustomDiff(diff *schema.ResourceDiff, meta interface{}) error {

block := diff.Get("bgp.0").(map[string]interface{})
advertiseMode := block["advertise_mode"]
advertisedGroups := block["advertised_groups"].([]interface{})
advertisedIPRanges := block["advertised_ip_ranges"].([]interface{})

if advertiseMode == "DEFAULT" && len(advertisedGroups) != 0 {
return fmt.Errorf("Error in bgp: advertised_groups cannot be specified when using advertise_mode DEFAULT")
}
if advertiseMode == "DEFAULT" && len(advertisedIPRanges) != 0 {
return fmt.Errorf("Error in bgp: advertised_ip_ranges cannot be specified when using advertise_mode DEFAULT")
}

return nil
}

func resourceComputeRouter() *schema.Resource {
return &schema.Resource{
Create: resourceComputeRouterCreate,
Expand All @@ -42,6 +60,8 @@ func resourceComputeRouter() *schema.Resource {
Delete: schema.DefaultTimeout(4 * time.Minute),
},

CustomizeDiff: resourceComputeRouterCustomDiff,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down

0 comments on commit 3446165

Please sign in to comment.