Skip to content

Commit

Permalink
Destroying tunnel configurations applies an empty configuration rathe…
Browse files Browse the repository at this point in the history
…r than deleting the parent cloudflare_tunnel resource
  • Loading branch information
samcook committed Sep 20, 2023
1 parent e41a876 commit bb8b020
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .changelog/2769.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_tunnel_config: Destroying tunnel configurations now applies an empty configuration rather than deleting the parent cloudflare_tunnel resource
```
3 changes: 0 additions & 3 deletions docs/resources/tunnel_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ description: |-

Provides a Cloudflare Tunnel configuration resource.

!> When you delete a tunnel configuration, the tunnel will be deleted. You need to make sure that the tunnel is not in use before deleting the configuration.

## Example Usage

```terraform
Expand Down Expand Up @@ -69,7 +67,6 @@ resource "cloudflare_tunnel_config" "example_config" {
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

Expand Down
22 changes: 20 additions & 2 deletions internal/sdkv2provider/resource_cloudflare_tunnel_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,31 @@ func resourceCloudflareTunnelConfigUpdate(ctx context.Context, d *schema.Resourc
func resourceCloudflareTunnelConfigDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*cloudflare.API)
accountID := d.Get(consts.AccountIDSchemaKey).(string)
tunnelID := d.Get("tunnel_id").(string)

err := client.DeleteTunnel(ctx, cloudflare.AccountIdentifier(accountID), d.Id())
// can't delete a tunnel config, so set an "empty" config instead
tunnel := cloudflare.TunnelConfigurationParams{
TunnelID: tunnelID,
Config: cloudflare.TunnelConfiguration{
OriginRequest: cloudflare.OriginRequestConfig{},
WarpRouting: &cloudflare.WarpRoutingConfig{
Enabled: false,
},
Ingress: []cloudflare.UnvalidatedIngressRule{
{
Service: "http_status:404",
},
},
},
}

_, err := client.UpdateTunnelConfiguration(ctx, cloudflare.AccountIdentifier(accountID), tunnel)
if err != nil {
return diag.FromErr(fmt.Errorf("error deleting tunnel config %q: %w", d.Id(), err))
return diag.FromErr(fmt.Errorf("error clearing tunnel config %q: %w", tunnelID, err))
}

d.SetId("")

return nil
}

Expand Down
26 changes: 0 additions & 26 deletions templates/resources/tunnel_config.md.tmpl

This file was deleted.

0 comments on commit bb8b020

Please sign in to comment.