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

Fix cloudflare_split_tunnel import #1331

Merged
merged 6 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all 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/1313.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_split_tunnel: import now works by specifying accountId/mode
```
10 changes: 8 additions & 2 deletions cloudflare/resource_cloudflare_split_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cloudflare
import (
"context"
"fmt"
"strings"

cloudflare "github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -75,8 +76,13 @@ func resourceCloudflareSplitTunnelDelete(d *schema.ResourceData, meta interface{
}

func resourceCloudflareSplitTunnelImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
accountID := d.Get("account_id").(string)
mode := d.Get("mode").(string)
attributes := strings.SplitN(d.Id(), "/", 2)

if len(attributes) != 2 {
return nil, fmt.Errorf("invalid id (\"%s\") specified, should be in format \"accountID/mode\"", d.Id())
}

accountID, mode := attributes[0], attributes[1]

d.Set("mode", mode)
d.Set("account_id", accountID)
Expand Down
7 changes: 4 additions & 3 deletions website/docs/r/split_tunnel.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: "cloudflare"
page_title: "Cloudflare: cloudflare_split_tunnel"
sidebar_current: "docs-cloudflare-resource-split-tunnel"
description: |-
Provides a Cloudflare Split Tunnel Exclude resource.
Provides a Cloudflare Split Tunnel resource.
---

# cloudflare_split_tunnel
Expand Down Expand Up @@ -40,6 +40,7 @@ resource "cloudflare_split_tunnel" "example_split_tunnel_include" {
The following arguments are supported:

- `account_id` - (Required) The account to which the device posture rule should be added.
- `mode` - (Required) The split tunnel mode. Valid values are `include` or `exclude`.
- `tunnels` - (Required) The value of the tunnel attributes (refer to the [nested schema](#nestedblock--tunnels)).

<a id="nestedblock--tunnels"></a>
Expand All @@ -51,8 +52,8 @@ The following arguments are supported:

## Import

Split Tunnels can be imported using the account identifer.
Split Tunnels can be imported using the account identifer and mode.

```
$ terraform import cloudflare_split_tunnel.example 1d5fdc9e88c8a8c4518b068cd94331fe
$ terraform import cloudflare_split_tunnel.example 1d5fdc9e88c8a8c4518b068cd94331fe/exclude
```