cloudflare / cloudflare/cloudflare-go

flarectl create-or-update record cannot be fully qualified

Open
#4,154 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
2.1k
Forks
781
Avg merge
12h 38m
Merged PRs (30d)
4

Description

### Confirm this is a Go library issue and not an underlying Cloudflare API issue

- [x] This is an issue with the Go library

### Describe the bug

I have an existing CNAME record `sample.apps.io` that points to `aaaaa.elb.us-east-1.amazonaws.com` and Im trying to update the contents to point to a new load balancer when `--name` is fully qualified for `flarectl dns create-or-update`.

### To Reproduce

The following attempt fails with:

```
$ flarectl dns create-or-update --proxy --zone apps.io --name sample.apps.io --content bbbbb.elb.us-east-1.amazonaws.com --type CNAME
Error creating DNS record: An A, AAAA, or CNAME record with that host already exists. For more details, refer to . (81053)
```
> flarectl is trying to `create` the record instead of `update` it if you look at the error meessage.

It seems that because the flag `--name sample.apps.io` is fully qualified instead of short `--name sample` this gets concatentated preemptively: https://github.com/cloudflare/cloudflare-go/blob/57714bfbdeea095ec27f4b9bafe65bda4f178d96/cmd/flarectl/dns.go#L86 This causes there to be no matching records (`sample.apps.io.apps.io`) to update and causes the create to fail instead since its still using what was passed in by `--name`: https://github.com/cloudflare/cloudflare-go/blob/57714bfbdeea095ec27f4b9bafe65bda4f178d96/cmd/flarectl/dns.go#L117

Ive noticed some inconsistency with `--name` for the CLI `dns` subcommands. `flarectl dns list` has differing results for FQDN vs short:

`flarectl dns list` FQDN:
```
$ flarectl dns list --zone apps.io --type CNAME --name sample.apps.io
ID | TYPE | NAME | CONTENT | PROXIED | TTL
-----------------------------------+-------+------------------------------+-------------------------------------------------------------------------------+---------+------
id123456 | CNAME | sample.apps.io | aaaaa.elb.us-east-1.amazonaws.com | true | 1
```

`flarectl dns list` short:
```
$ flarectl dns list --zone apps.io --type CNAME --name sample
ID | TYPE | NAME | CONTENT | PROXIED | TTL
-----+------+------+---------+---------+------
```

`create` and `update` dns subcommands will handle both FQDN and short. Heres the result of update:

```
$ flarectl dns update --id id123456 --proxy --zone apps.io --name sample.apps.io --content bbbbb.elb.us-east-1.amazonaws.com --type CNAME
$cloudinfra flarectl dns update --id id123456 --proxy --zone apps.io --name sample --content cccccc.elb.us-east-1.amazonaws.com --type CNAME
```
> Nothing is returned but records update as expected

### Suggestion

flarectl should have consistent behavior across the various `dns` subcommands consumption of `--name`. It seems like supporting both FQDN and short for `--name` for `create-or-update` and `list` would ensure it doesnt break existing behavior.

### OS

macOS

### Go version

Go 1.22.0

### Library version

github.com/cloudflare/cloudflare-go/v0.115.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.