Skip to content

Commit

Permalink
Adds missing gateway egress rule settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Borkenstein committed Jan 17, 2023
1 parent 3e3c8ed commit 851b2f4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/2159.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_teams_rules: adds egress rule settings.
```
30 changes: 30 additions & 0 deletions internal/provider/resource_cloudflare_teams_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func flattenTeamsRuleSettings(settings *cloudflare.TeamsRuleSettings) []interfac
"check_session": flattenTeamsCheckSessionSettings(settings.CheckSession),
"add_headers": flattenTeamsAddHeaders(settings.AddHeaders),
"insecure_disable_dnssec_validation": settings.InsecureDisableDNSSECValidation,
"egress": flattenTeamsEgressSettings(settings.EgressSettings),
}}
}

Expand All @@ -230,6 +231,7 @@ func inflateTeamsRuleSettings(settings interface{}) *cloudflare.TeamsRuleSetting
checkSessionSettings := inflateTeamsCheckSessionSettings(settingsMap["check_session"].([]interface{}))
addHeaders := inflateTeamsAddHeaders(settingsMap["add_headers"].(map[string]interface{}))
insecureDisableDNSSECValidation := settingsMap["insecure_disable_dnssec_validation"].(bool)
egressSettings := inflateTeamsEgressSettings(settingsMap["egress"].([]interface{}))

return &cloudflare.TeamsRuleSettings{
BlockPageEnabled: enabled,
Expand All @@ -241,6 +243,7 @@ func inflateTeamsRuleSettings(settings interface{}) *cloudflare.TeamsRuleSetting
CheckSession: checkSessionSettings,
AddHeaders: addHeaders,
InsecureDisableDNSSECValidation: insecureDisableDNSSECValidation,
EgressSettings: egressSettings,
}
}

Expand Down Expand Up @@ -363,6 +366,33 @@ func inflateTeamsL4Override(settings interface{}) *cloudflare.TeamsL4OverrideSet
}
}

func flattenTeamsEgressSettings(settings *cloudflare.EgressSettings) []interface{} {
if settings == nil {
return nil
}
return []interface{}{map[string]interface{}{
"ipv4": settings.Ipv4,
"ipv6": settings.Ipv6Range,
"ipv4_fallback": settings.Ipv4Fallback,
}}
}

func inflateTeamsEgressSettings(settings interface{}) *cloudflare.EgressSettings {
settingsList := settings.([]interface{})
if len(settingsList) != 1 {
return nil
}
settingsMap := settingsList[0].(map[string]interface{})
ipv4 := settingsMap["ipv4"].(string)
ipv6 := settingsMap["ipv6"].(string)
ipv4Fallback := settingsMap["ipv4_fallback"].(string)
return &cloudflare.EgressSettings{
Ipv4: ipv4,
Ipv6Range: ipv6,
Ipv4Fallback: ipv4Fallback,
}
}

func providerToApiRulePrecedence(provided int64, ruleName string) int64 {
return provided*rulePrecedenceFactor + int64(hashCodeString(ruleName))%rulePrecedenceFactor
}
Expand Down
27 changes: 27 additions & 0 deletions internal/provider/schema_cloudflare_teams_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,33 @@ var teamsRuleSettings = map[string]*schema.Schema{
Optional: true,
Description: "Disable DNSSEC validation (must be Allow rule).",
},
"egress": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: egressSettings,
},
Description: "Configure how Proxy traffic egresses. Can be set for rules with Egress action and Egress filter. Can be omitted to indicate local egress via Warp IPs.",
},
}

var egressSettings = map[string]*schema.Schema{
"ipv6": {
Type: schema.TypeString,
Required: true,
Description: "The IPv6 range to be used for egress.",
},
"ipv4": {
Type: schema.TypeString,
Required: true,
Description: "The IPv4 address to be used for egress.",
},
"ipv4_fallback": {
Type: schema.TypeString,
Optional: true,
Description: "The IPv4 address to be used for egress in the event of an error egressing with the primary IPv4. Can be '0.0.0.0' to indicate local egreass via Warp IPs.",
},
}

var teamsL4OverrideSettings = map[string]*schema.Schema{
Expand Down

0 comments on commit 851b2f4

Please sign in to comment.