Skip to content

Commit

Permalink
Merge pull request #1259 from cloudflare/add-uuid-to-tunnel
Browse files Browse the repository at this point in the history
resource/argo_tunnel: add CNAME as exported attribute
  • Loading branch information
jacobbednarz authored Oct 18, 2021
2 parents de50766 + 0629008 commit ae2bf3d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/1259.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_argo_tunnel: add `cname` as exported attribute
```
22 changes: 18 additions & 4 deletions cloudflare/resource_cloudflare_argo_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"github.com/pkg/errors"
)

const argoTunnelCNAME = "argotunnel.com"

func resourceCloudflareArgoTunnel() *schema.Resource {
return &schema.Resource{
Create: resourceCloudflareArgoTunnelCreate,
Read: resourceCloudflareArgoTunnelRead,
Update: resourceCloudflareArgoTunnelUpdate,
Delete: resourceCloudflareArgoTunnelDelete,
Importer: &schema.ResourceImporter{
State: resourceCloudflareArgoTunnelImport,
Expand All @@ -24,15 +25,22 @@ func resourceCloudflareArgoTunnel() *schema.Resource {
"account_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"secret": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
ForceNew: true,
},
"cname": {
Type: schema.TypeString,
Computed: true,
},
},
}
Expand All @@ -55,10 +63,16 @@ func resourceCloudflareArgoTunnelCreate(d *schema.ResourceData, meta interface{}
}

func resourceCloudflareArgoTunnelRead(d *schema.ResourceData, meta interface{}) error {
return nil
}
client := meta.(*cloudflare.API)
accID := d.Get("account_id").(string)

tunnel, err := client.ArgoTunnel(context.Background(), accID, d.Id())
if err != nil {
return fmt.Errorf("failed to fetch Argo Tunnel: %w", err)
}

d.Set("cname", fmt.Sprintf("%s.%s", tunnel.ID, argoTunnelCNAME))

func resourceCloudflareArgoTunnelUpdate(d *schema.ResourceData, meta interface{}) error {
return nil
}

Expand Down
2 changes: 2 additions & 0 deletions cloudflare/resource_cloudflare_argo_tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"regexp"
"testing"

"github.com/cloudflare/cloudflare-go"
Expand Down Expand Up @@ -37,6 +38,7 @@ func TestAccCloudflareArgoTunnelCreate(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "name", rnd),
resource.TestCheckResourceAttr(name, "secret", "AQIDBAUGBwgBAgMEBQYHCAECAwQFBgcIAQIDBAUGBwg="),
resource.TestMatchResourceAttr(name, "cname", regexp.MustCompile(".*\\.argotunnel\\.com")),
),
},
},
Expand Down
5 changes: 5 additions & 0 deletions website/docs/r/argo_tunnel.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ The following arguments are supported:
* `name` - (Required) A user-friendly name chosen when the tunnel is created. Cannot be empty.
* `secret` - (Required) 32 or more bytes, encoded as a base64 string. The Create Argo Tunnel endpoint sets this as the tunnel's password. Anyone wishing to run the tunnel needs this password.

## Attributes Reference

The following additional attributes are exported:

* `cname` - Usable CNAME for accessing the Argo Tunnel.

## Import

Expand Down

0 comments on commit ae2bf3d

Please sign in to comment.