Skip to content

Commit

Permalink
cloudflare_tunnel_route: fix resource import
Browse files Browse the repository at this point in the history
Signed-off-by: Terin Stock <terinjokes@gmail.com>
  • Loading branch information
tjstansell authored and terinjokes committed Apr 25, 2022
1 parent 5508aa1 commit 291cf55
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/1580.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_tunnel_route: Fix importing resource
```
7 changes: 3 additions & 4 deletions cloudflare/resource_cloudflare_tunnel_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,16 @@ func resourceCloudflareTunnelRouteDelete(d *schema.ResourceData, meta interface{
}

func resourceCloudflareTunnelRouteImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
attributes := strings.SplitN(d.Id(), "/", 3)
attributes := strings.SplitN(d.Id(), "/", 2)

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

accountID, tunnelID, network := attributes[0], attributes[1], attributes[2]
accountID, network := attributes[0], attributes[1]

d.SetId(network)
d.Set("account_id", accountID)
d.Set("tunnel_id", tunnelID)
d.Set("network", network)

err := resourceCloudflareTunnelRouteRead(d, meta)
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/tunnel_route.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ The following arguments are supported:

## Import

An existing tunnel route can be imported using the account ID, tunnel ID, and network CIDR.
An existing tunnel route can be imported using the account ID and network CIDR.

```
$ terraform import cloudflare_tunnel_route c4a7362d577a6c3019a474fd6f485821/f70ff985-a4ef-4643-bbbc-4a0ed4fc8415/192.0.2.24/32
$ terraform import cloudflare_tunnel_route c4a7362d577a6c3019a474fd6f485821/192.0.2.24/32
```

0 comments on commit 291cf55

Please sign in to comment.