-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix-lowercase-transformation-volumes
- Loading branch information
Showing
10 changed files
with
259 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
digitalocean/database/datasource_database_connection_pool.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
68
digitalocean/database/datasource_database_connection_pool_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
}` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.