Skip to content

Commit

Permalink
refactor: use code-generated enums
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Nov 12, 2024
1 parent ac1a35a commit 7080505
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 45 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
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
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 7080505

Please sign in to comment.