Skip to content

Commit

Permalink
Merge pull request #1590 from bradleyglover/add-tunnel-token
Browse files Browse the repository at this point in the history
cloudflare_argo_tunnel: add tunnel token to state
  • Loading branch information
jacobbednarz committed May 29, 2022
2 parents b2b0fff + edd8b61 commit 18a570f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/1590.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_argo_tunnel: add `tunnel_token` support
```
13 changes: 13 additions & 0 deletions internal/provider/resource_cloudflare_argo_tunnel.go
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pkg/errors"
Expand Down Expand Up @@ -50,7 +51,19 @@ func resourceCloudflareArgoTunnelRead(ctx context.Context, d *schema.ResourceDat
return diag.FromErr(fmt.Errorf("failed to fetch Argo Tunnel: %w", err))
}

token, err := client.TunnelToken(ctx, cloudflare.TunnelTokenParams{
AccountID: accID,
ID: tunnel.ID,
})

if err != nil {
tflog.Warn(ctx, "unable to set the tunnel_token in state because it's not found in API")
d.Set("tunnel_token", "")
return nil
}

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

return nil
}
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/schema_cloudflare_argo_tunnel.go
Expand Up @@ -24,5 +24,9 @@ func resourceCloudflareArgoTunnelSchema() map[string]*schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"tunnel_token": {
Type: schema.TypeString,
Computed: true,
},
}
}
1 change: 1 addition & 0 deletions website/docs/r/argo_tunnel.html.markdown
Expand Up @@ -33,6 +33,7 @@ The following arguments are supported:
The following additional attributes are exported:

* `cname` - Usable CNAME for accessing the Argo Tunnel.
* `tunnel_token` - Token used by a connector to authenticate and run the tunnel.

## Import

Expand Down

0 comments on commit 18a570f

Please sign in to comment.