Skip to content

Commit

Permalink
fix(aiven_service_integration_endpoint): can't create external_postgr…
Browse files Browse the repository at this point in the history
…esql
  • Loading branch information
byashimov committed Mar 15, 2024
1 parent f5dc3ed commit a9f0bae
Show file tree
Hide file tree
Showing 21 changed files with 167 additions and 123 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ nav_order: 1
- Add `external_aws_cloudwatch_logs`, `external_elasticsearch_logs_user_config`, `external_opensearch_logs_user_config`,
`prometheus_user_config` service integration configs
- Fix `aiven_kafka_schema` Protobuf normalization
- Fix `aiven_service_integration_endpoint` for `external_postgresql` type
- Add `AIVEN_ALLOW_IP_FILTER_PURGE` environment variable to allow purging of IP filters. This is a safety feature to
prevent accidental purging of IP filters, which can lead to loss of access to services. To enable purging, set the
environment variable to any value before running Terraform commands.
Expand Down
21 changes: 11 additions & 10 deletions internal/schemautil/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/converters"
"github.com/aiven/terraform-provider-aiven/internal/sdkprovider/userconfig/service"
)

// defaultTimeout is the default timeout for service operations. This is not a const because it can be changed during
Expand Down Expand Up @@ -61,6 +60,12 @@ var TechEmailsResourceSchema = &schema.Resource{
},
}

func ServiceCommonSchemaWithUserConfig(kind string) map[string]*schema.Schema {
s := ServiceCommonSchema()
converters.SetUserConfig(converters.ServiceUserConfig, kind, s)
return s
}

func ServiceCommonSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"project": CommonSchemaProjectReference,
Expand Down Expand Up @@ -713,15 +718,11 @@ func copyServicePropertiesFromAPIResponseToTerraform(
}
}

newUserConfig, err := FlattenService(serviceType, d, s.UserConfig)
err := FlattenService(serviceType, d, s.UserConfig)
if err != nil {
return err
}

if err := d.Set(serviceType+"_user_config", newUserConfig); err != nil {
return fmt.Errorf("cannot set `%s_user_config` : %w; Please make sure that all Aiven services have unique s names", serviceType, err)
}

params := s.URIParams
if err := d.Set("service_host", params["host"]); err != nil {
return err
Expand Down Expand Up @@ -886,10 +887,10 @@ func getContactEmailListForAPI(d *schema.ResourceData, field string) *[]aiven.Co
return &results
}

func ExpandService(kind string, d *schema.ResourceData) (map[string]any, error) {
return converters.Expand(kind, service.GetUserConfig(kind), d)
func ExpandService(name string, d *schema.ResourceData) (map[string]any, error) {
return converters.Expand(converters.ServiceUserConfig, name, d)
}

func FlattenService(kind string, d *schema.ResourceData, dto map[string]any) ([]map[string]any, error) {
return converters.Flatten(kind, service.GetUserConfig(kind), d, dto)
func FlattenService(name string, d *schema.ResourceData, dto map[string]any) error {
return converters.Flatten(converters.ServiceUserConfig, name, d, dto)
}
5 changes: 1 addition & 4 deletions internal/sdkprovider/service/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (

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

func cassandraSchema() map[string]*schema.Schema {
s := schemautil.ServiceCommonSchema()
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeCassandra)
s[schemautil.ServiceTypeCassandra] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand All @@ -19,8 +18,6 @@ func cassandraSchema() map[string]*schema.Schema {
Schema: map[string]*schema.Schema{},
},
}
s[schemautil.ServiceTypeCassandra+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeCassandra)

return s
}

Expand Down
4 changes: 1 addition & 3 deletions internal/sdkprovider/service/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

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

func clickhouseSchema() map[string]*schema.Schema {
s := schemautil.ServiceCommonSchema()
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeClickhouse)
s[schemautil.ServiceTypeClickhouse] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand All @@ -18,7 +17,6 @@ func clickhouseSchema() map[string]*schema.Schema {
Schema: map[string]*schema.Schema{},
},
}
s[schemautil.ServiceTypeClickhouse+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeClickhouse)
s["service_integrations"] = &schema.Schema{
Type: schema.TypeList,
Optional: true,
Expand Down
5 changes: 1 addition & 4 deletions internal/sdkprovider/service/dragonfly/dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"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/dist"
)

func dragonflySchema() map[string]*schema.Schema {
s := schemautil.ServiceCommonSchema()
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeDragonfly)
s[schemautil.ServiceTypeDragonfly] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand All @@ -18,8 +17,6 @@ func dragonflySchema() map[string]*schema.Schema {
Schema: map[string]*schema.Schema{},
},
}
s[schemautil.ServiceTypeDragonfly+"_user_config"] = dist.ServiceTypeDragonfly()

return s
}

Expand Down
5 changes: 1 addition & 4 deletions internal/sdkprovider/service/flink/flink.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import (

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

func aivenFlinkSchema() map[string]*schema.Schema {
aivenFlinkSchema := schemautil.ServiceCommonSchema()
aivenFlinkSchema := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeFlink)
aivenFlinkSchema[schemautil.ServiceTypeFlink] = &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Expand All @@ -35,8 +34,6 @@ func aivenFlinkSchema() map[string]*schema.Schema {
},
},
}
aivenFlinkSchema[schemautil.ServiceTypeFlink+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeFlink)

return aivenFlinkSchema
}

Expand Down
4 changes: 1 addition & 3 deletions internal/sdkprovider/service/grafana/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (

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

func grafanaSchema() map[string]*schema.Schema {
s := schemautil.ServiceCommonSchema()
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeGrafana)
s[schemautil.ServiceTypeGrafana] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand All @@ -19,7 +18,6 @@ func grafanaSchema() map[string]*schema.Schema {
Schema: map[string]*schema.Schema{},
},
}
s[schemautil.ServiceTypeGrafana+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeGrafana)
return s
}

Expand Down
5 changes: 1 addition & 4 deletions internal/sdkprovider/service/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (

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

func influxDBSchema() map[string]*schema.Schema {
s := schemautil.ServiceCommonSchema()
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeInfluxDB)
s[schemautil.ServiceTypeInfluxDB] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand All @@ -25,8 +24,6 @@ func influxDBSchema() map[string]*schema.Schema {
},
},
}
s[schemautil.ServiceTypeInfluxDB+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeInfluxDB)

return s
}

Expand Down
4 changes: 1 addition & 3 deletions internal/sdkprovider/service/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import (

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

func aivenKafkaSchema() map[string]*schema.Schema {
aivenKafkaSchema := schemautil.ServiceCommonSchema()
aivenKafkaSchema := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeKafka)
aivenKafkaSchema["karapace"] = &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -70,7 +69,6 @@ func aivenKafkaSchema() map[string]*schema.Schema {
},
},
}
aivenKafkaSchema[schemautil.ServiceTypeKafka+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeKafka)

return aivenKafkaSchema
}
Expand Down
9 changes: 3 additions & 6 deletions internal/sdkprovider/service/kafka/kafka_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import (

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

func aivenKafkaConnectSchema() map[string]*schema.Schema {
kafkaConnectSchema := schemautil.ServiceCommonSchema()
kafkaConnectSchema[schemautil.ServiceTypeKafkaConnect] = &schema.Schema{
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeKafkaConnect)
s[schemautil.ServiceTypeKafkaConnect] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Kafka Connect server provided values",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{},
},
}
kafkaConnectSchema[schemautil.ServiceTypeKafkaConnect+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeKafkaConnect)

return kafkaConnectSchema
return s
}

func ResourceKafkaConnect() *schema.Resource {
Expand Down
9 changes: 3 additions & 6 deletions internal/sdkprovider/service/kafka/kafka_mirrormaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import (

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

func aivenKafkaMirrormakerSchema() map[string]*schema.Schema {
kafkaMMSchema := schemautil.ServiceCommonSchema()
kafkaMMSchema[schemautil.ServiceTypeKafkaMirrormaker] = &schema.Schema{
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeKafkaMirrormaker)
s[schemautil.ServiceTypeKafkaMirrormaker] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "Kafka MirrorMaker 2 server provided values",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{},
},
}
kafkaMMSchema[schemautil.ServiceTypeKafkaMirrormaker+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeKafkaMirrormaker)

return kafkaMMSchema
return s
}
func ResourceKafkaMirrormaker() *schema.Resource {
return &schema.Resource{
Expand Down
9 changes: 3 additions & 6 deletions internal/sdkprovider/service/m3db/m3aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,19 @@ import (

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

func aivenM3AggregatorSchema() map[string]*schema.Schema {
schemaM3 := schemautil.ServiceCommonSchema()
schemaM3[schemautil.ServiceTypeM3Aggregator] = &schema.Schema{
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeM3Aggregator)
s[schemautil.ServiceTypeM3Aggregator] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "M3 aggregator specific server provided values",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{},
},
}
schemaM3[schemautil.ServiceTypeM3Aggregator+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeM3Aggregator)

return schemaM3
return s
}
func ResourceM3Aggregator() *schema.Resource {
return &schema.Resource{
Expand Down
5 changes: 1 addition & 4 deletions internal/sdkprovider/service/m3db/m3db.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (

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

func aivenM3DBSchema() map[string]*schema.Schema {
schemaM3 := schemautil.ServiceCommonSchema()
schemaM3 := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeM3)
schemaM3[schemautil.ServiceTypeM3] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand All @@ -19,8 +18,6 @@ func aivenM3DBSchema() map[string]*schema.Schema {
Schema: map[string]*schema.Schema{},
},
}
schemaM3[schemautil.ServiceTypeM3+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeM3)

return schemaM3
}
func ResourceM3DB() *schema.Resource {
Expand Down
5 changes: 1 addition & 4 deletions internal/sdkprovider/service/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (

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

func aivenMySQLSchema() map[string]*schema.Schema {
schemaMySQL := schemautil.ServiceCommonSchema()
schemaMySQL := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeMySQL)
schemaMySQL[schemautil.ServiceTypeMySQL] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand All @@ -19,8 +18,6 @@ func aivenMySQLSchema() map[string]*schema.Schema {
Schema: map[string]*schema.Schema{},
},
}
schemaMySQL[schemautil.ServiceTypeMySQL+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeMySQL)

return schemaMySQL
}
func ResourceMySQL() *schema.Resource {
Expand Down
5 changes: 1 addition & 4 deletions internal/sdkprovider/service/opensearch/opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (

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

func opensearchSchema() map[string]*schema.Schema {
s := schemautil.ServiceCommonSchema()
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeOpenSearch)
s[schemautil.ServiceTypeOpenSearch] = &schema.Schema{
Type: schema.TypeList,
Computed: true,
Expand All @@ -26,8 +25,6 @@ func opensearchSchema() map[string]*schema.Schema {
},
},
}
s[schemautil.ServiceTypeOpenSearch+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypeOpenSearch)

return s
}

Expand Down
9 changes: 3 additions & 6 deletions internal/sdkprovider/service/pg/pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ import (

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

func aivenPGSchema() map[string]*schema.Schema {
schemaPG := schemautil.ServiceCommonSchema()
schemaPG[schemautil.ServiceTypePG] = &schema.Schema{
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypePG)
s[schemautil.ServiceTypePG] = &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Expand Down Expand Up @@ -78,9 +77,7 @@ func aivenPGSchema() map[string]*schema.Schema {
},
},
}
schemaPG[schemautil.ServiceTypePG+"_user_config"] = service.GetUserConfig(schemautil.ServiceTypePG)

return schemaPG
return s
}

func ResourcePG() *schema.Resource {
Expand Down
Loading

0 comments on commit a9f0bae

Please sign in to comment.