Skip to content

Commit

Permalink
Merge branch 'main' into fix-lowercase-transformation-volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
T-jegou authored Nov 14, 2023
2 parents 3999cc2 + b152e95 commit d10310b
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 54 deletions.
8 changes: 8 additions & 0 deletions digitalocean/app/app_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ func appSpecRouteSchema() map[string]*schema.Schema {

func appSpecHealthCheckSchema() map[string]*schema.Schema {
return map[string]*schema.Schema{
"port": {
Type: schema.TypeInt,
Optional: true,
Description: "The port on which the health check will be performed. If not set, the health check will be performed on the component's http_port.",
ValidateFunc: validation.IntBetween(1, 65535),
},
"http_path": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -1459,6 +1465,7 @@ func expandAppHealthCheck(config []interface{}) *godo.AppServiceSpecHealthCheck
TimeoutSeconds: int32(healthCheckConfig["timeout_seconds"].(int)),
SuccessThreshold: int32(healthCheckConfig["success_threshold"].(int)),
FailureThreshold: int32(healthCheckConfig["failure_threshold"].(int)),
Port: int64(healthCheckConfig["port"].(int)),
}

return healthCheck
Expand All @@ -1476,6 +1483,7 @@ func flattenAppHealthCheck(check *godo.AppServiceSpecHealthCheck) []interface{}
r["timeout_seconds"] = check.TimeoutSeconds
r["success_threshold"] = check.SuccessThreshold
r["failure_threshold"] = check.FailureThreshold
r["port"] = check.Port

result = append(result, r)
}
Expand Down
3 changes: 3 additions & 0 deletions digitalocean/app/resource_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func TestAccDigitalOceanApp_Basic(t *testing.T) {
"digitalocean_app.foobar", "spec.0.service.0.health_check.0.http_path", "/"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.health_check.0.timeout_seconds", "10"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.health_check.0.port", "1234"),
resource.TestCheckResourceAttr(
"digitalocean_app.foobar", "spec.0.service.0.alert.0.value", "75"),
resource.TestCheckResourceAttr(
Expand Down Expand Up @@ -898,6 +900,7 @@ resource "digitalocean_app" "foobar" {
health_check {
http_path = "/"
timeout_seconds = 10
port = 1234
}
alert {
Expand Down
93 changes: 93 additions & 0 deletions digitalocean/database/datasource_database_connection_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package database

import (
"context"

"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"
)

func DataSourceDigitalOceanDatabaseConnectionPool() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceDigitalOceanDatabaseConnectionPoolRead,
Schema: map[string]*schema.Schema{
"cluster_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.NoZeroValues,
},

"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(3, 63),
},

"user": {
Type: schema.TypeString,
Computed: true,
},

"mode": {
Type: schema.TypeString,
Computed: true,
},

"size": {
Type: schema.TypeInt,
Computed: true,
},

"db_name": {
Type: schema.TypeString,
Computed: true,
},

"host": {
Type: schema.TypeString,
Computed: true,
},

"private_host": {
Type: schema.TypeString,
Computed: true,
},

"port": {
Type: schema.TypeInt,
Computed: true,
},

"uri": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"private_uri": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},

"password": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
},
}

}

func dataSourceDigitalOceanDatabaseConnectionPoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

clusterID := d.Get("cluster_id").(string)
poolName := d.Get("name").(string)
d.SetId(createConnectionPoolID(clusterID, poolName))

return resourceDigitalOceanDatabaseConnectionPoolRead(ctx, d, meta)
}
68 changes: 68 additions & 0 deletions digitalocean/database/datasource_database_connection_pool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package database_test

import (
"fmt"
"testing"

"github.com/digitalocean/godo"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/acceptance"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceDigitalOceanDatabaseConnectionPool_Basic(t *testing.T) {
var pool godo.DatabasePool

databaseName := acceptance.RandomTestName()
poolName := acceptance.RandomTestName()

resourceConfig := fmt.Sprintf(testAccCheckDigitalOceanDatabaseConnectionPoolConfigBasic, databaseName, poolName)
datasourceConfig := fmt.Sprintf(testAccCheckDigitalOceanDatasourceDatabaseConnectionPoolConfigBasic, poolName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanDatabaseConnectionPoolDestroy,
Steps: []resource.TestStep{
{
Config: resourceConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckDigitalOceanDatabaseConnectionPoolExists("digitalocean_database_connection_pool.pool-01", &pool),
testAccCheckDigitalOceanDatabaseConnectionPoolAttributes(&pool, poolName),
resource.TestCheckResourceAttr(
"digitalocean_database_connection_pool.pool-01", "name", poolName),
resource.TestCheckResourceAttrSet(
"digitalocean_database_connection_pool.pool-01", "cluster_id"),
resource.TestCheckResourceAttr(
"digitalocean_database_connection_pool.pool-01", "size", "10"),
resource.TestCheckResourceAttr(
"digitalocean_database_connection_pool.pool-01", "mode", "transaction"),
resource.TestCheckResourceAttr(
"digitalocean_database_connection_pool.pool-01", "db_name", "defaultdb"),
resource.TestCheckResourceAttr(
"digitalocean_database_connection_pool.pool-01", "user", "doadmin"),
),
},
{
Config: resourceConfig + datasourceConfig,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("digitalocean_database_connection_pool.pool-01", "name",
"data.digitalocean_database_connection_pool.pool-01", "name"),
resource.TestCheckResourceAttrPair("digitalocean_database_connection_pool.pool-01", "mode",
"data.digitalocean_database_connection_pool.pool-01", "mode"),
resource.TestCheckResourceAttrPair("digitalocean_database_connection_pool.pool-01", "size",
"data.digitalocean_database_connection_pool.pool-01", "size"),
resource.TestCheckResourceAttrPair("digitalocean_database_connection_pool.pool-01", "db_name",
"data.digitalocean_database_connection_pool.pool-01", "db_name"),
resource.TestCheckResourceAttrPair("digitalocean_database_connection_pool.pool-01", "user",
"data.digitalocean_database_connection_pool.pool-01", "user"),
),
},
},
})
}

const testAccCheckDigitalOceanDatasourceDatabaseConnectionPoolConfigBasic = `
data "digitalocean_database_connection_pool" "pool-01" {
cluster_id = digitalocean_database_cluster.foobar.id
name = "%s"
}`
9 changes: 0 additions & 9 deletions digitalocean/database/resource_database_kafka_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,6 @@ func ResourceDigitalOceanDatabaseKafkaTopic() *schema.Resource {
Computed: true,
ValidateFunc: validateUint64(),
},
"unclean_leader_election_enable": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -419,7 +414,6 @@ func flattenTopicConfig(config *godo.TopicConfig) []map[string]interface{} {
item["segment_index_bytes"] = strconv.FormatUint(*config.SegmentIndexBytes, 10)
item["segment_jitter_ms"] = strconv.FormatUint(*config.SegmentJitterMS, 10)
item["segment_ms"] = strconv.FormatUint(*config.SegmentMS, 10)
item["unclean_leader_election_enable"] = *config.UncleanLeaderElectionEnable
result = append(result, item)

return result
Expand Down Expand Up @@ -571,9 +565,6 @@ func getTopicConfig(raw []interface{}) *godo.TopicConfig {
res.SegmentMS = godo.PtrTo(v)
}
}
if v, ok := cfg["unclean_leader_election_enable"]; ok {
res.UncleanLeaderElectionEnable = godo.PtrTo(v.(bool))
}
}

return res
Expand Down
4 changes: 0 additions & 4 deletions digitalocean/database/resource_database_kafka_topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ func TestAccDigitalOceanDatabaseKafkaTopic(t *testing.T) {
"digitalocean_database_kafka_topic.foobar", "config.0.segment_jitter_ms"),
resource.TestCheckResourceAttrSet(
"digitalocean_database_kafka_topic.foobar", "config.0.segment_ms"),
resource.TestCheckResourceAttrSet(
"digitalocean_database_kafka_topic.foobar", "config.0.unclean_leader_election_enable"),
),
},
{
Expand Down Expand Up @@ -136,8 +134,6 @@ func TestAccDigitalOceanDatabaseKafkaTopic(t *testing.T) {
"digitalocean_database_kafka_topic.foobar", "config.0.segment_jitter_ms"),
resource.TestCheckResourceAttrSet(
"digitalocean_database_kafka_topic.foobar", "config.0.segment_ms"),
resource.TestCheckResourceAttrSet(
"digitalocean_database_kafka_topic.foobar", "config.0.unclean_leader_election_enable"),
),
},
},
Expand Down
79 changes: 40 additions & 39 deletions digitalocean/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,45 +93,46 @@ func Provider() *schema.Provider {
},
},
DataSourcesMap: map[string]*schema.Resource{
"digitalocean_account": account.DataSourceDigitalOceanAccount(),
"digitalocean_app": app.DataSourceDigitalOceanApp(),
"digitalocean_certificate": certificate.DataSourceDigitalOceanCertificate(),
"digitalocean_container_registry": registry.DataSourceDigitalOceanContainerRegistry(),
"digitalocean_database_cluster": database.DataSourceDigitalOceanDatabaseCluster(),
"digitalocean_database_ca": database.DataSourceDigitalOceanDatabaseCA(),
"digitalocean_database_replica": database.DataSourceDigitalOceanDatabaseReplica(),
"digitalocean_database_user": database.DataSourceDigitalOceanDatabaseUser(),
"digitalocean_domain": domain.DataSourceDigitalOceanDomain(),
"digitalocean_domains": domain.DataSourceDigitalOceanDomains(),
"digitalocean_droplet": droplet.DataSourceDigitalOceanDroplet(),
"digitalocean_droplets": droplet.DataSourceDigitalOceanDroplets(),
"digitalocean_droplet_snapshot": snapshot.DataSourceDigitalOceanDropletSnapshot(),
"digitalocean_firewall": firewall.DataSourceDigitalOceanFirewall(),
"digitalocean_floating_ip": reservedip.DataSourceDigitalOceanFloatingIP(),
"digitalocean_image": image.DataSourceDigitalOceanImage(),
"digitalocean_images": image.DataSourceDigitalOceanImages(),
"digitalocean_kubernetes_cluster": kubernetes.DataSourceDigitalOceanKubernetesCluster(),
"digitalocean_kubernetes_versions": kubernetes.DataSourceDigitalOceanKubernetesVersions(),
"digitalocean_loadbalancer": loadbalancer.DataSourceDigitalOceanLoadbalancer(),
"digitalocean_project": project.DataSourceDigitalOceanProject(),
"digitalocean_projects": project.DataSourceDigitalOceanProjects(),
"digitalocean_record": domain.DataSourceDigitalOceanRecord(),
"digitalocean_records": domain.DataSourceDigitalOceanRecords(),
"digitalocean_region": region.DataSourceDigitalOceanRegion(),
"digitalocean_regions": region.DataSourceDigitalOceanRegions(),
"digitalocean_reserved_ip": reservedip.DataSourceDigitalOceanReservedIP(),
"digitalocean_sizes": size.DataSourceDigitalOceanSizes(),
"digitalocean_spaces_bucket": spaces.DataSourceDigitalOceanSpacesBucket(),
"digitalocean_spaces_buckets": spaces.DataSourceDigitalOceanSpacesBuckets(),
"digitalocean_spaces_bucket_object": spaces.DataSourceDigitalOceanSpacesBucketObject(),
"digitalocean_spaces_bucket_objects": spaces.DataSourceDigitalOceanSpacesBucketObjects(),
"digitalocean_ssh_key": sshkey.DataSourceDigitalOceanSSHKey(),
"digitalocean_ssh_keys": sshkey.DataSourceDigitalOceanSSHKeys(),
"digitalocean_tag": tag.DataSourceDigitalOceanTag(),
"digitalocean_tags": tag.DataSourceDigitalOceanTags(),
"digitalocean_volume_snapshot": snapshot.DataSourceDigitalOceanVolumeSnapshot(),
"digitalocean_volume": volume.DataSourceDigitalOceanVolume(),
"digitalocean_vpc": vpc.DataSourceDigitalOceanVPC(),
"digitalocean_account": account.DataSourceDigitalOceanAccount(),
"digitalocean_app": app.DataSourceDigitalOceanApp(),
"digitalocean_certificate": certificate.DataSourceDigitalOceanCertificate(),
"digitalocean_container_registry": registry.DataSourceDigitalOceanContainerRegistry(),
"digitalocean_database_cluster": database.DataSourceDigitalOceanDatabaseCluster(),
"digitalocean_database_connection_pool": database.DataSourceDigitalOceanDatabaseConnectionPool(),
"digitalocean_database_ca": database.DataSourceDigitalOceanDatabaseCA(),
"digitalocean_database_replica": database.DataSourceDigitalOceanDatabaseReplica(),
"digitalocean_database_user": database.DataSourceDigitalOceanDatabaseUser(),
"digitalocean_domain": domain.DataSourceDigitalOceanDomain(),
"digitalocean_domains": domain.DataSourceDigitalOceanDomains(),
"digitalocean_droplet": droplet.DataSourceDigitalOceanDroplet(),
"digitalocean_droplets": droplet.DataSourceDigitalOceanDroplets(),
"digitalocean_droplet_snapshot": snapshot.DataSourceDigitalOceanDropletSnapshot(),
"digitalocean_firewall": firewall.DataSourceDigitalOceanFirewall(),
"digitalocean_floating_ip": reservedip.DataSourceDigitalOceanFloatingIP(),
"digitalocean_image": image.DataSourceDigitalOceanImage(),
"digitalocean_images": image.DataSourceDigitalOceanImages(),
"digitalocean_kubernetes_cluster": kubernetes.DataSourceDigitalOceanKubernetesCluster(),
"digitalocean_kubernetes_versions": kubernetes.DataSourceDigitalOceanKubernetesVersions(),
"digitalocean_loadbalancer": loadbalancer.DataSourceDigitalOceanLoadbalancer(),
"digitalocean_project": project.DataSourceDigitalOceanProject(),
"digitalocean_projects": project.DataSourceDigitalOceanProjects(),
"digitalocean_record": domain.DataSourceDigitalOceanRecord(),
"digitalocean_records": domain.DataSourceDigitalOceanRecords(),
"digitalocean_region": region.DataSourceDigitalOceanRegion(),
"digitalocean_regions": region.DataSourceDigitalOceanRegions(),
"digitalocean_reserved_ip": reservedip.DataSourceDigitalOceanReservedIP(),
"digitalocean_sizes": size.DataSourceDigitalOceanSizes(),
"digitalocean_spaces_bucket": spaces.DataSourceDigitalOceanSpacesBucket(),
"digitalocean_spaces_buckets": spaces.DataSourceDigitalOceanSpacesBuckets(),
"digitalocean_spaces_bucket_object": spaces.DataSourceDigitalOceanSpacesBucketObject(),
"digitalocean_spaces_bucket_objects": spaces.DataSourceDigitalOceanSpacesBucketObjects(),
"digitalocean_ssh_key": sshkey.DataSourceDigitalOceanSSHKey(),
"digitalocean_ssh_keys": sshkey.DataSourceDigitalOceanSSHKeys(),
"digitalocean_tag": tag.DataSourceDigitalOceanTag(),
"digitalocean_tags": tag.DataSourceDigitalOceanTags(),
"digitalocean_volume_snapshot": snapshot.DataSourceDigitalOceanVolumeSnapshot(),
"digitalocean_volume": volume.DataSourceDigitalOceanVolume(),
"digitalocean_vpc": vpc.DataSourceDigitalOceanVPC(),
},

ResourcesMap: map[string]*schema.Resource{
Expand Down
46 changes: 46 additions & 0 deletions docs/data-sources/database_connection_pool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
page_title: "DigitalOcean: digitalocean_database_connection_pool"
---

# digitalocean\_database\_connection\_pool

Provides information on a DigitalOcean PostgreSQL database connection pool.

## Example Usage

```hcl
data "digitalocean_database_cluster" "example" {
name = "example-cluster"
}
data "digitalocean_database_connection_pool" "read-only" {
cluster_id = data.digitalocean_database_cluster.example.id
name = "pool-01"
}
output "connection_pool_uri_output" {
value = data.digitalocean_database_connection_pool.read-only.uri
}
```

## Argument Reference

The following arguments are supported:

* `cluster_id` - (Required) The ID of the original source database cluster.
* `name` - (Required) The name for the database connection pool.


## Attributes Reference

The following attributes are exported:

* `id` - The ID of the database connection pool.
* `host` - Connection pool hostname.
* `private_host` - Same as `host`, but only accessible from resources within the account and in the same region.
* `port` - Network port that the connection pool is listening on.
* `uri` - The full URI for connecting to the database connection pool.
* `private_uri` - Same as `uri`, but only accessible from resources within the account and in the same region.
* `db_name` - Name of the connection pool's default database.
* `size` - Size of the connection pool.
* `mode` - The transaction mode for the connection pool.
* `user` - Username for the connection pool's default user.
* `password` - Password for the connection pool's default user.
1 change: 1 addition & 0 deletions docs/resources/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ A `service` can contain:
- `timeout_seconds` - The number of seconds after which the check times out.
- `success_threshold` - The number of successful health checks before considered healthy.
- `failure_threshold` - The number of failed health checks before considered unhealthy.
- `port` - The health check will be performed on this port instead of component's HTTP port.
* `cors` - (Deprecated - use `ingress`) The [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) policies of the app.
* `alert` - Describes an alert policy for the component.
- `rule` - The type of the alert to configure. Component app alert policies can be: `CPU_UTILIZATION`, `MEM_UTILIZATION`, or `RESTART_COUNT`.
Expand Down
Loading

0 comments on commit d10310b

Please sign in to comment.