Alibaba Cloud

Pulumi Official
Package maintained by Pulumi
v3.19.0 published on Friday, Mar 18, 2022 by Pulumi

AccountPrivilege

Provides a PolarDB account privilege resource and used to grant several database some access privilege. A database can be granted by multiple account.

NOTE: Available in v1.67.0+.

Example Usage

using Pulumi;
using AliCloud = Pulumi.AliCloud;

class MyStack : Stack
{
    public MyStack()
    {
        var config = new Config();
        var creation = config.Get("creation") ?? "PolarDB";
        var name = config.Get("name") ?? "dbaccountprivilegebasic";
        var defaultZones = Output.Create(AliCloud.GetZones.InvokeAsync(new AliCloud.GetZonesArgs
        {
            AvailableResourceCreation = creation,
        }));
        var defaultNetwork = new AliCloud.Vpc.Network("defaultNetwork", new AliCloud.Vpc.NetworkArgs
        {
            CidrBlock = "172.16.0.0/16",
        });
        var defaultSwitch = new AliCloud.Vpc.Switch("defaultSwitch", new AliCloud.Vpc.SwitchArgs
        {
            VpcId = defaultNetwork.Id,
            CidrBlock = "172.16.0.0/24",
            ZoneId = defaultZones.Apply(defaultZones => defaultZones.Zones?[0]?.Id),
        });
        var cluster = new AliCloud.PolarDB.Cluster("cluster", new AliCloud.PolarDB.ClusterArgs
        {
            DbType = "MySQL",
            DbVersion = "8.0",
            PayType = "PostPaid",
            DbNodeClass = "polar.mysql.x4.large",
            VswitchId = defaultSwitch.Id,
            Description = name,
        });
        var db = new AliCloud.PolarDB.Database("db", new AliCloud.PolarDB.DatabaseArgs
        {
            DbClusterId = cluster.Id,
            DbName = "tftestdatabase",
        });
        var account = new AliCloud.PolarDB.Account("account", new AliCloud.PolarDB.AccountArgs
        {
            DbClusterId = cluster.Id,
            AccountName = "tftestnormal",
            AccountPassword = "Test12345",
            AccountDescription = name,
        });
        var privilege = new AliCloud.PolarDB.AccountPrivilege("privilege", new AliCloud.PolarDB.AccountPrivilegeArgs
        {
            DbClusterId = cluster.Id,
            AccountName = account.AccountName,
            AccountPrivilege = "ReadOnly",
            DbNames = 
            {
                db.DbName,
            },
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud"
	"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"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		cfg := config.New(ctx, "")
		creation := "PolarDB"
		if param := cfg.Get("creation"); param != "" {
			creation = param
		}
		name := "dbaccountprivilegebasic"
		if param := cfg.Get("name"); param != "" {
			name = param
		}
		defaultZones, err := alicloud.GetZones(ctx, &GetZonesArgs{
			AvailableResourceCreation: pulumi.StringRef(creation),
		}, nil)
		if err != nil {
			return err
		}
		defaultNetwork, err := vpc.NewNetwork(ctx, "defaultNetwork", &vpc.NetworkArgs{
			CidrBlock: pulumi.String("172.16.0.0/16"),
		})
		if err != nil {
			return err
		}
		defaultSwitch, err := vpc.NewSwitch(ctx, "defaultSwitch", &vpc.SwitchArgs{
			VpcId:     defaultNetwork.ID(),
			CidrBlock: pulumi.String("172.16.0.0/24"),
			ZoneId:    pulumi.String(defaultZones.Zones[0].Id),
		})
		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"),
			DbNodeClass: pulumi.String("polar.mysql.x4.large"),
			VswitchId:   defaultSwitch.ID(),
			Description: pulumi.String(name),
		})
		if err != nil {
			return err
		}
		db, err := polardb.NewDatabase(ctx, "db", &polardb.DatabaseArgs{
			DbClusterId: cluster.ID(),
			DbName:      pulumi.String("tftestdatabase"),
		})
		if err != nil {
			return err
		}
		account, err := polardb.NewAccount(ctx, "account", &polardb.AccountArgs{
			DbClusterId:        cluster.ID(),
			AccountName:        pulumi.String("tftestnormal"),
			AccountPassword:    pulumi.String("Test12345"),
			AccountDescription: pulumi.String(name),
		})
		if err != nil {
			return err
		}
		_, err = polardb.NewAccountPrivilege(ctx, "privilege", &polardb.AccountPrivilegeArgs{
			DbClusterId:      cluster.ID(),
			AccountName:      account.AccountName,
			AccountPrivilege: pulumi.String("ReadOnly"),
			DbNames: pulumi.StringArray{
				db.DbName,
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}

Coming soon!

import pulumi
import pulumi_alicloud as alicloud

config = pulumi.Config()
creation = config.get("creation")
if creation is None:
    creation = "PolarDB"
name = config.get("name")
if name is None:
    name = "dbaccountprivilegebasic"
default_zones = alicloud.get_zones(available_resource_creation=creation)
default_network = alicloud.vpc.Network("defaultNetwork", cidr_block="172.16.0.0/16")
default_switch = alicloud.vpc.Switch("defaultSwitch",
    vpc_id=default_network.id,
    cidr_block="172.16.0.0/24",
    zone_id=default_zones.zones[0].id)
cluster = alicloud.polardb.Cluster("cluster",
    db_type="MySQL",
    db_version="8.0",
    pay_type="PostPaid",
    db_node_class="polar.mysql.x4.large",
    vswitch_id=default_switch.id,
    description=name)
db = alicloud.polardb.Database("db",
    db_cluster_id=cluster.id,
    db_name="tftestdatabase")
account = alicloud.polardb.Account("account",
    db_cluster_id=cluster.id,
    account_name="tftestnormal",
    account_password="Test12345",
    account_description=name)
privilege = alicloud.polardb.AccountPrivilege("privilege",
    db_cluster_id=cluster.id,
    account_name=account.account_name,
    account_privilege="ReadOnly",
    db_names=[db.db_name])
import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";

const config = new pulumi.Config();
const creation = config.get("creation") || "PolarDB";
const name = config.get("name") || "dbaccountprivilegebasic";
const defaultZones = alicloud.getZones({
    availableResourceCreation: creation,
});
const defaultNetwork = new alicloud.vpc.Network("defaultNetwork", {cidrBlock: "172.16.0.0/16"});
const defaultSwitch = new alicloud.vpc.Switch("defaultSwitch", {
    vpcId: defaultNetwork.id,
    cidrBlock: "172.16.0.0/24",
    zoneId: defaultZones.then(defaultZones => defaultZones.zones?[0]?.id),
});
const cluster = new alicloud.polardb.Cluster("cluster", {
    dbType: "MySQL",
    dbVersion: "8.0",
    payType: "PostPaid",
    dbNodeClass: "polar.mysql.x4.large",
    vswitchId: defaultSwitch.id,
    description: name,
});
const db = new alicloud.polardb.Database("db", {
    dbClusterId: cluster.id,
    dbName: "tftestdatabase",
});
const account = new alicloud.polardb.Account("account", {
    dbClusterId: cluster.id,
    accountName: "tftestnormal",
    accountPassword: "Test12345",
    accountDescription: name,
});
const privilege = new alicloud.polardb.AccountPrivilege("privilege", {
    dbClusterId: cluster.id,
    accountName: account.accountName,
    accountPrivilege: "ReadOnly",
    dbNames: [db.dbName],
});

Coming soon!

Create a AccountPrivilege Resource

new AccountPrivilege(name: string, args: AccountPrivilegeArgs, opts?: CustomResourceOptions);
@overload
def AccountPrivilege(resource_name: str,
                     opts: Optional[ResourceOptions] = None,
                     account_name: Optional[str] = None,
                     account_privilege: Optional[str] = None,
                     db_cluster_id: Optional[str] = None,
                     db_names: Optional[Sequence[str]] = None)
@overload
def AccountPrivilege(resource_name: str,
                     args: AccountPrivilegeArgs,
                     opts: Optional[ResourceOptions] = None)
func NewAccountPrivilege(ctx *Context, name string, args AccountPrivilegeArgs, opts ...ResourceOption) (*AccountPrivilege, error)
public AccountPrivilege(string name, AccountPrivilegeArgs args, CustomResourceOptions? opts = null)
public AccountPrivilege(String name, AccountPrivilegeArgs args)
public AccountPrivilege(String name, AccountPrivilegeArgs args, CustomResourceOptions options)
type: alicloud:polardb:AccountPrivilege
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args AccountPrivilegeArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args AccountPrivilegeArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args AccountPrivilegeArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args AccountPrivilegeArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args AccountPrivilegeArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

AccountPrivilege Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The AccountPrivilege resource accepts the following input properties:

AccountName string

A specified account name.

DbClusterId string

The Id of cluster in which account belongs.

DbNames List<string>

List of specified database name.

Privilege string

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

AccountName string

A specified account name.

DbClusterId string

The Id of cluster in which account belongs.

DbNames []string

List of specified database name.

AccountPrivilege string

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

accountName String

A specified account name.

dbClusterId String

The Id of cluster in which account belongs.

dbNames List

List of specified database name.

accountPrivilege String

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

accountName string

A specified account name.

dbClusterId string

The Id of cluster in which account belongs.

dbNames string[]

List of specified database name.

accountPrivilege string

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

account_name str

A specified account name.

db_cluster_id str

The Id of cluster in which account belongs.

db_names Sequence[str]

List of specified database name.

account_privilege str

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

accountName String

A specified account name.

dbClusterId String

The Id of cluster in which account belongs.

dbNames List

List of specified database name.

accountPrivilege String

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

Outputs

All input properties are implicitly available as output properties. Additionally, the AccountPrivilege resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Id string

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

id string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up an Existing AccountPrivilege Resource

Get an existing AccountPrivilege resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: AccountPrivilegeState, opts?: CustomResourceOptions): AccountPrivilege
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        account_name: Optional[str] = None,
        account_privilege: Optional[str] = None,
        db_cluster_id: Optional[str] = None,
        db_names: Optional[Sequence[str]] = None) -> AccountPrivilege
func GetAccountPrivilege(ctx *Context, name string, id IDInput, state *AccountPrivilegeState, opts ...ResourceOption) (*AccountPrivilege, error)
public static AccountPrivilege Get(string name, Input<string> id, AccountPrivilegeState? state, CustomResourceOptions? opts = null)
public static AccountPrivilege get(String name, Output<String> id, AccountPrivilegeState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
AccountName string

A specified account name.

DbClusterId string

The Id of cluster in which account belongs.

DbNames List<string>

List of specified database name.

Privilege string

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

AccountName string

A specified account name.

AccountPrivilege string

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

DbClusterId string

The Id of cluster in which account belongs.

DbNames []string

List of specified database name.

accountName String

A specified account name.

accountPrivilege String

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

dbClusterId String

The Id of cluster in which account belongs.

dbNames List

List of specified database name.

accountName string

A specified account name.

accountPrivilege string

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

dbClusterId string

The Id of cluster in which account belongs.

dbNames string[]

List of specified database name.

account_name str

A specified account name.

account_privilege str

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

db_cluster_id str

The Id of cluster in which account belongs.

db_names Sequence[str]

List of specified database name.

accountName String

A specified account name.

accountPrivilege String

The privilege of one account access database. Valid values: ["ReadOnly", "ReadWrite"], ["DMLOnly", "DDLOnly"] added since version v1.101.0. Default to "ReadOnly".

dbClusterId String

The Id of cluster in which account belongs.

dbNames List

List of specified database name.

Import

PolarDB account privilege can be imported using the id, e.g.

 $ pulumi import alicloud:polardb/accountPrivilege:AccountPrivilege example "pc-12345:tf_account:ReadOnly"

Package Details

Repository
https://github.com/pulumi/pulumi-alicloud
License
Apache-2.0
Notes

This Pulumi package is based on the alicloud Terraform Provider.