Skip to content

Commit 9c1a2db

Browse files
committed
update logpush to delete instant-logs for kind
1 parent 7ad287d commit 9c1a2db

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

integration/v4_to_v5/testdata/logpush_job/expected/logpush_job.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ resource "cloudflare_logpush_job" "with_cve_field" {
4949
}
5050
}
5151

52-
# Job with instant-logs kind (should become empty string)
52+
# Job with instant-logs kind (should be removed)
5353
resource "cloudflare_logpush_job" "instant_logs" {
5454
zone_id = var.cloudflare_zone_id
5555
dataset = "http_requests"
5656
destination_conf = "https://logpush-receiver.sd.cfplat.com"
57-
kind = ""
5857
}
5958

6059
# Job with edge kind (should be preserved)
@@ -65,12 +64,19 @@ resource "cloudflare_logpush_job" "edge_logs" {
6564
kind = "edge"
6665
}
6766

67+
# Job with "" kind (should be preserved)
68+
resource "cloudflare_logpush_job" "edge_logs" {
69+
zone_id = var.cloudflare_zone_id
70+
dataset = "http_requests"
71+
destination_conf = "https://logpush-receiver.sd.cfplat.com"
72+
kind = ""
73+
}
74+
6875
# Full featured job with all transformations
6976
resource "cloudflare_logpush_job" "full" {
7077
zone_id = var.cloudflare_zone_id
7178
dataset = "http_requests"
7279
destination_conf = "https://logpush-receiver.sd.cfplat.com"
73-
kind = ""
7480
enabled = true
7581
name = "my-logpush-job"
7682
frequency = "high"

integration/v4_to_v5/testdata/logpush_job/expected/terraform.tfstate

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@
111111
"account_id": "f037e56e89293a057740de681ac9abbe",
112112
"dataset": "http_requests",
113113
"destination_conf": "https://logpush-receiver.sd.cfplat.com",
114-
"enabled": true,
115-
"kind": ""
114+
"enabled": true
116115
}
117116
}
118117
]
@@ -150,7 +149,6 @@
150149
"dataset": "http_requests",
151150
"destination_conf": "https://logpush-receiver.sd.cfplat.com",
152151
"enabled": true,
153-
"kind": "",
154152
"name": "my-logpush-job",
155153
"frequency": "high",
156154
"max_upload_bytes": 5000000.0,

integration/v4_to_v5/testdata/logpush_job/input/logpush_job.tf

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ resource "cloudflare_logpush_job" "with_cve_field" {
3939
}
4040
}
4141

42-
# Job with instant-logs kind (should become empty string)
42+
# Job with instant-logs kind (should be removed)
4343
resource "cloudflare_logpush_job" "instant_logs" {
4444
zone_id = var.cloudflare_zone_id
4545
dataset = "http_requests"
@@ -55,6 +55,14 @@ resource "cloudflare_logpush_job" "edge_logs" {
5555
kind = "edge"
5656
}
5757

58+
# Job with "" kind (should be preserved)
59+
resource "cloudflare_logpush_job" "edge_logs" {
60+
zone_id = var.cloudflare_zone_id
61+
dataset = "http_requests"
62+
destination_conf = "https://logpush-receiver.sd.cfplat.com"
63+
kind = ""
64+
}
65+
5866
# Full featured job with all transformations
5967
resource "cloudflare_logpush_job" "full" {
6068
zone_id = var.cloudflare_zone_id

internal/resources/logpush_job/v4_to_v5.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,13 @@ func (m *V4ToV5Migrator) TransformConfig(ctx *transform.Context, block *hclwrite
5454
tfhcl.ConvertSingleBlockToAttribute(body, "output_options", "output_options")
5555
}
5656

57-
// 2. Handle kind = "instant-logs" → kind = ""
58-
// "instant-logs" is no longer valid in v5, convert to empty string
57+
// 2. Handle kind = "instant-logs" → remove attribute
58+
// "instant-logs" is no longer valid in v5, remove the attribute entirely
5959
if kindAttr := body.GetAttribute("kind"); kindAttr != nil {
6060
kindValue := tfhcl.ExtractStringFromAttribute(kindAttr)
6161
if kindValue == "instant-logs" {
62-
// Set to empty string (default in v5)
63-
tokens := hcl.TokensForSimpleValue("")
64-
if tokens != nil {
65-
body.SetAttributeRaw("kind", tokens)
66-
}
62+
// Remove the attribute entirely since instant-logs is not valid in v5
63+
body.RemoveAttribute("kind")
6764
}
6865
}
6966

@@ -120,9 +117,10 @@ func (m *V4ToV5Migrator) TransformState(ctx *transform.Context, stateJSON gjson.
120117
result = state.RemoveFields(result, "attributes", attrs,
121118
"error_message", "last_complete", "last_error")
122119

123-
// 4. Handle kind value change: "instant-logs" → ""
120+
// 4. Handle kind value change: "instant-logs" → remove attribute
121+
// "instant-logs" is no longer valid in v5, remove it entirely
124122
if kind := attrs.Get("kind"); kind.Exists() && kind.String() == "instant-logs" {
125-
result, _ = sjson.Set(result, "attributes.kind", "")
123+
result, _ = sjson.Delete(result, "attributes.kind")
126124
}
127125

128126
return result, nil

internal/resources/logpush_job/v4_to_v5_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func TestV4ToV5Transformation(t *testing.T) {
147147
}`,
148148
},
149149
{
150-
Name: "Handle kind instant-logs to empty string",
150+
Name: "Handle kind instant-logs by removing attribute",
151151
Input: `resource "cloudflare_logpush_job" "example" {
152152
dataset = "http_requests"
153153
destination_conf = "s3://mybucket/logs?region=us-west-2"
@@ -156,7 +156,6 @@ func TestV4ToV5Transformation(t *testing.T) {
156156
Expected: `resource "cloudflare_logpush_job" "example" {
157157
dataset = "http_requests"
158158
destination_conf = "s3://mybucket/logs?region=us-west-2"
159-
kind = ""
160159
}`,
161160
},
162161
{
@@ -208,7 +207,6 @@ func TestV4ToV5Transformation(t *testing.T) {
208207
account_id = "abc123"
209208
dataset = "http_requests"
210209
destination_conf = "s3://mybucket/logs?region=us-west-2"
211-
kind = ""
212210
enabled = true
213211
214212
output_options = {
@@ -249,7 +247,6 @@ resource "cloudflare_logpush_job" "job2" {
249247
Expected: `resource "cloudflare_logpush_job" "job1" {
250248
dataset = "http_requests"
251249
destination_conf = "s3://bucket1/logs?region=us-west-2"
252-
kind = ""
253250
254251
output_options = {
255252
output_type = "ndjson"
@@ -539,7 +536,7 @@ resource "cloudflare_logpush_job" "job2" {
539536
}`,
540537
},
541538
{
542-
Name: "Handle kind instant-logs to empty string",
539+
Name: "Handle kind instant-logs by removing attribute",
543540
Input: `{
544541
"attributes": {
545542
"dataset": "http_requests",
@@ -550,8 +547,7 @@ resource "cloudflare_logpush_job" "job2" {
550547
Expected: `{
551548
"attributes": {
552549
"dataset": "http_requests",
553-
"destination_conf": "s3://mybucket/logs?region=us-west-2",
554-
"kind": ""
550+
"destination_conf": "s3://mybucket/logs?region=us-west-2"
555551
}
556552
}`,
557553
},
@@ -639,7 +635,6 @@ resource "cloudflare_logpush_job" "job2" {
639635
"account_id": "abc123",
640636
"dataset": "http_requests",
641637
"destination_conf": "s3://mybucket/logs?region=us-west-2",
642-
"kind": "",
643638
"enabled": true,
644639
"max_upload_bytes": 5000000.0,
645640
"max_upload_records": 1000.0,

0 commit comments

Comments
 (0)