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

cloudflare_argo_tunnel: add tunnel token to state #1590

Merged
merged 9 commits into from May 29, 2022
3 changes: 3 additions & 0 deletions .changelog/1590.txt
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_argo_tunnel: Add computed `tunnel_token` to schema
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
```
10 changes: 10 additions & 0 deletions internal/provider/resource_cloudflare_argo_tunnel.go
Expand Up @@ -50,6 +50,16 @@ func resourceCloudflareArgoTunnelRead(ctx context.Context, d *schema.ResourceDat
return diag.FromErr(fmt.Errorf("failed to fetch Argo Tunnel: %w", err))
}

token, err := client.TunnelToken(context.Background(), cloudflare.TunnelTokenParams{
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
AccountID: accID,
ID: tunnel.ID,
})
if err != nil {
fmt.Sprintf("[WARN] Unable to set the tunnel_token in state because it's not found in API")
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
d.Set("tunnel_token", "")
return nil
}

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

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": {
jacobbednarz marked this conversation as resolved.
Show resolved Hide resolved
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