Skip to content

Commit

Permalink
Fix: required ip when location vpn creds type is IP & stop unnecessar…
Browse files Browse the repository at this point in the history
…y resource updates
  • Loading branch information
amazzalel-habib committed Dec 10, 2021
1 parent 589469f commit 5f0d608
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
3 changes: 1 addition & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ else
build13: DESTINATION=$(HOME)/.terraform.d/plugins/$(ZIA_PROVIDER_NAMESPACE)/1.0.2/$(GOOS)_$(GOARCH)
endif
build13: fmtcheck
go mod vendor
go mod tidy
go mod tidy && go mod vendor
@echo "==> Installing plugin to $(DESTINATION)"
@mkdir -p $(DESTINATION)
go build -o $(DESTINATION)/terraform-provider-zia_v1.0.2
Expand Down
8 changes: 4 additions & 4 deletions gozscaler/trafficforwarding/vpncredentials/vpncredentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const (
type VPNCredentials struct {
ID int `json:"id"`
Type string `json:"type,omitempty"`
FQDN string `json:"fqdn"`
IPAddress string `json:"ipAddress"`
FQDN string `json:"fqdn,omitempty"`
IPAddress string `json:"ipAddress,omitempty"`
PreSharedKey string `json:"preSharedKey,omitempty"`
Comments string `json:"comments,omitempty"`
Location *Location `json:"location"`
ManagedBy *ManagedBy `json:"managedBy"`
Location *Location `json:"location,omitempty"`
ManagedBy *ManagedBy `json:"managedBy,omitempty"`
}
type Location struct {
ID int `json:"id"`
Expand Down
19 changes: 16 additions & 3 deletions zia/resource_zia_location_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ func resourceLocationManagement() *schema.Resource {
"id": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
},
"type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{
"IP",
"UFQDN",
Expand All @@ -94,10 +95,12 @@ func resourceLocationManagement() *schema.Resource {
"fqdn": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"ip_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.IsIPAddress,
},
"pre_shared_key": {
Expand Down Expand Up @@ -261,6 +264,9 @@ func resourceLocationManagementCreate(d *schema.ResourceData, m interface{}) err
if err := checkSurrogateIPDependencies(req); err != nil {
return err
}
if err := checkVPNCredentials(req); err != nil {
return err
}
resp, err := zClient.locationmanagement.Create(&req)
if err != nil {
return err
Expand All @@ -271,7 +277,14 @@ func resourceLocationManagementCreate(d *schema.ResourceData, m interface{}) err

return resourceLocationManagementRead(d, m)
}

func checkVPNCredentials(locations locationmanagement.Locations) error {
for _, vpn := range locations.VPNCredentials {
if vpn.Type == "IP" && vpn.IPAddress == "" {
return fmt.Errorf("ip_address is required when VPN credential is of type IP in: %d", vpn.ID)
}
}
return nil
}
func checkSurrogateIPDependencies(loc locationmanagement.Locations) error {
if loc.SurrogateIP && loc.IdleTimeInMinutes == 0 {
return fmt.Errorf("surrogate IP requires setting of an idle timeout")
Expand Down Expand Up @@ -460,11 +473,11 @@ func expandLocationManagementVPNCredentials(d *schema.ResourceData) []locationma
ID: vpnItem["id"].(int),
Type: vpnItem["type"].(string),
FQDN: vpnItem["fqdn"].(string),
IPAddress: vpnItem["ip_address"].(string),
PreSharedKey: vpnItem["pre_shared_key"].(string),
Comments: vpnItem["comments"].(string),
}
}
}

return vpnCredentials
}
2 changes: 2 additions & 0 deletions zia/resource_zia_traffic_forwarding_static_ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ func resourceTrafficForwardingStaticIP() *schema.Resource {
"latitude": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
ValidateFunc: validation.FloatBetween(-90, 90),
Description: "Required only if the geoOverride attribute is set. Latitude with 7 digit precision after decimal point, ranges between -90 and 90 degrees.",
},
"longitude": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
ValidateFunc: validation.FloatBetween(-180, 180),
Description: "Required only if the geoOverride attribute is set. Longitude with 7 digit precision after decimal point, ranges between -180 and 180 degrees.",
},
Expand Down
1 change: 0 additions & 1 deletion zia/resource_zia_traffic_forwarding_vpn_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func resourceTrafficForwardingVPNCredentialsRead(d *schema.ResourceData, m inter
_ = d.Set("type", resp.Type)
_ = d.Set("fqdn", resp.FQDN)
_ = d.Set("ip_address", resp.IPAddress)
_ = d.Set("pre_shared_key", resp.PreSharedKey)
_ = d.Set("comments", resp.Comments)

return nil
Expand Down

0 comments on commit 5f0d608

Please sign in to comment.