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

DNS comment fixes #2148

Merged
merged 7 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2148.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_record: fix issue with DNS comments and tags not being set for new records
```
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ FROM golang:1.18.3
RUN apt-get update -y && apt-get install -y lsb-release
RUN wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
RUN echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/hashicorp.list
RUN apt-get update -y && apt-get install -y terraform
RUN apt-get update -y && apt-get install -y terraform jq curl
20 changes: 20 additions & 0 deletions internal/provider/resource_cloudflare_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ func resourceCloudflareRecordCreate(ctx context.Context, d *schema.ResourceData,
proxiedVal = cloudflare.BoolPtr(false)
}

if comment, ok := d.GetOk("comment"); ok {
newRecord.Comment = comment.(string)
}

if tags, ok := d.GetOk("tags"); ok {
for _, tag := range tags.(*schema.Set).List() {
newRecord.Tags = append(newRecord.Tags, tag.(string))
}
}

// Validate type
if err := validateRecordType(newRecord.Type, *proxiedVal); err != nil {
return diag.FromErr(fmt.Errorf("error validating record type %q: %w", newRecord.Type, err))
Expand Down Expand Up @@ -295,6 +305,16 @@ func resourceCloudflareRecordUpdate(ctx context.Context, d *schema.ResourceData,
updateRecord.TTL = ttl.(int)
}

if comment, ok := d.GetOk("comment"); ok {
updateRecord.Comment = comment.(string)
}

if tags, ok := d.GetOk("tags"); ok {
for _, tag := range tags.(*schema.Set).List() {
updateRecord.Tags = append(updateRecord.Tags, tag.(string))
}
}

tflog.Debug(ctx, fmt.Sprintf("Cloudflare Record update configuration: %#v", updateRecord))

retry := resource.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
Expand Down
8 changes: 8 additions & 0 deletions internal/provider/resource_cloudflare_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func TestAccCloudflareRecord_Basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "ttl", "3600"),
resource.TestCheckResourceAttr(resourceName, "metadata.%", "4"),
resource.TestCheckResourceAttr(resourceName, "metadata.auto_added", "false"),
resource.TestCheckResourceAttr(resourceName, "tags.#", "2"),
resource.TestCheckResourceAttr(resourceName, "tags.0", "tag1"),
resource.TestCheckResourceAttr(resourceName, "tags.1", "tag2"),
resource.TestCheckResourceAttr(resourceName, "comment", "this is a comment"),
),
},
},
Expand Down Expand Up @@ -700,6 +704,8 @@ resource "cloudflare_record" "%[3]s" {
value = "192.168.0.10"
type = "A"
ttl = 3600
tags = ["tag1", "tag2"]
comment = "this is a comment"
}`, zoneID, name, rnd)
}

Expand Down Expand Up @@ -791,6 +797,8 @@ resource "cloudflare_record" "%[3]s" {
value = "192.168.0.11"
type = "A"
ttl = 3600
tags = ["updated_tag1", "updated_tag2"]
comment = "this is am updated comment"
}`, zoneID, name, rnd)
}

Expand Down
1 change: 1 addition & 0 deletions scripts/generate-docs.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exclude_files=()

# Check if manual changes were made to any excluded files and exit
# otherwise these will be lost with `tfplugindocs`

if [ "$(git status --porcelain "${exclude_files[@]}")" ]; then
echo "Uncommitted changes were detected to the following files. These aren't autogenerated, please commit or stash these changes and try again"
echo $(git status --porcelain "${exclude_files[@]}")
Expand Down