From 0629008548ec0628f6da970db3b9ec835c4deb09 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Mon, 18 Oct 2021 10:58:00 +1100 Subject: [PATCH] resource/argo_tunnel: add CNAME as exported attribute Supersedes #1176 Co-Authored-By: Andrew Burian --- .changelog/1259.txt | 3 +++ cloudflare/resource_cloudflare_argo_tunnel.go | 22 +++++++++++++++---- .../resource_cloudflare_argo_tunnel_test.go | 2 ++ website/docs/r/argo_tunnel.html.markdown | 5 +++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 .changelog/1259.txt diff --git a/.changelog/1259.txt b/.changelog/1259.txt new file mode 100644 index 0000000000..2f84a44176 --- /dev/null +++ b/.changelog/1259.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/cloudflare_argo_tunnel: add `cname` as exported attribute +``` diff --git a/cloudflare/resource_cloudflare_argo_tunnel.go b/cloudflare/resource_cloudflare_argo_tunnel.go index a1c5345d3d..60bb21fd29 100644 --- a/cloudflare/resource_cloudflare_argo_tunnel.go +++ b/cloudflare/resource_cloudflare_argo_tunnel.go @@ -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, @@ -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, }, }, } @@ -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 } diff --git a/cloudflare/resource_cloudflare_argo_tunnel_test.go b/cloudflare/resource_cloudflare_argo_tunnel_test.go index df2dfc86fa..78b7d38141 100644 --- a/cloudflare/resource_cloudflare_argo_tunnel_test.go +++ b/cloudflare/resource_cloudflare_argo_tunnel_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "regexp" "testing" "github.com/cloudflare/cloudflare-go" @@ -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")), ), }, }, diff --git a/website/docs/r/argo_tunnel.html.markdown b/website/docs/r/argo_tunnel.html.markdown index 301be3c05e..b1260b34b6 100644 --- a/website/docs/r/argo_tunnel.html.markdown +++ b/website/docs/r/argo_tunnel.html.markdown @@ -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