Skip to content

Commit

Permalink
refactor: use code-generated enums (#1894)
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov authored Nov 12, 2024
1 parent ac1a35a commit 3174ef3
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 61 deletions.
2 changes: 1 addition & 1 deletion docs/data-sources/mirrormaker_replication_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data "aiven_mirrormaker_replication_flow" "f1" {
- `emit_heartbeats_enabled` (Boolean) Whether to emit heartbeats to the target cluster. The default value is `false`.
- `enable` (Boolean) Enable of disable replication flows for a service.
- `id` (String) The ID of this resource.
- `offset_syncs_topic_location` (String) Offset syncs topic location. Possible values are `source` & `target`. There is no default value.
- `offset_syncs_topic_location` (String) Offset syncs topic location. The possible values are `source` and `target`.
- `replication_factor` (Number) Replication factor, `>= 1`.
- `replication_policy_class` (String) Replication policy class. The possible values are `org.apache.kafka.connect.mirror.DefaultReplicationPolicy` and `org.apache.kafka.connect.mirror.IdentityReplicationPolicy`. The default value is `org.apache.kafka.connect.mirror.DefaultReplicationPolicy`.
- `sync_group_offsets_enabled` (Boolean) Sync consumer group offsets. The default value is `false`.
Expand Down
6 changes: 3 additions & 3 deletions docs/data-sources/service_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ data "aiven_service_component" "sc1" {

### Optional

- `kafka_authentication_method` (String) Kafka authentication method. This is a value specific to the 'kafka' service component
- `route` (String) Network access route
- `kafka_authentication_method` (String) Kafka authentication method. This is a value specific to the 'kafka' service component. The possible values are `certificate` and `sasl`.
- `route` (String) Network access route. The possible values are `dynamic`, `public`, `private` and `privatelink`.
- `service_name` (String) Service name
- `ssl` (Boolean) Whether the endpoint is encrypted or accepts plaintext. By default endpoints are always encrypted and this property is only included for service components that may disable encryption
- `usage` (String) DNS usage name
- `usage` (String) DNS usage name. The possible values are `disaster_recovery`, `primary` and `replica`.

### Read-Only

Expand Down
8 changes: 4 additions & 4 deletions docs/resources/kafka_topic.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ resource "aiven_kafka_topic" "example_topic" {

Optional:

- `cleanup_policy` (String) cleanup.policy value
- `compression_type` (String) compression.type value
- `cleanup_policy` (String) cleanup.policy value. The possible values are `delete`, `compact` and `compact,delete`.
- `compression_type` (String) compression.type value. The possible values are `snappy`, `gzip`, `lz4`, `producer`, `uncompressed` and `zstd`.
- `delete_retention_ms` (String) delete.retention.ms value
- `file_delete_delay_ms` (String) file.delete.delay.ms value
- `flush_messages` (String) flush.messages value
Expand All @@ -76,9 +76,9 @@ Optional:
- `max_compaction_lag_ms` (String) max.compaction.lag.ms value
- `max_message_bytes` (String) max.message.bytes value
- `message_downconversion_enable` (Boolean) message.downconversion.enable value
- `message_format_version` (String) message.format.version value
- `message_format_version` (String) message.format.version value. The possible values are `0.8.0`, `0.8.1`, `0.8.2`, `0.9.0`, `0.10.0`, `0.10.0-IV0`, `0.10.0-IV1`, `0.10.1`, `0.10.1-IV0`, `0.10.1-IV1`, `0.10.1-IV2`, `0.10.2`, `0.10.2-IV0`, `0.11.0`, `0.11.0-IV0`, `0.11.0-IV1`, `0.11.0-IV2`, `1.0`, `1.0-IV0`, `1.1`, `1.1-IV0`, `2.0`, `2.0-IV0`, `2.0-IV1`, `2.1`, `2.1-IV0`, `2.1-IV1`, `2.1-IV2`, `2.2`, `2.2-IV0`, `2.2-IV1`, `2.3`, `2.3-IV0`, `2.3-IV1`, `2.4`, `2.4-IV0`, `2.4-IV1`, `2.5`, `2.5-IV0`, `2.6`, `2.6-IV0`, `2.7`, `2.7-IV0`, `2.7-IV1`, `2.7-IV2`, `2.8`, `2.8-IV0`, `2.8-IV1`, `3.0`, `3.0-IV0`, `3.0-IV1`, `3.1`, `3.1-IV0`, `3.2`, `3.2-IV0`, `3.3`, `3.3-IV0`, `3.3-IV1`, `3.3-IV2`, `3.3-IV3`, `3.4`, `3.4-IV0`, `3.5`, `3.5-IV0`, `3.5-IV1`, `3.5-IV2`, `3.6`, `3.6-IV0`, `3.6-IV1`, `3.6-IV2`, `3.7`, `3.7-IV0`, `3.7-IV1`, `3.7-IV2`, `3.7-IV3`, `3.7-IV4`, `3.8`, `3.8-IV0`, `3.9`, `3.9-IV0` and `3.9-IV1`.
- `message_timestamp_difference_max_ms` (String) message.timestamp.difference.max.ms value
- `message_timestamp_type` (String) message.timestamp.type value
- `message_timestamp_type` (String) message.timestamp.type value. The possible values are `CreateTime` and `LogAppendTime`.
- `min_cleanable_dirty_ratio` (Number) min.cleanable.dirty.ratio value
- `min_compaction_lag_ms` (String) min.compaction.lag.ms value
- `min_insync_replicas` (String) min.insync.replicas value
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/mirrormaker_replication_flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ resource "aiven_mirrormaker_replication_flow" "f1" {
### Required

- `enable` (Boolean) Enable of disable replication flows for a service.
- `offset_syncs_topic_location` (String) Offset syncs topic location. Possible values are `source` & `target`. There is no default value.
- `offset_syncs_topic_location` (String) Offset syncs topic location. The possible values are `source` and `target`.
- `project` (String) The name of the project this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
- `replication_policy_class` (String) Replication policy class. The possible values are `org.apache.kafka.connect.mirror.DefaultReplicationPolicy` and `org.apache.kafka.connect.mirror.IdentityReplicationPolicy`. The default value is `org.apache.kafka.connect.mirror.DefaultReplicationPolicy`.
- `service_name` (String) The name of the project this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var aivenAccountAuthenticationSchema = map[string]*schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"internal", "saml"}, false),
ValidateFunc: validation.StringInSlice(accountauthentication.AuthenticationMethodTypeChoices(), false),
Description: userconfig.Desc("The account authentication type.").PossibleValuesString(accountauthentication.AuthenticationMethodTypeChoices()...).Build(),
},
"enabled": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var aivenAccountTeamProjectSchema = map[string]*schema.Schema{
"team_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"admin", "developer", "operator", "read_only"}, false),
ValidateFunc: validation.StringInSlice(account.TeamTypeChoices(), false),
Description: userconfig.Desc("The Account team project type").PossibleValuesString(account.TeamTypeChoices()...).Build(),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ var aivenConnectionPoolSchema = map[string]*schema.Schema{
"pool_mode": {
Type: schema.TypeString,
Optional: true,
Default: "transaction",
ValidateFunc: validation.StringInSlice([]string{"session", "transaction", "statement"}, false),
Description: userconfig.Desc("The [operational mode](https://aiven.io/docs/products/postgresql/concepts/pg-connection-pooling#pooling-modes).").DefaultValue("transaction").PossibleValuesString(service.PoolModeTypeChoices()...).Build(),
Default: service.PoolModeTypeTransaction,
ValidateFunc: validation.StringInSlice(service.PoolModeTypeChoices(), false),
Description: userconfig.Desc("The [operational mode](https://aiven.io/docs/products/postgresql/concepts/pg-connection-pooling#pooling-modes).").DefaultValue(service.PoolModeTypeTransaction).PossibleValuesString(service.PoolModeTypeChoices()...).Build(),
},
"pool_name": {
Type: schema.TypeString,
Expand Down
2 changes: 1 addition & 1 deletion internal/sdkprovider/service/kafka/kafka_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var aivenKafkaACLSchema = map[string]*schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"admin", "read", "readwrite", "write"}, false),
ValidateFunc: validation.StringInSlice(kafka.PermissionTypeChoices(), false),
Description: userconfig.Desc("Permissions to grant.").ForceNew().PossibleValuesString(kafka.PermissionTypeChoices()...).Build(),
},
"topic": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ var aivenMirrorMakerReplicationFlowSchema = map[string]*schema.Schema{
"offset_syncs_topic_location": {
Type: schema.TypeString,
Required: true,
Description: "Offset syncs topic location. Possible values are `source` & `target`. There is no default value.",
ValidateFunc: validation.StringInSlice([]string{"source", "target"}, false),
ValidateFunc: validation.StringInSlice(kafkamirrormaker.OffsetSyncsTopicLocationTypeChoices(), false),
Description: userconfig.Desc("Offset syncs topic location").PossibleValuesString(kafkamirrormaker.OffsetSyncsTopicLocationTypeChoices()...).Build(),
},
"config_properties_exclude": {
Type: schema.TypeSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var aivenKafkaSchemaRegistryACLSchema = map[string]*schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"schema_registry_read", "schema_registry_write"}, false),
ValidateFunc: validation.StringInSlice(kafkaschemaregistry.PermissionTypeChoices(), false),
Description: userconfig.Desc("Kafka Schema Registry permission to grant.").ForceNew().PossibleValuesString(kafkaschemaregistry.PermissionTypeChoices()...).Build(),
},
"resource": {
Expand Down
29 changes: 17 additions & 12 deletions internal/sdkprovider/service/kafkatopic/kafka_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strconv"

"github.com/aiven/aiven-go-client/v2"
"github.com/aiven/go-client-codegen/handler/kafkatopic"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand All @@ -29,14 +30,16 @@ var (

var aivenKafkaTopicConfigSchema = map[string]*schema.Schema{
"cleanup_policy": {
Type: schema.TypeString,
Description: "cleanup.policy value",
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(kafkatopic.CleanupPolicyTypeChoices(), false),
Description: userconfig.Desc("cleanup.policy value").PossibleValuesString(kafkatopic.CleanupPolicyTypeChoices()...).Build(),
},
"compression_type": {
Type: schema.TypeString,
Description: "compression.type value",
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(kafkatopic.CompressionTypeChoices(), false),
Description: userconfig.Desc("compression.type value").PossibleValuesString(kafkatopic.CompressionTypeChoices()...).Build(),
},
"delete_retention_ms": {
Type: schema.TypeString,
Expand Down Expand Up @@ -79,19 +82,21 @@ var aivenKafkaTopicConfigSchema = map[string]*schema.Schema{
Optional: true,
},
"message_format_version": {
Type: schema.TypeString,
Description: "message.format.version value",
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(kafkatopic.MessageFormatVersionTypeChoices(), false),
Description: userconfig.Desc("message.format.version value").PossibleValuesString(kafkatopic.MessageFormatVersionTypeChoices()...).Build(),
},
"message_timestamp_difference_max_ms": {
Type: schema.TypeString,
Description: "message.timestamp.difference.max.ms value",
Optional: true,
},
"message_timestamp_type": {
Type: schema.TypeString,
Description: "message.timestamp.type value",
Optional: true,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(kafkatopic.MessageTimestampTypeChoices(), false),
Description: userconfig.Desc("message.timestamp.type value").PossibleValuesString(kafkatopic.MessageTimestampTypeChoices()...).Build(),
},
"min_cleanable_dirty_ratio": {
Type: schema.TypeFloat,
Expand Down
2 changes: 1 addition & 1 deletion internal/sdkprovider/service/mysql/mysql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var aivenMySQLUserSchema = map[string]*schema.Schema{
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: schemautil.EmptyObjectDiffSuppressFunc,
ValidateFunc: validation.StringInSlice([]string{"caching_sha2_password", "mysql_native_password"}, false),
ValidateFunc: validation.StringInSlice(service.AuthenticationTypeChoices(), false),
Description: userconfig.Desc("Authentication details.").PossibleValuesString(service.AuthenticationTypeChoices()...).Build(),
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var aivenOpenSearchACLRuleSchema = map[string]*schema.Schema{
"permission": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"deny", "admin", "read", "readwrite", "write"}, false),
ValidateFunc: validation.StringInSlice(opensearch.PermissionTypeChoices(), false),
Description: userconfig.Desc("The permissions for this ACL entry").PossibleValuesString(opensearch.PermissionTypeChoices()...).Build(),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/aiven/go-client-codegen/handler/account"
"github.com/aiven/go-client-codegen/handler/organization"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/aiven/terraform-provider-aiven/internal/common"
"github.com/aiven/terraform-provider-aiven/internal/schemautil"
Expand All @@ -20,9 +21,10 @@ var aivenOrganizationalPermissionSchema = map[string]*schema.Schema{
Required: true,
},
"resource_type": {
Type: schema.TypeString,
Required: true,
Description: userconfig.Desc("Resource type.").PossibleValuesString("project").Build(),
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(organization.ResourceTypeChoices(), false),
Description: userconfig.Desc("Resource type.").PossibleValuesString(organization.ResourceTypeChoices()...).Build(),
},
"resource_id": {
Type: schema.TypeString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"strconv"

"github.com/aiven/aiven-go-client/v2"
"github.com/aiven/go-client-codegen/handler/service"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

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

func DatasourceServiceComponent() *schema.Resource {
Expand All @@ -31,7 +33,7 @@ func DatasourceServiceComponent() *schema.Resource {
Type: schema.TypeString,
Required: true,
Description: "Service component name",
ValidateFunc: validation.StringInSlice([]string{
ValidateFunc: validation.StringInSlice([]string{ // fixme: choices are missing from the schema
"cassandra",
"elasticsearch",
"grafana",
Expand All @@ -52,24 +54,16 @@ func DatasourceServiceComponent() *schema.Resource {
}, false),
},
"route": {
Type: schema.TypeString,
Optional: true,
Description: "Network access route",
ValidateFunc: validation.StringInSlice([]string{
"dynamic",
"public",
"private",
"privatelink",
}, false),
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(service.RouteTypeChoices(), false),
Description: userconfig.Desc("Network access route").PossibleValuesString(service.RouteTypeChoices()...).Build(),
},
"kafka_authentication_method": {
Type: schema.TypeString,
Optional: true,
Description: "Kafka authentication method. This is a value specific to the 'kafka' service component",
ValidateFunc: validation.StringInSlice([]string{
"certificate",
"sasl",
}, false),
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(service.KafkaAuthenticationMethodTypeChoices(), false),
Description: userconfig.Desc("Kafka authentication method. This is a value specific to the 'kafka' service component").PossibleValuesString(service.KafkaAuthenticationMethodTypeChoices()...).Build(),
},
"ssl": {
Type: schema.TypeBool,
Expand All @@ -79,15 +73,11 @@ func DatasourceServiceComponent() *schema.Resource {
"disable encryption",
},
"usage": {
Type: schema.TypeString,
Optional: true,
Description: "DNS usage name",
Default: "primary",
ValidateFunc: validation.StringInSlice([]string{
"primary",
"replica",
"syncing",
}, false),
Type: schema.TypeString,
Optional: true,
Default: "primary",
ValidateFunc: validation.StringInSlice(service.UsageTypeChoices(), false),
Description: userconfig.Desc("DNS usage name").PossibleValuesString(service.UsageTypeChoices()...).Build(),
},
"host": {
Type: schema.TypeString,
Expand Down

0 comments on commit 3174ef3

Please sign in to comment.