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

resource/cloudflare_ipsec_tunnel: Adds IPsec tunnel health_check_direction & health_check_rate parameters #3112

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3112.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
cloudflare_ipsec_tunnel: Adds IPsec tunnel health_check_direction & health_check_rate parameters
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
```
2 changes: 2 additions & 0 deletions docs/resources/ipsec_tunnel.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ resource "cloudflare_ipsec_tunnel" "example" {
- `allow_null_cipher` (Boolean) Specifies if this tunnel may use a null cipher (ENCR_NULL) in Phase 2. Defaults to `false`.
- `description` (String) An optional description of the IPsec tunnel.
- `fqdn_id` (String) `remote_id` in the form of a fqdn. This value is generated by cloudflare.
- `health_check_direction` (String) Specifies the direction for the health check. Available values: `unidirectional`, `bidirectional` Default: `unidirectional`.
- `health_check_enabled` (Boolean) Specifies if ICMP tunnel health checks are enabled. Default: `true`.
- `health_check_rate` (String) Specifies the ICMP rate for the health check. Available values: `low`, `mid`, `high` Default: `mid`.
- `health_check_target` (String) The IP address of the customer endpoint that will receive tunnel health checks. Default: `<customer_gre_endpoint>`.
- `health_check_type` (String) Specifies the ICMP echo type for the health check (`request` or `reply`). Available values: `request`, `reply` Default: `reply`.
- `hex_id` (String) `remote_id` as a hex string. This value is generated by cloudflare.
Expand Down
42 changes: 42 additions & 0 deletions internal/sdkv2provider/resource_cloudflare_ipsec_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func resourceCloudflareIPsecTunnelRead(ctx context.Context, d *schema.ResourceDa
d.Set("health_check_enabled", tunnel.HealthCheck.Enabled)
d.Set("health_check_target", tunnel.HealthCheck.Target)
d.Set("health_check_type", tunnel.HealthCheck.Type)
d.Set("health_check_direction", tunnel.HealthCheck.Direction)
d.Set("health_check_rate", tunnel.HealthCheck.Rate)
d.Set("allow_null_cipher", tunnel.AllowNullCipher)

// Set Remote Identities
Expand Down Expand Up @@ -176,5 +178,45 @@ func IPsecTunnelFromResource(d *schema.ResourceData) cloudflare.MagicTransitIPse
tunnel.AllowNullCipher = allowNullCipher.(bool)
}

healthcheck := IPsecTunnelHealthcheckFromResource(d)
if healthcheck != nil {
tunnel.HealthCheck = healthcheck
}

return tunnel
}

func IPsecTunnelHealthcheckFromResource(d *schema.ResourceData) *cloudflare.MagicTransitTunnelHealthcheck {
healthcheck := cloudflare.MagicTransitTunnelHealthcheck{}

healthcheckEnabled, healthcheckEnabledOk := d.GetOk("health_check_enabled")
if healthcheckEnabledOk {
healthcheck.Enabled = healthcheckEnabled.(bool)
}

healthcheckTarget, healthcheckTargetOk := d.GetOk("health_check_target")
if healthcheckTargetOk {
healthcheck.Target = healthcheckTarget.(string)
}

healthcheckType, healthcheckTypeOk := d.GetOk("health_check_type")
if healthcheckTypeOk {
healthcheck.Type = healthcheckType.(string)
}

healthcheckDirection, healthcheckDirectionOk := d.GetOk("health_check_direction")
if healthcheckDirectionOk {
healthcheck.Direction = healthcheckDirection.(string)
}

healthcheckRate, healthcheckRateOk := d.GetOk("health_check_rate")
if healthcheckRateOk {
healthcheck.Rate = healthcheckRate.(string)
}

if healthcheckEnabledOk || healthcheckTargetOk || healthcheckTypeOk || healthcheckDirectionOk || healthcheckRateOk {
return &healthcheck
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func TestAccCloudflareIPsecTunnelExists(t *testing.T) {
resource.TestCheckResourceAttr(name, "health_check_enabled", "true"),
resource.TestCheckResourceAttr(name, "health_check_target", "203.0.113.1"),
resource.TestCheckResourceAttr(name, "health_check_type", "request"),
resource.TestCheckResourceAttr(name, "health_check_direction", "unidirectional"),
resource.TestCheckResourceAttr(name, "health_check_rate", "mid"),
resource.TestCheckResourceAttr(name, "psk", "asdf1234"),
resource.TestCheckResourceAttr(name, "allowNullCipher", "false"),
),
Expand Down Expand Up @@ -147,6 +149,8 @@ func testAccCheckCloudflareIPsecTunnelSimple(ID, description, accountID, psk str
health_check_enabled = true
health_check_target = "203.0.113.1"
health_check_type = "request"
health_check_direction = "unidirectional"
health_check_rate = "mid"
psk = "%[4]s"
allow_null_cipher = false
}`, ID, description, accountID, psk)
Expand Down
14 changes: 14 additions & 0 deletions internal/sdkv2provider/schema_cloudflare_ipsec_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ func resourceCloudflareIPsecTunnelSchema() map[string]*schema.Schema {
ValidateFunc: validation.StringInSlice([]string{"request", "reply"}, false),
Description: fmt.Sprintf("Specifies the ICMP echo type for the health check (`request` or `reply`). %s Default: `reply`.", renderAvailableDocumentationValuesStringSlice([]string{"request", "reply"})),
},
"health_check_direction": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"unidirectional", "bidirectional"}, false),
Description: fmt.Sprintf("Specifies the direction for the health check. %s Default: `unidirectional`.", renderAvailableDocumentationValuesStringSlice([]string{"unidirectional", "bidirectional"})),
},
"health_check_rate": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{"low", "mid", "high"}, false),
Description: fmt.Sprintf("Specifies the ICMP rate for the health check. %s Default: `mid`.", renderAvailableDocumentationValuesStringSlice([]string{"low", "mid", "high"})),
},
"psk": {
Type: schema.TypeString,
Optional: true,
Expand Down