Alibaba Cloud v3.57.1 published on Wednesday, Jun 26, 2024 by Pulumi
alicloud.polardb.getDatabases
Explore with Pulumi AI
The alicloud.polardb.getDatabases
data source provides a collection of PolarDB cluster database available in Alibaba Cloud account.
Filters support regular expression for the database name, searches by clusterId.
NOTE: Available since v1.70.0+.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";
const this = alicloud.polardb.getNodeClasses({
dbType: "MySQL",
dbVersion: "8.0",
payType: "PostPaid",
category: "Normal",
});
const defaultNetwork = new alicloud.vpc.Network("default", {
vpcName: "terraform-example",
cidrBlock: "172.16.0.0/16",
});
const defaultSwitch = new alicloud.vpc.Switch("default", {
vpcId: defaultNetwork.id,
cidrBlock: "172.16.0.0/24",
zoneId: _this.then(_this => _this.classes?.[0]?.zoneId),
vswitchName: "terraform-example",
});
const cluster = new alicloud.polardb.Cluster("cluster", {
dbType: "MySQL",
dbVersion: "8.0",
payType: "PostPaid",
dbNodeCount: 2,
dbNodeClass: _this.then(_this => _this.classes?.[0]?.supportedEngines?.[0]?.availableResources?.[0]?.dbNodeClass),
vswitchId: defaultSwitch.id,
});
const polardbClustersDs = alicloud.polardb.getClustersOutput({
descriptionRegex: cluster.description,
status: "Running",
});
const defaultDatabase = new alicloud.polardb.Database("default", {
dbClusterId: polardbClustersDs.apply(polardbClustersDs => polardbClustersDs.clusters?.[0]?.id),
dbName: polardbClustersDs.apply(polardbClustersDs => `tfaccountpri_${polardbClustersDs.clusters?.[0]?.id}`),
dbDescription: "from terraform",
});
const default = pulumi.all([polardbClustersDs, defaultDatabase.dbName]).apply(([polardbClustersDs, dbName]) => alicloud.polardb.getDatabasesOutput({
dbClusterId: polardbClustersDs.clusters?.[0]?.id,
nameRegex: dbName,
}));
export const database = _default.apply(_default => _default.databases?.[0]?.dbName);
import pulumi
import pulumi_alicloud as alicloud
this = alicloud.polardb.get_node_classes(db_type="MySQL",
db_version="8.0",
pay_type="PostPaid",
category="Normal")
default_network = alicloud.vpc.Network("default",
vpc_name="terraform-example",
cidr_block="172.16.0.0/16")
default_switch = alicloud.vpc.Switch("default",
vpc_id=default_network.id,
cidr_block="172.16.0.0/24",
zone_id=this.classes[0].zone_id,
vswitch_name="terraform-example")
cluster = alicloud.polardb.Cluster("cluster",
db_type="MySQL",
db_version="8.0",
pay_type="PostPaid",
db_node_count=2,
db_node_class=this.classes[0].supported_engines[0].available_resources[0].db_node_class,
vswitch_id=default_switch.id)
polardb_clusters_ds = alicloud.polardb.get_clusters_output(description_regex=cluster.description,
status="Running")
default_database = alicloud.polardb.Database("default",
db_cluster_id=polardb_clusters_ds.clusters[0].id,
db_name=polardb_clusters_ds.apply(lambda polardb_clusters_ds: f"tfaccountpri_{polardb_clusters_ds.clusters[0].id}"),
db_description="from terraform")
default = pulumi.Output.all(polardb_clusters_ds, default_database.db_name).apply(lambda polardb_clusters_ds, db_name: alicloud.polardb.get_databases_output(db_cluster_id=polardb_clusters_ds.clusters[0].id,
name_regex=db_name))
pulumi.export("database", default.databases[0].db_name)
package main
import (
"fmt"
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/polardb"
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/vpc"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
this, err := polardb.GetNodeClasses(ctx, &polardb.GetNodeClassesArgs{
DbType: pulumi.StringRef("MySQL"),
DbVersion: pulumi.StringRef("8.0"),
PayType: "PostPaid",
Category: pulumi.StringRef("Normal"),
}, nil);
if err != nil {
return err
}
defaultNetwork, err := vpc.NewNetwork(ctx, "default", &vpc.NetworkArgs{
VpcName: pulumi.String("terraform-example"),
CidrBlock: pulumi.String("172.16.0.0/16"),
})
if err != nil {
return err
}
defaultSwitch, err := vpc.NewSwitch(ctx, "default", &vpc.SwitchArgs{
VpcId: defaultNetwork.ID(),
CidrBlock: pulumi.String("172.16.0.0/24"),
ZoneId: pulumi.String(this.Classes[0].ZoneId),
VswitchName: pulumi.String("terraform-example"),
})
if err != nil {
return err
}
cluster, err := polardb.NewCluster(ctx, "cluster", &polardb.ClusterArgs{
DbType: pulumi.String("MySQL"),
DbVersion: pulumi.String("8.0"),
PayType: pulumi.String("PostPaid"),
DbNodeCount: pulumi.Int(2),
DbNodeClass: pulumi.String(this.Classes[0].SupportedEngines[0].AvailableResources[0].DbNodeClass),
VswitchId: defaultSwitch.ID(),
})
if err != nil {
return err
}
polardbClustersDs := polardb.GetClustersOutput(ctx, polardb.GetClustersOutputArgs{
DescriptionRegex: cluster.Description,
Status: pulumi.String("Running"),
}, nil);
defaultDatabase, err := polardb.NewDatabase(ctx, "default", &polardb.DatabaseArgs{
DbClusterId: polardbClustersDs.ApplyT(func(polardbClustersDs polardb.GetClustersResult) (*string, error) {
return &polardbClustersDs.Clusters[0].Id, nil
}).(pulumi.StringPtrOutput),
DbName: polardbClustersDs.ApplyT(func(polardbClustersDs polardb.GetClustersResult) (string, error) {
return fmt.Sprintf("tfaccountpri_%v", polardbClustersDs.Clusters[0].Id), nil
}).(pulumi.StringOutput),
DbDescription: pulumi.String("from terraform"),
})
if err != nil {
return err
}
_default := pulumi.All(polardbClustersDs,defaultDatabase.DbName).ApplyT(func(_args []interface{}) (polardb.GetDatabasesResult, error) {
polardbClustersDs := _args[0].(polardb.GetClustersResult)
dbName := _args[1].(string)
return polardb.GetDatabasesOutput(ctx, polardb.GetDatabasesOutputArgs{
DbClusterId: polardbClustersDs.Clusters[0].Id,
NameRegex: dbName,
}, nil), nil
}).(polardb.GetDatabasesResultOutput)
ctx.Export("database", _default.ApplyT(func(_default polardb.GetDatabasesResult) (*string, error) {
return &default.Databases[0].DbName, nil
}).(pulumi.StringPtrOutput))
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;
return await Deployment.RunAsync(() =>
{
var @this = AliCloud.PolarDB.GetNodeClasses.Invoke(new()
{
DbType = "MySQL",
DbVersion = "8.0",
PayType = "PostPaid",
Category = "Normal",
});
var defaultNetwork = new AliCloud.Vpc.Network("default", new()
{
VpcName = "terraform-example",
CidrBlock = "172.16.0.0/16",
});
var defaultSwitch = new AliCloud.Vpc.Switch("default", new()
{
VpcId = defaultNetwork.Id,
CidrBlock = "172.16.0.0/24",
ZoneId = @this.Apply(@this => @this.Apply(getNodeClassesResult => getNodeClassesResult.Classes[0]?.ZoneId)),
VswitchName = "terraform-example",
});
var cluster = new AliCloud.PolarDB.Cluster("cluster", new()
{
DbType = "MySQL",
DbVersion = "8.0",
PayType = "PostPaid",
DbNodeCount = 2,
DbNodeClass = @this.Apply(@this => @this.Apply(getNodeClassesResult => getNodeClassesResult.Classes[0]?.SupportedEngines[0]?.AvailableResources[0]?.DbNodeClass)),
VswitchId = defaultSwitch.Id,
});
var polardbClustersDs = AliCloud.PolarDB.GetClusters.Invoke(new()
{
DescriptionRegex = cluster.Description,
Status = "Running",
});
var defaultDatabase = new AliCloud.PolarDB.Database("default", new()
{
DbClusterId = polardbClustersDs.Apply(getClustersResult => getClustersResult.Clusters[0]?.Id),
DbName = $"tfaccountpri_{polardbClustersDs.Apply(getClustersResult => getClustersResult.Clusters[0]?.Id)}",
DbDescription = "from terraform",
});
var @default = AliCloud.PolarDB.GetDatabases.Invoke(new()
{
DbClusterId = polardbClustersDs.Apply(getClustersResult => getClustersResult.Clusters[0]?.Id),
NameRegex = defaultDatabase.DbName,
});
return new Dictionary<string, object?>
{
["database"] = @default.Apply(@default => @default.Apply(getDatabasesResult => getDatabasesResult.Databases[0]?.DbName)),
};
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.polardb.PolardbFunctions;
import com.pulumi.alicloud.polardb.inputs.GetNodeClassesArgs;
import com.pulumi.alicloud.vpc.Network;
import com.pulumi.alicloud.vpc.NetworkArgs;
import com.pulumi.alicloud.vpc.Switch;
import com.pulumi.alicloud.vpc.SwitchArgs;
import com.pulumi.alicloud.polardb.Cluster;
import com.pulumi.alicloud.polardb.ClusterArgs;
import com.pulumi.alicloud.polardb.inputs.GetClustersArgs;
import com.pulumi.alicloud.polardb.Database;
import com.pulumi.alicloud.polardb.DatabaseArgs;
import com.pulumi.alicloud.polardb.inputs.GetDatabasesArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
final var this = PolardbFunctions.getNodeClasses(GetNodeClassesArgs.builder()
.dbType("MySQL")
.dbVersion("8.0")
.payType("PostPaid")
.category("Normal")
.build());
var defaultNetwork = new Network("defaultNetwork", NetworkArgs.builder()
.vpcName("terraform-example")
.cidrBlock("172.16.0.0/16")
.build());
var defaultSwitch = new Switch("defaultSwitch", SwitchArgs.builder()
.vpcId(defaultNetwork.id())
.cidrBlock("172.16.0.0/24")
.zoneId(this_.classes()[0].zoneId())
.vswitchName("terraform-example")
.build());
var cluster = new Cluster("cluster", ClusterArgs.builder()
.dbType("MySQL")
.dbVersion("8.0")
.payType("PostPaid")
.dbNodeCount("2")
.dbNodeClass(this_.classes()[0].supportedEngines()[0].availableResources()[0].dbNodeClass())
.vswitchId(defaultSwitch.id())
.build());
final var polardbClustersDs = PolardbFunctions.getClusters(GetClustersArgs.builder()
.descriptionRegex(cluster.description())
.status("Running")
.build());
var defaultDatabase = new Database("defaultDatabase", DatabaseArgs.builder()
.dbClusterId(polardbClustersDs.applyValue(getClustersResult -> getClustersResult).applyValue(polardbClustersDs -> polardbClustersDs.applyValue(getClustersResult -> getClustersResult.clusters()[0].id())))
.dbName(polardbClustersDs.applyValue(getClustersResult -> getClustersResult).applyValue(polardbClustersDs -> String.format("tfaccountpri_%s", polardbClustersDs.applyValue(getClustersResult -> getClustersResult.clusters()[0].id()))))
.dbDescription("from terraform")
.build());
final var default = PolardbFunctions.getDatabases(GetDatabasesArgs.builder()
.dbClusterId(polardbClustersDs.applyValue(getClustersResult -> getClustersResult).applyValue(polardbClustersDs -> polardbClustersDs.applyValue(getClustersResult -> getClustersResult.clusters()[0].id())))
.nameRegex(defaultDatabase.dbName())
.build());
ctx.export("database", default_.applyValue(default_ -> default_.databases()[0].dbName()));
}
}
resources:
defaultNetwork:
type: alicloud:vpc:Network
name: default
properties:
vpcName: terraform-example
cidrBlock: 172.16.0.0/16
defaultSwitch:
type: alicloud:vpc:Switch
name: default
properties:
vpcId: ${defaultNetwork.id}
cidrBlock: 172.16.0.0/24
zoneId: ${this.classes[0].zoneId}
vswitchName: terraform-example
cluster:
type: alicloud:polardb:Cluster
properties:
dbType: MySQL
dbVersion: '8.0'
payType: PostPaid
dbNodeCount: '2'
dbNodeClass: ${this.classes[0].supportedEngines[0].availableResources[0].dbNodeClass}
vswitchId: ${defaultSwitch.id}
defaultDatabase:
type: alicloud:polardb:Database
name: default
properties:
dbClusterId: ${polardbClustersDs.clusters[0].id}
dbName: tfaccountpri_${polardbClustersDs.clusters[0].id}
dbDescription: from terraform
variables:
this:
fn::invoke:
Function: alicloud:polardb:getNodeClasses
Arguments:
dbType: MySQL
dbVersion: '8.0'
payType: PostPaid
category: Normal
polardbClustersDs:
fn::invoke:
Function: alicloud:polardb:getClusters
Arguments:
descriptionRegex: ${cluster.description}
status: Running
default:
fn::invoke:
Function: alicloud:polardb:getDatabases
Arguments:
dbClusterId: ${polardbClustersDs.clusters[0].id}
nameRegex: ${defaultDatabase.dbName}
outputs:
database: ${default.databases[0].dbName}
Using getDatabases
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getDatabases(args: GetDatabasesArgs, opts?: InvokeOptions): Promise<GetDatabasesResult>
function getDatabasesOutput(args: GetDatabasesOutputArgs, opts?: InvokeOptions): Output<GetDatabasesResult>
def get_databases(db_cluster_id: Optional[str] = None,
name_regex: Optional[str] = None,
opts: Optional[InvokeOptions] = None) -> GetDatabasesResult
def get_databases_output(db_cluster_id: Optional[pulumi.Input[str]] = None,
name_regex: Optional[pulumi.Input[str]] = None,
opts: Optional[InvokeOptions] = None) -> Output[GetDatabasesResult]
func GetDatabases(ctx *Context, args *GetDatabasesArgs, opts ...InvokeOption) (*GetDatabasesResult, error)
func GetDatabasesOutput(ctx *Context, args *GetDatabasesOutputArgs, opts ...InvokeOption) GetDatabasesResultOutput
> Note: This function is named GetDatabases
in the Go SDK.
public static class GetDatabases
{
public static Task<GetDatabasesResult> InvokeAsync(GetDatabasesArgs args, InvokeOptions? opts = null)
public static Output<GetDatabasesResult> Invoke(GetDatabasesInvokeArgs args, InvokeOptions? opts = null)
}
public static CompletableFuture<GetDatabasesResult> getDatabases(GetDatabasesArgs args, InvokeOptions options)
// Output-based functions aren't available in Java yet
fn::invoke:
function: alicloud:polardb/getDatabases:getDatabases
arguments:
# arguments dictionary
The following arguments are supported:
- Db
Cluster stringId - The polarDB cluster ID.
- Name
Regex string - A regex string to filter results by database name.
- Db
Cluster stringId - The polarDB cluster ID.
- Name
Regex string - A regex string to filter results by database name.
- db
Cluster StringId - The polarDB cluster ID.
- name
Regex String - A regex string to filter results by database name.
- db
Cluster stringId - The polarDB cluster ID.
- name
Regex string - A regex string to filter results by database name.
- db_
cluster_ strid - The polarDB cluster ID.
- name_
regex str - A regex string to filter results by database name.
- db
Cluster StringId - The polarDB cluster ID.
- name
Regex String - A regex string to filter results by database name.
getDatabases Result
The following output properties are available:
- Databases
List<Pulumi.
Ali Cloud. Polar DB. Outputs. Get Databases Database> - A list of PolarDB cluster databases. Each element contains the following attributes:
- Db
Cluster stringId - Id string
- The provider-assigned unique ID for this managed resource.
- Names List<string>
- database name of the cluster.
- Name
Regex string
- Databases
[]Get
Databases Database - A list of PolarDB cluster databases. Each element contains the following attributes:
- Db
Cluster stringId - Id string
- The provider-assigned unique ID for this managed resource.
- Names []string
- database name of the cluster.
- Name
Regex string
- databases
List<Get
Databases Database> - A list of PolarDB cluster databases. Each element contains the following attributes:
- db
Cluster StringId - id String
- The provider-assigned unique ID for this managed resource.
- names List<String>
- database name of the cluster.
- name
Regex String
- databases
Get
Databases Database[] - A list of PolarDB cluster databases. Each element contains the following attributes:
- db
Cluster stringId - id string
- The provider-assigned unique ID for this managed resource.
- names string[]
- database name of the cluster.
- name
Regex string
- databases
Sequence[Get
Databases Database] - A list of PolarDB cluster databases. Each element contains the following attributes:
- db_
cluster_ strid - id str
- The provider-assigned unique ID for this managed resource.
- names Sequence[str]
- database name of the cluster.
- name_
regex str
- databases List<Property Map>
- A list of PolarDB cluster databases. Each element contains the following attributes:
- db
Cluster StringId - id String
- The provider-assigned unique ID for this managed resource.
- names List<String>
- database name of the cluster.
- name
Regex String
Supporting Types
GetDatabasesDatabase
- Accounts
List<Pulumi.
Ali Cloud. Polar DB. Inputs. Get Databases Database Account> - A list of accounts of database. Each element contains the following attributes.
- Character
Set stringName - The character set name of database.
- Db
Description string - Database description.
- Db
Name string - Database name.
- Db
Status string - The status of database.
- Engine string
- The engine of database.
- Accounts
[]Get
Databases Database Account - A list of accounts of database. Each element contains the following attributes.
- Character
Set stringName - The character set name of database.
- Db
Description string - Database description.
- Db
Name string - Database name.
- Db
Status string - The status of database.
- Engine string
- The engine of database.
- accounts
List<Get
Databases Database Account> - A list of accounts of database. Each element contains the following attributes.
- character
Set StringName - The character set name of database.
- db
Description String - Database description.
- db
Name String - Database name.
- db
Status String - The status of database.
- engine String
- The engine of database.
- accounts
Get
Databases Database Account[] - A list of accounts of database. Each element contains the following attributes.
- character
Set stringName - The character set name of database.
- db
Description string - Database description.
- db
Name string - Database name.
- db
Status string - The status of database.
- engine string
- The engine of database.
- accounts
Sequence[Get
Databases Database Account] - A list of accounts of database. Each element contains the following attributes.
- character_
set_ strname - The character set name of database.
- db_
description str - Database description.
- db_
name str - Database name.
- db_
status str - The status of database.
- engine str
- The engine of database.
- accounts List<Property Map>
- A list of accounts of database. Each element contains the following attributes.
- character
Set StringName - The character set name of database.
- db
Description String - Database description.
- db
Name String - Database name.
- db
Status String - The status of database.
- engine String
- The engine of database.
GetDatabasesDatabaseAccount
- Account
Name string - Account name.
- Account
Status string - Account status.
- Privilege
Status string - The privilege status of account.
- Account
Name string - Account name.
- Account
Status string - Account status.
- Privilege
Status string - The privilege status of account.
- account
Name String - Account name.
- account
Status String - Account status.
- privilege
Status String - The privilege status of account.
- account
Name string - Account name.
- account
Status string - Account status.
- privilege
Status string - The privilege status of account.
- account_
name str - Account name.
- account_
status str - Account status.
- privilege_
status str - The privilege status of account.
- account
Name String - Account name.
- account
Status String - Account status.
- privilege
Status String - The privilege status of account.
Package Details
- Repository
- Alibaba Cloud pulumi/pulumi-alicloud
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
alicloud
Terraform Provider.