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

Add cname and UUID to tunnel #1176

Closed
Closed
Changes from 1 commit
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
51 changes: 32 additions & 19 deletions cloudflare/resource_cloudflare_argo_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func resourceCloudflareArgoTunnel() *schema.Resource {
Required: true,
Sensitive: true,
},
"cname": {
Type: schema.TypeString,
Computed: true,
Description: "The generated CNAME for the named tunnel",
},
"uuid": {
Type: schema.TypeString,
Computed: true,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't really need this; the resource ID is already this value.

},
}
}
Expand All @@ -55,10 +64,30 @@ func resourceCloudflareArgoTunnelCreate(d *schema.ResourceData, meta interface{}
}

func resourceCloudflareArgoTunnelRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*cloudflare.API)

attributes := strings.Split(d.Id(), "/")

if len(attributes) != 2 {
return fmt.Errorf("invalid id (\"%s\") specified, should be in format \"accountID/argoTunnelUUID\"", d.Id())
}

accID, tunnelID := attributes[0], attributes[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is Import specific behaviour, the Read doesn't need any of this. Read only syncs the remote API to the local state configuration.


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

d.Set("name", tunnel.Name)
d.Set("cname", fmt.Sprintf("%s.argotunnel.com", tunnelID))
d.Set("uuid", tunnelID)
d.SetId(tunnel.ID)

return nil
}

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

Expand All @@ -82,24 +111,8 @@ func resourceCloudflareArgoTunnelDelete(d *schema.ResourceData, meta interface{}
}

func resourceCloudflareArgoTunnelImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*cloudflare.API)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned at https://github.com/cloudflare/terraform-provider-cloudflare/pull/1176/files#r700663326, some of this functionality needs to stay as is as it's Import specific and Read doesn't use it.

attributes := strings.Split(d.Id(), "/")

if len(attributes) != 2 {
return nil, fmt.Errorf("invalid id (\"%s\") specified, should be in format \"accountID/argoTunnelUUID\"", d.Id())
}

accID, tunnelID := attributes[0], attributes[1]

tunnel, err := client.ArgoTunnel(context.Background(), accID, tunnelID)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch Argo Tunnel %s", tunnelID))
}

d.Set("name", tunnel.Name)
d.SetId(tunnel.ID)

resourceCloudflareArgoTunnelRead(d, meta)
err := resourceCloudflareArgoTunnelRead(d, meta)

return []*schema.ResourceData{d}, nil
return []*schema.ResourceData{d}, err
}