Skip to content

Commit

Permalink
feat: add TypeSet support (#1171)
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov authored May 17, 2023
1 parent 2e06814 commit 7643631
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ nav_order: 1

## [MAJOR.MINOR.PATCH] - YYYY-MM-DD

- Set `TypeSet` for `user_peer_network_cidrs` field

## [4.3.0] - 2023-05-10

- Added docs and validation for `aiven_service_integration_endpoint`
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/transit_gateway_vpc_attachment.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ data "aiven_transit_gateway_vpc_attachment" "attachment" {
- `peering_connection_id` (String) Cloud provider identifier for the peering connection if available
- `state` (String) State of the peering connection
- `state_info` (Map of String) State-specific help or error information
- `user_peer_network_cidrs` (List of String) List of private IPv4 ranges to route through the peering connection
- `user_peer_network_cidrs` (Set of String) List of private IPv4 ranges to route through the peering connection


2 changes: 1 addition & 1 deletion docs/resources/transit_gateway_vpc_attachment.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ resource "aiven_transit_gateway_vpc_attachment" "attachment" {
- `peer_cloud_account` (String) AWS account ID or GCP project ID of the peered VPC. This property cannot be changed, doing so forces recreation of the resource.
- `peer_region` (String) AWS region of the peered VPC (if not in the same region as Aiven VPC)
- `peer_vpc` (String) Transit gateway ID. This property cannot be changed, doing so forces recreation of the resource.
- `user_peer_network_cidrs` (List of String) List of private IPv4 ranges to route through the peering connection
- `user_peer_network_cidrs` (Set of String) List of private IPv4 ranges to route through the peering connection
- `vpc_id` (String) The VPC the peering connection belongs to. To set up proper dependencies please refer to this variable as a reference. This property cannot be changed, doing so forces recreation of the resource.

### Optional
Expand Down
3 changes: 2 additions & 1 deletion internal/schemautil/schemautil.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ func EmptyObjectDiffSuppressFunc(k, old, new string, d *schema.ResourceData) boo
func EmptyObjectDiffSuppressFuncSkipArrays(s map[string]*schema.Schema) schema.SchemaDiffSuppressFunc {
var skipKeys []string
for key, sh := range s {
if sh.Type == schema.TypeList {
switch sh.Type {
case schema.TypeList, schema.TypeSet:
skipKeys = append(skipKeys, key)
}
}
Expand Down
7 changes: 7 additions & 0 deletions internal/schemautil/userconfig/apiconvert/fromapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package apiconvert
import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig"
)

Expand Down Expand Up @@ -190,6 +192,11 @@ func propsFromAPI(n string, r map[string]interface{}, p map[string]interface{})
}

vrs = l

switch k {
case "user_peer_network_cidrs":
vrs = schema.NewSet(schema.HashString, l)
}
}
case "object":
vra, ok := vr.(map[string]interface{})
Expand Down
9 changes: 8 additions & 1 deletion internal/schemautil/userconfig/apiconvert/toapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"regexp"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig"
)

Expand Down Expand Up @@ -268,7 +270,12 @@ func itemToAPI(

va, ok := v.([]interface{})
if !ok {
return nil, false, fmt.Errorf("%s: not a slice", fks)
// This can be TypeSet
set, ok := v.(*schema.Set)
if !ok {
return nil, false, fmt.Errorf("%s: not slice or set", fks)
}
va = set.List()
}

if va == nil || o {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"

"github.com/aiven/aiven-go-client"
"github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/aiven/terraform-provider-aiven/internal/schemautil"
"github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig"
)

var aivenTransitGatewayVPCAttachmentSchema = map[string]*schema.Schema{
Expand All @@ -32,7 +32,7 @@ var aivenTransitGatewayVPCAttachmentSchema = map[string]*schema.Schema{
},
"user_peer_network_cidrs": {
Required: true,
Type: schema.TypeList,
Type: schema.TypeSet,
Description: "List of private IPv4 ranges to route through the peering connection",
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down

0 comments on commit 7643631

Please sign in to comment.