Skip to content

Commit 9fccffb

Browse files
committed
Add generation support to inbound rulesets
1 parent 4f29209 commit 9fccffb

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

docs/resources/space_inbound_ruleset.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ Provides a resource for managing [inbound rulesets](https://devcenter.heroku.com
1313
## Example Usage
1414

1515
```hcl-terraform
16-
# Create a new Heroku space
16+
# Create a new Heroku space (Cedar generation - supports inbound rulesets)
1717
resource "heroku_space" "default" {
1818
name = "test-space"
1919
organization = "my-company"
2020
region = "virginia"
21+
generation = "cedar"
2122
}
2223
2324
# Allow all traffic EXCEPT 8.8.4.4 to access the HPS.
2425
resource "heroku_space_inbound_ruleset" "default" {
25-
space = heroku_space.default.id
26+
space = heroku_space.default.id
27+
generation = "cedar"
2628
2729
rule {
2830
action = "allow"
@@ -41,6 +43,7 @@ resource "heroku_space_inbound_ruleset" "default" {
4143
The following arguments are supported:
4244

4345
* `space` - (Required) The ID of the space.
46+
* `generation` - (Optional) Generation of the space for inbound ruleset. Valid values are `cedar` and `fir`. Defaults to `cedar` for backward compatibility. **ForceNew**. Note: Inbound rulesets are not supported for `fir` generation spaces.
4447
* `rule` - (Required) At least one `rule` block. Rules are documented below.
4548

4649
A `rule` block supports the following arguments:
@@ -53,3 +56,4 @@ A `rule` block supports the following arguments:
5356
The following attributes are exported:
5457

5558
* `id` - The ID of the inbound ruleset.
59+
* `generation` - Generation of the space for inbound ruleset.

heroku/resource_heroku_space_inbound_ruleset.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@ func resourceHerokuSpaceInboundRuleset() *schema.Resource {
1616
Update: resourceHerokuSpaceInboundRulesetSet,
1717
Delete: resourceHerokuSpaceInboundRulesetDelete,
1818

19+
CustomizeDiff: resourceHerokuSpaceInboundRulesetCustomizeDiff,
20+
1921
Schema: map[string]*schema.Schema{
2022
"space": {
2123
Type: schema.TypeString,
2224
Required: true,
2325
ForceNew: true,
2426
},
2527

28+
"generation": {
29+
Type: schema.TypeString,
30+
Optional: true,
31+
Default: "cedar",
32+
ForceNew: true,
33+
ValidateFunc: validation.StringInSlice([]string{"cedar", "fir"}, false),
34+
Description: "Generation of the space for inbound ruleset. Defaults to cedar for backward compatibility.",
35+
},
36+
2637
"rule": {
2738
Type: schema.TypeSet,
2839
Required: true,
@@ -136,3 +147,16 @@ func resourceHerokuSpaceInboundRulesetDelete(d *schema.ResourceData, meta interf
136147
d.SetId("")
137148
return nil
138149
}
150+
151+
func resourceHerokuSpaceInboundRulesetCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, v interface{}) error {
152+
generation, generationExists := diff.GetOk("generation")
153+
154+
if generationExists {
155+
generationStr := generation.(string)
156+
157+
if !IsFeatureSupported(generationStr, "space", "inbound_ruleset") {
158+
return fmt.Errorf("inbound rulesets are not supported for %s generation spaces", generationStr)
159+
}
160+
}
161+
return nil
162+
}

heroku/resource_heroku_space_inbound_ruleset_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,32 @@ resource "heroku_space_inbound_ruleset" "foobar" {
4040
}
4141
`, spaceConfig)
4242
}
43+
44+
// Unit tests for inbound ruleset generation support
45+
func TestHerokuSpaceInboundRulesetGeneration(t *testing.T) {
46+
tests := []struct {
47+
name string
48+
generation string
49+
expectError bool
50+
description string
51+
}{
52+
{name: "Cedar generation should be supported", generation: "cedar", expectError: false, description: "Cedar supports inbound rulesets"},
53+
{name: "Fir generation should be unsupported", generation: "fir", expectError: true, description: "Fir does not support inbound rulesets"},
54+
{name: "Default generation (cedar) should be supported", generation: "", expectError: false, description: "Default cedar generation supports inbound rulesets"},
55+
}
56+
57+
for _, tt := range tests {
58+
t.Run(tt.name, func(t *testing.T) {
59+
generation := tt.generation
60+
if generation == "" {
61+
generation = "cedar"
62+
}
63+
supported := IsFeatureSupported(generation, "space", "inbound_ruleset")
64+
shouldError := !supported
65+
if shouldError != tt.expectError {
66+
t.Errorf("Expected error: %t, but got: %t for generation %s", tt.expectError, shouldError, generation)
67+
}
68+
t.Logf("✅ Generation: %s, Supported: %t, ShouldError: %t", generation, supported, shouldError)
69+
})
70+
}
71+
}

0 commit comments

Comments
 (0)