Skip to content

Commit

Permalink
feat(alloydbomni): add service and dependant resources
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Nov 20, 2024
1 parent aaf3888 commit fe0f10f
Show file tree
Hide file tree
Showing 19 changed files with 2,937 additions and 29 deletions.
25 changes: 1 addition & 24 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,7 @@ jobs:
fail-fast: false
matrix:
pkg: [
kafka,
kafkatopic,
kafkaschema,
account,
cassandra,
clickhouse,
connectionpool,
flink,
pg,
grafana,
influxdb,
m3db,
mysql,
opensearch,
organization,
project,
redis,
servicecomponent,
staticip,
serviceintegration,
vpc,
dragonfly,
thanos,
valkey
alloydbomni
]

steps:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ nav_order: 1

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

- Add `alloydbomni`, `aiven_alloydbomni_user`, `aiven_alloydbomni_database` BETA resources and datasources
- Add `aiven_opensearch` resource field `opensearch_user_config.opensearch.search_insights_top_queries`
- Add `aiven_thanos` resource field `thanos_user_config.private_access`: Allow access to selected service ports from
private networks
Expand Down
3 changes: 2 additions & 1 deletion internal/schemautil/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func DefaultResourceTimeouts() *schema.ResourceTimeout {
}

const (
ServiceTypeAlloyDBOmni = "alloydbomni"
ServiceTypePG = "pg"
ServiceTypeCassandra = "cassandra"
ServiceTypeOpenSearch = "opensearch"
Expand Down Expand Up @@ -826,7 +827,7 @@ func copyConnectionInfoFromAPIResponseToTerraform(
setProp(props, "connect_uri", connectionInfo.KafkaConnectUri)
setProp(props, "rest_uri", connectionInfo.KafkaRestUri)
setProp(props, "schema_registry_uri", connectionInfo.SchemaRegistryUri)
case ServiceTypePG:
case ServiceTypeAlloyDBOmni, ServiceTypePG:
// For compatibility with the old schema, we only set the first URI.
// TODO: Remove this block in the next major version. Keep `uris` key only, see below.
if len(connectionInfo.Pg) > 0 {
Expand Down
2 changes: 1 addition & 1 deletion internal/schemautil/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func grafanaReady(s *service.ServiceGetOut) bool {

func backupsReady(s *service.ServiceGetOut) bool {
switch s.ServiceType {
case ServiceTypePG, ServiceTypeInfluxDB, ServiceTypeRedis, ServiceTypeDragonfly:
case ServiceTypeAlloyDBOmni, ServiceTypePG, ServiceTypeInfluxDB, ServiceTypeRedis, ServiceTypeDragonfly:
// See https://github.com/aiven/terraform-provider-aiven/issues/756
switch "off" {
case s.UserConfig["redis_persistence"], s.UserConfig["dragonfly_persistence"]:
Expand Down
20 changes: 19 additions & 1 deletion internal/sdkprovider/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/aiven/terraform-provider-aiven/internal/plugin/util"
"github.com/aiven/terraform-provider-aiven/internal/schemautil/userconfig"
"github.com/aiven/terraform-provider-aiven/internal/sdkprovider/service/account"
"github.com/aiven/terraform-provider-aiven/internal/sdkprovider/service/alloydbomni"
"github.com/aiven/terraform-provider-aiven/internal/sdkprovider/service/cassandra"
"github.com/aiven/terraform-provider-aiven/internal/sdkprovider/service/clickhouse"
"github.com/aiven/terraform-provider-aiven/internal/sdkprovider/service/connectionpool"
Expand Down Expand Up @@ -77,6 +78,11 @@ func Provider(version string) (*schema.Provider, error) {
"aiven_pg_user": pg.DatasourcePGUser(),
"aiven_pg_database": pg.DatasourcePGDatabase(),

// alloydbomni
"aiven_alloydbomni": alloydbomni.DatasourceAlloyDBOmni(),
"aiven_alloydbomni_user": alloydbomni.DatasourceAlloyDBOmniUser(),
"aiven_alloydbomni_database": alloydbomni.DatasourceAlloyDBOmniDatabase(),

// cassandra
"aiven_cassandra": cassandra.DatasourceCassandra(),
"aiven_cassandra_user": cassandra.DatasourceCassandraUser(),
Expand Down Expand Up @@ -186,6 +192,11 @@ func Provider(version string) (*schema.Provider, error) {
"aiven_pg_user": pg.ResourcePGUser(),
"aiven_pg_database": pg.ResourcePGDatabase(),

// alloydbomni
"aiven_alloydbomni": alloydbomni.ResourceAlloyDBOmni(),
"aiven_alloydbomni_user": alloydbomni.ResourceAlloyDBOmniUser(),
"aiven_alloydbomni_database": alloydbomni.ResourceAlloyDBOmniDatabase(),

// cassandra
"aiven_cassandra": cassandra.ResourceCassandra(),
"aiven_cassandra_user": cassandra.ResourceCassandraUser(),
Expand Down Expand Up @@ -277,9 +288,16 @@ func Provider(version string) (*schema.Provider, error) {
}

// Adds "beta" warning to the description
betaResources := []string{}
betaResources := []string{
"aiven_alloydbomni",
"aiven_alloydbomni_user",
"aiven_alloydbomni_database",
}

betaDataSources := []string{
"aiven_alloydbomni",
"aiven_alloydbomni_user",
"aiven_alloydbomni_database",
"aiven_organization_user_list",
}

Expand Down
192 changes: 192 additions & 0 deletions internal/sdkprovider/service/alloydbomni/alloydbomni.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
package alloydbomni

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

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

func aivenAlloyDBOmniSchema() map[string]*schema.Schema {
s := schemautil.ServiceCommonSchemaWithUserConfig(schemautil.ServiceTypeAlloyDBOmni)
s[schemautil.ServiceTypeAlloyDBOmni] = &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Computed: true,
Description: "Values provided by the AlloyDB Omni server.",
Optional: true,
Sensitive: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
// TODO: Remove `uri` in the next major version.
"uri": {
Type: schema.TypeString,
Computed: true,
Description: "AlloyDB Omni primary connection URI.",
Optional: true,
Sensitive: true,
},
"uris": {
Type: schema.TypeList,
Computed: true,
Description: "AlloyDB Omni primary connection URIs.",
Optional: true,
Sensitive: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Sensitive: true,
},
},
"bouncer": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "PgBouncer connection details for [connection pooling](https://aiven.io/docs/products/postgresql/concepts/pg-connection-pooling).",
Deprecated: "This field was added by mistake and has never worked. It will be removed in future versions.",
},
// TODO: Remove `host` in the next major version.
"host": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "AlloyDB Omni primary node host IP or name.",
},
// TODO: Remove `port` in the next major version.
"port": {
Type: schema.TypeInt,
Computed: true,
Sensitive: true,
Description: "AlloyDB Omni port.",
},
// TODO: Remove `sslmode` in the next major version.
"sslmode": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "AlloyDB Omni SSL mode setting.",
},
// TODO: Remove `user` in the next major version.
"user": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "AlloyDB Omni admin user name.",
},
// TODO: Remove `password` in the next major version.
"password": {
Type: schema.TypeString,
Computed: true,
Description: "AlloyDB Omni admin user password.",
Sensitive: true,
},
// TODO: Remove `dbname` in the next major version.
"dbname": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "Primary AlloyDB Omni database name.",
},
"params": {
Type: schema.TypeList,
Computed: true,
Description: "AlloyDB Omni connection parameters.",
Optional: true,
Sensitive: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"host": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "AlloyDB Omni host IP or name.",
},
"port": {
Type: schema.TypeInt,
Computed: true,
Sensitive: true,
Description: "AlloyDB Omni port.",
},
"sslmode": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "AlloyDB Omni SSL mode setting.",
},
"user": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "AlloyDB Omni admin user name.",
},
"password": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "AlloyDB Omni admin user password.",
},
"database_name": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
Description: "Primary AlloyDB Omni database name.",
},
},
},
},
"replica_uri": {
Type: schema.TypeString,
Computed: true,
Description: "AlloyDB Omni replica URI for services with a replica.",
Sensitive: true,
},
"standby_uris": {
Type: schema.TypeList,
Computed: true,
Description: "AlloyDB Omni standby connection URIs.",
Optional: true,
Sensitive: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Sensitive: true,
},
},
"syncing_uris": {
Type: schema.TypeList,
Computed: true,
Description: "AlloyDB Omni syncing connection URIs.",
Optional: true,
Sensitive: true,
Elem: &schema.Schema{
Type: schema.TypeString,
Sensitive: true,
},
},
// TODO: This isn't in the connection info, but it's in the metadata.
// We should move this to the other part of the schema in the next major version.
"max_connections": {
Type: schema.TypeInt,
Computed: true,
Sensitive: true,
Description: "The [number of allowed connections](https://aiven.io/docs/products/postgresql/reference/pg-connection-limits). Varies based on the service plan.",
},
},
},
}
return s
}

func ResourceAlloyDBOmni() *schema.Resource {
return &schema.Resource{
Description: "Creates and manages an Aiven for AlloyDB Omni service.",
CreateContext: schemautil.ResourceServiceCreateWrapper(schemautil.ServiceTypeAlloyDBOmni),
ReadContext: schemautil.ResourceServiceRead,
UpdateContext: schemautil.ResourceServiceUpdate,
DeleteContext: schemautil.ResourceServiceDelete,
CustomizeDiff: schemautil.CustomizeDiffGenericService(schemautil.ServiceTypeAlloyDBOmni),
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: schemautil.DefaultResourceTimeouts(),
Schema: aivenAlloyDBOmniSchema(),
SchemaVersion: 1,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package alloydbomni

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

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

func DatasourceAlloyDBOmni() *schema.Resource {
return &schema.Resource{
ReadContext: schemautil.DatasourceServiceRead,
Description: "Gets information about an Aiven for AlloyDB Omni service.",
Schema: schemautil.ResourceSchemaAsDatasourceSchema(aivenAlloyDBOmniSchema(), "project", "service_name"),
}
}
Loading

0 comments on commit fe0f10f

Please sign in to comment.