1. Packages
  2. Alibaba Cloud
  3. API Docs
  4. polardb
  5. getAccounts
Alibaba Cloud v3.57.0 published on Saturday, Jun 15, 2024 by Pulumi

alicloud.polardb.getAccounts

Explore with Pulumi AI

alicloud logo
Alibaba Cloud v3.57.0 published on Saturday, Jun 15, 2024 by Pulumi

    The alicloud.polardb.getAccounts data source provides a collection of PolarDB cluster database account available in Alibaba Cloud account. Filters support regular expression for the account name, searches by clusterId.

    NOTE: Available since v1.70.0+.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as alicloud from "@pulumi/alicloud";
    
    export = async () => {
        const this = await 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.classes?.[0]?.zoneId,
            vswitchName: "terraform-example",
        });
        const cluster = new alicloud.polardb.Cluster("cluster", {
            dbType: "MySQL",
            dbVersion: "8.0",
            payType: "PostPaid",
            dbNodeCount: 2,
            dbNodeClass: _this.classes?.[0]?.supportedEngines?.[0]?.availableResources?.[0]?.dbNodeClass,
            vswitchId: defaultSwitch.id,
        });
        const polardbClustersDs = alicloud.polardb.getClustersOutput({
            descriptionRegex: cluster.description,
            status: "Running",
        });
        const account = new alicloud.polardb.Account("account", {
            dbClusterId: polardbClustersDs.apply(polardbClustersDs => polardbClustersDs.clusters?.[0]?.id),
            accountName: "tfnormal_01",
            accountPassword: "Test12345",
            accountDescription: "tf_account_description",
            accountType: "Normal",
        });
        const default = pulumi.all([polardbClustersDs, account.accountName]).apply(([polardbClustersDs, accountName]) => alicloud.polardb.getAccountsOutput({
            dbClusterId: polardbClustersDs.clusters?.[0]?.id,
            nameRegex: accountName,
        }));
        return {
            account: _default.apply(_default => _default.accounts?.[0]?.accountName),
        };
    }
    
    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")
    account = alicloud.polardb.Account("account",
        db_cluster_id=polardb_clusters_ds.clusters[0].id,
        account_name="tfnormal_01",
        account_password="Test12345",
        account_description="tf_account_description",
        account_type="Normal")
    default = pulumi.Output.all(polardb_clusters_ds, account.account_name).apply(lambda polardb_clusters_ds, account_name: alicloud.polardb.get_accounts_output(db_cluster_id=polardb_clusters_ds.clusters[0].id,
        name_regex=account_name))
    pulumi.export("account", default.accounts[0].account_name)
    
    package main
    
    import (
    	"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);
    account, err := polardb.NewAccount(ctx, "account", &polardb.AccountArgs{
    DbClusterId: polardbClustersDs.ApplyT(func(polardbClustersDs polardb.GetClustersResult) (*string, error) {
    return &polardbClustersDs.Clusters[0].Id, nil
    }).(pulumi.StringPtrOutput),
    AccountName: pulumi.String("tfnormal_01"),
    AccountPassword: pulumi.String("Test12345"),
    AccountDescription: pulumi.String("tf_account_description"),
    AccountType: pulumi.String("Normal"),
    })
    if err != nil {
    return err
    }
    _default := pulumi.All(polardbClustersDs,account.AccountName).ApplyT(func(_args []interface{}) (polardb.GetAccountsResult, error) {
    polardbClustersDs := _args[0].(polardb.GetClustersResult)
    accountName := _args[1].(string)
    return polardb.GetAccountsOutput(ctx, polardb.GetAccountsOutputArgs{
    DbClusterId: polardbClustersDs.Clusters[0].Id,
    NameRegex: accountName,
    }, nil), nil
    }).(polardb.GetAccountsResultOutput)
    ctx.Export("account", _default.ApplyT(func(_default polardb.GetAccountsResult) (*string, error) {
    return &default.Accounts[0].AccountName, 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 account = new AliCloud.PolarDB.Account("account", new()
        {
            DbClusterId = polardbClustersDs.Apply(getClustersResult => getClustersResult.Clusters[0]?.Id),
            AccountName = "tfnormal_01",
            AccountPassword = "Test12345",
            AccountDescription = "tf_account_description",
            AccountType = "Normal",
        });
    
        var @default = AliCloud.PolarDB.GetAccounts.Invoke(new()
        {
            DbClusterId = polardbClustersDs.Apply(getClustersResult => getClustersResult.Clusters[0]?.Id),
            NameRegex = account.AccountName,
        });
    
        return new Dictionary<string, object?>
        {
            ["account"] = @default.Apply(@default => @default.Apply(getAccountsResult => getAccountsResult.Accounts[0]?.AccountName)),
        };
    });
    
    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.Account;
    import com.pulumi.alicloud.polardb.AccountArgs;
    import com.pulumi.alicloud.polardb.inputs.GetAccountsArgs;
    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 account = new Account("account", AccountArgs.builder()
                .dbClusterId(polardbClustersDs.applyValue(getClustersResult -> getClustersResult).applyValue(polardbClustersDs -> polardbClustersDs.applyValue(getClustersResult -> getClustersResult.clusters()[0].id())))
                .accountName("tfnormal_01")
                .accountPassword("Test12345")
                .accountDescription("tf_account_description")
                .accountType("Normal")
                .build());
    
            final var default = PolardbFunctions.getAccounts(GetAccountsArgs.builder()
                .dbClusterId(polardbClustersDs.applyValue(getClustersResult -> getClustersResult).applyValue(polardbClustersDs -> polardbClustersDs.applyValue(getClustersResult -> getClustersResult.clusters()[0].id())))
                .nameRegex(account.accountName())
                .build());
    
            ctx.export("account", default_.applyValue(default_ -> default_.accounts()[0].accountName()));
        }
    }
    
    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}
      account:
        type: alicloud:polardb:Account
        properties:
          dbClusterId: ${polardbClustersDs.clusters[0].id}
          accountName: tfnormal_01
          accountPassword: Test12345
          accountDescription: tf_account_description
          accountType: Normal
    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:getAccounts
          Arguments:
            dbClusterId: ${polardbClustersDs.clusters[0].id}
            nameRegex: ${account.accountName}
    outputs:
      account: ${default.accounts[0].accountName}
    

    Using getAccounts

    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 getAccounts(args: GetAccountsArgs, opts?: InvokeOptions): Promise<GetAccountsResult>
    function getAccountsOutput(args: GetAccountsOutputArgs, opts?: InvokeOptions): Output<GetAccountsResult>
    def get_accounts(db_cluster_id: Optional[str] = None,
                     name_regex: Optional[str] = None,
                     opts: Optional[InvokeOptions] = None) -> GetAccountsResult
    def get_accounts_output(db_cluster_id: Optional[pulumi.Input[str]] = None,
                     name_regex: Optional[pulumi.Input[str]] = None,
                     opts: Optional[InvokeOptions] = None) -> Output[GetAccountsResult]
    func GetAccounts(ctx *Context, args *GetAccountsArgs, opts ...InvokeOption) (*GetAccountsResult, error)
    func GetAccountsOutput(ctx *Context, args *GetAccountsOutputArgs, opts ...InvokeOption) GetAccountsResultOutput

    > Note: This function is named GetAccounts in the Go SDK.

    public static class GetAccounts 
    {
        public static Task<GetAccountsResult> InvokeAsync(GetAccountsArgs args, InvokeOptions? opts = null)
        public static Output<GetAccountsResult> Invoke(GetAccountsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetAccountsResult> getAccounts(GetAccountsArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: alicloud:polardb/getAccounts:getAccounts
      arguments:
        # arguments dictionary

    The following arguments are supported:

    DbClusterId string
    The polarDB cluster ID.
    NameRegex string
    A regex string to filter results by account name.
    DbClusterId string
    The polarDB cluster ID.
    NameRegex string
    A regex string to filter results by account name.
    dbClusterId String
    The polarDB cluster ID.
    nameRegex String
    A regex string to filter results by account name.
    dbClusterId string
    The polarDB cluster ID.
    nameRegex string
    A regex string to filter results by account name.
    db_cluster_id str
    The polarDB cluster ID.
    name_regex str
    A regex string to filter results by account name.
    dbClusterId String
    The polarDB cluster ID.
    nameRegex String
    A regex string to filter results by account name.

    getAccounts Result

    The following output properties are available:

    Accounts List<Pulumi.AliCloud.PolarDB.Outputs.GetAccountsAccount>
    A list of PolarDB cluster accounts. Each element contains the following attributes:
    DbClusterId string
    Id string
    The provider-assigned unique ID for this managed resource.
    Names List<string>
    Account name of the cluster.
    NameRegex string
    Accounts []GetAccountsAccount
    A list of PolarDB cluster accounts. Each element contains the following attributes:
    DbClusterId string
    Id string
    The provider-assigned unique ID for this managed resource.
    Names []string
    Account name of the cluster.
    NameRegex string
    accounts List<GetAccountsAccount>
    A list of PolarDB cluster accounts. Each element contains the following attributes:
    dbClusterId String
    id String
    The provider-assigned unique ID for this managed resource.
    names List<String>
    Account name of the cluster.
    nameRegex String
    accounts GetAccountsAccount[]
    A list of PolarDB cluster accounts. Each element contains the following attributes:
    dbClusterId string
    id string
    The provider-assigned unique ID for this managed resource.
    names string[]
    Account name of the cluster.
    nameRegex string
    accounts Sequence[GetAccountsAccount]
    A list of PolarDB cluster accounts. Each element contains the following attributes:
    db_cluster_id str
    id str
    The provider-assigned unique ID for this managed resource.
    names Sequence[str]
    Account name of the cluster.
    name_regex str
    accounts List<Property Map>
    A list of PolarDB cluster accounts. Each element contains the following attributes:
    dbClusterId String
    id String
    The provider-assigned unique ID for this managed resource.
    names List<String>
    Account name of the cluster.
    nameRegex String

    Supporting Types

    GetAccountsAccount

    AccountDescription string
    Account description.
    AccountLockState string
    Account lock state, Valid values are Lock, UnLock.
    AccountName string
    Account name.
    AccountStatus string
    Cluster address type.Cluster: the default address of the Cluster.Primary: Primary address.Custom: Custom cluster addresses.
    AccountType string
    Account type, Valid values are Normal, Super.
    DatabasePrivileges List<Pulumi.AliCloud.PolarDB.Inputs.GetAccountsAccountDatabasePrivilege>
    A list of database privilege. Each element contains the following attributes.
    AccountDescription string
    Account description.
    AccountLockState string
    Account lock state, Valid values are Lock, UnLock.
    AccountName string
    Account name.
    AccountStatus string
    Cluster address type.Cluster: the default address of the Cluster.Primary: Primary address.Custom: Custom cluster addresses.
    AccountType string
    Account type, Valid values are Normal, Super.
    DatabasePrivileges []GetAccountsAccountDatabasePrivilege
    A list of database privilege. Each element contains the following attributes.
    accountDescription String
    Account description.
    accountLockState String
    Account lock state, Valid values are Lock, UnLock.
    accountName String
    Account name.
    accountStatus String
    Cluster address type.Cluster: the default address of the Cluster.Primary: Primary address.Custom: Custom cluster addresses.
    accountType String
    Account type, Valid values are Normal, Super.
    databasePrivileges List<GetAccountsAccountDatabasePrivilege>
    A list of database privilege. Each element contains the following attributes.
    accountDescription string
    Account description.
    accountLockState string
    Account lock state, Valid values are Lock, UnLock.
    accountName string
    Account name.
    accountStatus string
    Cluster address type.Cluster: the default address of the Cluster.Primary: Primary address.Custom: Custom cluster addresses.
    accountType string
    Account type, Valid values are Normal, Super.
    databasePrivileges GetAccountsAccountDatabasePrivilege[]
    A list of database privilege. Each element contains the following attributes.
    account_description str
    Account description.
    account_lock_state str
    Account lock state, Valid values are Lock, UnLock.
    account_name str
    Account name.
    account_status str
    Cluster address type.Cluster: the default address of the Cluster.Primary: Primary address.Custom: Custom cluster addresses.
    account_type str
    Account type, Valid values are Normal, Super.
    database_privileges Sequence[GetAccountsAccountDatabasePrivilege]
    A list of database privilege. Each element contains the following attributes.
    accountDescription String
    Account description.
    accountLockState String
    Account lock state, Valid values are Lock, UnLock.
    accountName String
    Account name.
    accountStatus String
    Cluster address type.Cluster: the default address of the Cluster.Primary: Primary address.Custom: Custom cluster addresses.
    accountType String
    Account type, Valid values are Normal, Super.
    databasePrivileges List<Property Map>
    A list of database privilege. Each element contains the following attributes.

    GetAccountsAccountDatabasePrivilege

    AccountPrivilege string
    Account privilege of database
    DbName string
    The account owned database name
    AccountPrivilege string
    Account privilege of database
    DbName string
    The account owned database name
    accountPrivilege String
    Account privilege of database
    dbName String
    The account owned database name
    accountPrivilege string
    Account privilege of database
    dbName string
    The account owned database name
    account_privilege str
    Account privilege of database
    db_name str
    The account owned database name
    accountPrivilege String
    Account privilege of database
    dbName String
    The account owned database name

    Package Details

    Repository
    Alibaba Cloud pulumi/pulumi-alicloud
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the alicloud Terraform Provider.
    alicloud logo
    Alibaba Cloud v3.57.0 published on Saturday, Jun 15, 2024 by Pulumi