cloudflare / cloudflare/tf-migrate

`cloudflare_ruleset`: converts valid nested dynamic block into invalid syntax

Open
#304 1 comment 0 reactions 1 assignee Claimed by @vaishakdinesh View on GitHub
bug
Dominant language
Go
Stars
33
Forks
12
Avg merge
1d 1h
Merged PRs (30d)
2

Description

### tf-migrate version

1.0.1

### Migration path

v4 to v5

### Affected resource type(s)

cloudflare_ruleset

### Description

The tool converts a valid nested dynamic block into invalid syntax.

### Input configuration

```hcl
resource "cloudflare_ruleset" "http_ratelimit" {
account_id = cloudflare_account.abc.id
name = "Rate limit configuration"
description = "Apply rate limiting configuration"
kind = "custom"
phase = "http_ratelimit"

# All the rate limit rules using blocks instead of attribute lists
dynamic "rules" {
for_each = local.account_ratelimit_rules_with_ref
content {
action = try(rules.value.action, null)
description = try(rules.value.description, null)
enabled = try(rules.value.enabled, null)
expression = try(rules.value.expression, null)
ref = rules.value.ref

dynamic "ratelimit" {
for_each = [rules.value.ratelimit]
content {
characteristics = try(ratelimit.value.characteristics, null)
period = try(ratelimit.value.period, null)
requests_per_period = try(ratelimit.value.requests_per_period, null)
mitigation_timeout = try(ratelimit.value.mitigation_timeout, null)
counting_expression = try(ratelimit.value.counting_expression, null)
}
}
}
}
}
```

### Expected output

```hcl
resource "cloudflare_ruleset" "http_ratelimit" {
account_id = cloudflare_account.nlo.id
name = "Rate limit configuration"
description = "Apply rate limiting configuration"
kind = "custom"
phase = "http_ratelimit"

rules = [for rule in local.account_ratelimit_rules_with_ref : {
action = try(rule.action, null)
description = try(rule.description, null)
enabled = try(rule.enabled, null)
expression = try(rule.expression, null)
ref = rule.ref

ratelimit = {
characteristics = try(rule.ratelimit.characteristics, null)
counting_expression = try(rule.ratelimit.counting_expression, null)
mitigation_timeout = try(rule.ratelimit.mitigation_timeout, null)
period = try(rule.ratelimit.period, null)
requests_per_period = try(rule.ratelimit.requests_per_period, null)
}
}]
}
```

### Actual output

```shell
Error: Reference to undeclared resource

│ on ../modules/cloudflare-account/rate_limit.tf line 66, in resource "cloudflare_ruleset" "http_ratelimit":
│ 66: characteristics = try(ratelimit.value.characteristics, null)

│ A managed resource "ratelimit" "value" has not been declared in module.account.


│ Error: Reference to undeclared resource

│ on ../modules/cloudflare-account/rate_limit.tf line 67, in resource "cloudflare_ruleset" "http_ratelimit":
│ 67: counting_expression = try(ratelimit.value.counting_expression, null)

│ A managed resource "ratelimit" "value" has not been declared in module.account.

resource "cloudflare_ruleset" "http_ratelimit" {
account_id = cloudflare_account.abc.id
name = "Rate limit configuration"
description = "Apply rate limiting configuration"
kind = "custom"
phase = "http_ratelimit"

# All the rate limit rules using blocks instead of attribute lists
rules = [for rules in local.account_ratelimit_rules_with_ref : {
action = try(rules.action, null)
description = try(rules.description, null)
enabled = try(rules.enabled, null)
expression = try(rules.expression, null)
ref = rules.ref
dynamic = {
for_each = [rules.ratelimit]
content = {
characteristics = try(ratelimit.value.characteristics, null)
counting_expression = try(ratelimit.value.counting_expression, null)
mitigation_timeout = try(ratelimit.value.mitigation_timeout, null)
period = try(ratelimit.value.period, null)
requests_per_period = try(ratelimit.value.requests_per_period, null)
}
}
}
}
```

### Steps to reproduce

_No response_

### Additional context

_No response_

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.