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/argo_tunnel: add CNAME as exported attribute #1259

Merged
merged 1 commit into from
Oct 18, 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/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