Skip to content

Commit 65df003

Browse files
committed
Add generation support to peering connections
1 parent 9fccffb commit 65df003

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

docs/resources/space_peering_connection_accepter.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ resource "aws_vpc_peering_connection" "request" {
2525
vpc_id = aws_vpc.main.id
2626
}
2727
28-
# Accept the request.
28+
# Accept the request (Cedar generation - supports peering connections).
2929
resource "heroku_space_peering_connection_accepter" "accept" {
3030
space = heroku_space.peer_space.id
3131
vpc_peering_connection_id = aws_vpc_peering_connection.request.id
32+
generation = "cedar"
3233
}
3334
```
3435

@@ -38,10 +39,12 @@ The following arguments are supported:
3839

3940
* `space` - (Required) The ID of the space.
4041
* `vpc_peering_connection_id` - (Required) The peering connection request ID.
42+
* `generation` - (Optional) Generation of the space for peering connection. Valid values are `cedar` and `fir`. Defaults to `cedar` for backward compatibility. **ForceNew**. Note: Peering connections are not supported for `fir` generation spaces.
4143

4244
## Attributes Reference
4345

4446
The following attributes are exported:
4547

4648
* `status` - The status of the peering connection request.
4749
* `type` - The type of the peering connection.
50+
* `generation` - Generation of the space for peering connection.

heroku/resource_heroku_space_peering_connection_accepter.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1010
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1112
heroku "github.com/heroku/heroku-go/v6"
1213
)
1314

@@ -21,6 +22,8 @@ func resourceHerokuSpacePeeringConnectionAccepter() *schema.Resource {
2122
Read: resourceHerokuSpacePeeringConnectionAccepterRead,
2223
Delete: resourceHerokuSpacePeeringConnectionAccepterDelete,
2324

25+
CustomizeDiff: resourceHerokuSpacePeeringConnectionAccepterCustomizeDiff,
26+
2427
Importer: &schema.ResourceImporter{
2528
StateContext: resourceHerokuSpacePeeringConnectionAccepterImport,
2629
},
@@ -32,6 +35,15 @@ func resourceHerokuSpacePeeringConnectionAccepter() *schema.Resource {
3235
ForceNew: true,
3336
},
3437

38+
"generation": {
39+
Type: schema.TypeString,
40+
Optional: true,
41+
Default: "cedar",
42+
ForceNew: true,
43+
ValidateFunc: validation.StringInSlice([]string{"cedar", "fir"}, false),
44+
Description: "Generation of the space for peering connection. Defaults to cedar for backward compatibility.",
45+
},
46+
3547
"status": {
3648
Type: schema.TypeString,
3749
Computed: true,
@@ -171,3 +183,16 @@ func SpacePeeringConnAccepterStateRefreshFunc(client *heroku.Service, spaceIdent
171183
return &pcx, peeringConn.Status, nil
172184
}
173185
}
186+
187+
func resourceHerokuSpacePeeringConnectionAccepterCustomizeDiff(ctx context.Context, diff *schema.ResourceDiff, v interface{}) error {
188+
generation, generationExists := diff.GetOk("generation")
189+
190+
if generationExists {
191+
generationStr := generation.(string)
192+
193+
if !IsFeatureSupported(generationStr, "space", "peering_connection") {
194+
return fmt.Errorf("peering connections are not supported for %s generation spaces", generationStr)
195+
}
196+
}
197+
return nil
198+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package heroku
2+
3+
import (
4+
"testing"
5+
)
6+
7+
// Unit tests for peering connection generation support
8+
func TestHerokuSpacePeeringConnectionAccepterGeneration(t *testing.T) {
9+
tests := []struct {
10+
name string
11+
generation string
12+
expectError bool
13+
description string
14+
}{
15+
{name: "Cedar generation should be supported", generation: "cedar", expectError: false, description: "Cedar supports peering connections"},
16+
{name: "Fir generation should be unsupported", generation: "fir", expectError: true, description: "Fir does not support peering connections"},
17+
{name: "Default generation (cedar) should be supported", generation: "", expectError: false, description: "Default cedar generation supports peering connections"},
18+
}
19+
20+
for _, tt := range tests {
21+
t.Run(tt.name, func(t *testing.T) {
22+
generation := tt.generation
23+
if generation == "" {
24+
generation = "cedar"
25+
}
26+
supported := IsFeatureSupported(generation, "space", "peering_connection")
27+
shouldError := !supported
28+
if shouldError != tt.expectError {
29+
t.Errorf("Expected error: %t, but got: %t for generation %s", tt.expectError, shouldError, generation)
30+
}
31+
t.Logf("✅ Generation: %s, Supported: %t, ShouldError: %t", generation, supported, shouldError)
32+
})
33+
}
34+
}

0 commit comments

Comments
 (0)