Alibaba Cloud

Pulumi Official
Package maintained by Pulumi
v3.27.0 published on Monday, Aug 8, 2022 by Pulumi

AccountPrivilege

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

NOTE: At present, a database can only have one database owner.

Example Usage

using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;

class MyStack : Stack
{
    public MyStack()
    {
        var config = new Config();
        var creation = config.Get("creation") ?? "Rds";
        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
        {
            VpcName = name,
            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),
            VswitchName = name,
        });
        var instance = new AliCloud.Rds.Instance("instance", new AliCloud.Rds.InstanceArgs
        {
            Engine = "MySQL",
            EngineVersion = "5.6",
            InstanceType = "rds.mysql.s1.small",
            InstanceStorage = 10,
            VswitchId = defaultSwitch.Id,
            InstanceName = name,
        });
        var db = new List<AliCloud.Rds.Database>();
        for (var rangeIndex = 0; rangeIndex < 2; rangeIndex++)
        {
            var range = new { Value = rangeIndex };
            db.Add(new AliCloud.Rds.Database($"db-{range.Value}", new AliCloud.Rds.DatabaseArgs
            {
                InstanceId = instance.Id,
                Description = "from terraform",
            }));
        }
        var account = new AliCloud.Rds.Account("account", new AliCloud.Rds.AccountArgs
        {
            InstanceId = instance.Id,
            Password = "Test12345",
            Description = "from terraform",
        });
        var privilege = new AliCloud.Rds.AccountPrivilege("privilege", new AliCloud.Rds.AccountPrivilegeArgs
        {
            InstanceId = instance.Id,
            AccountName = account.Name,
            Privilege = "ReadOnly",
            DbNames = db.Select(__item => __item.Name).ToList(),
        });
    }

}

Coming soon!

package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.AlicloudFunctions;
import com.pulumi.alicloud.adb.inputs.GetZonesArgs;
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.rds.Instance;
import com.pulumi.alicloud.rds.InstanceArgs;
import com.pulumi.alicloud.rds.Database;
import com.pulumi.alicloud.rds.DatabaseArgs;
import com.pulumi.alicloud.rds.Account;
import com.pulumi.alicloud.rds.AccountArgs;
import com.pulumi.alicloud.rds.AccountPrivilege;
import com.pulumi.alicloud.rds.AccountPrivilegeArgs;
import com.pulumi.codegen.internal.KeyedValue;
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 config = ctx.config();
        final var creation = config.get("creation").orElse("Rds");
        final var name = config.get("name").orElse("dbaccountprivilegebasic");
        final var defaultZones = AlicloudFunctions.getZones(GetZonesArgs.builder()
            .availableResourceCreation(creation)
            .build());

        var defaultNetwork = new Network("defaultNetwork", NetworkArgs.builder()        
            .vpcName(name)
            .cidrBlock("172.16.0.0/16")
            .build());

        var defaultSwitch = new Switch("defaultSwitch", SwitchArgs.builder()        
            .vpcId(defaultNetwork.id())
            .cidrBlock("172.16.0.0/24")
            .zoneId(defaultZones.applyValue(getZonesResult -> getZonesResult.zones()[0].id()))
            .vswitchName(name)
            .build());

        var instance = new Instance("instance", InstanceArgs.builder()        
            .engine("MySQL")
            .engineVersion("5.6")
            .instanceType("rds.mysql.s1.small")
            .instanceStorage("10")
            .vswitchId(defaultSwitch.id())
            .instanceName(name)
            .build());

        for (var i = 0; i < 2; i++) {
            new Database("db-" + i, DatabaseArgs.builder()            
                .instanceId(instance.id())
                .description("from terraform")
                .build());

        
}
        var account = new Account("account", AccountArgs.builder()        
            .instanceId(instance.id())
            .password("Test12345")
            .description("from terraform")
            .build());

        var privilege = new AccountPrivilege("privilege", AccountPrivilegeArgs.builder()        
            .instanceId(instance.id())
            .accountName(account.name())
            .privilege("ReadOnly")
            .dbNames(db.stream().map(element -> element.name()).collect(toList()))
            .build());

    }
}
import pulumi
import pulumi_alicloud as alicloud

config = pulumi.Config()
creation = config.get("creation")
if creation is None:
    creation = "Rds"
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",
    vpc_name=name,
    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,
    vswitch_name=name)
instance = alicloud.rds.Instance("instance",
    engine="MySQL",
    engine_version="5.6",
    instance_type="rds.mysql.s1.small",
    instance_storage=10,
    vswitch_id=default_switch.id,
    instance_name=name)
db = []
for range in [{"value": i} for i in range(0, 2)]:
    db.append(alicloud.rds.Database(f"db-{range['value']}",
        instance_id=instance.id,
        description="from terraform"))
account = alicloud.rds.Account("account",
    instance_id=instance.id,
    password="Test12345",
    description="from terraform")
privilege = alicloud.rds.AccountPrivilege("privilege",
    instance_id=instance.id,
    account_name=account.name,
    privilege="ReadOnly",
    db_names=[__item.name for __item in db])
import * as pulumi from "@pulumi/pulumi";
import * as alicloud from "@pulumi/alicloud";

const config = new pulumi.Config();
const creation = config.get("creation") || "Rds";
const name = config.get("name") || "dbaccountprivilegebasic";
const defaultZones = alicloud.getZones({
    availableResourceCreation: creation,
});
const defaultNetwork = new alicloud.vpc.Network("defaultNetwork", {
    vpcName: name,
    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),
    vswitchName: name,
});
const instance = new alicloud.rds.Instance("instance", {
    engine: "MySQL",
    engineVersion: "5.6",
    instanceType: "rds.mysql.s1.small",
    instanceStorage: 10,
    vswitchId: defaultSwitch.id,
    instanceName: name,
});
const db: alicloud.rds.Database[];
for (const range = {value: 0}; range.value < 2; range.value++) {
    db.push(new alicloud.rds.Database(`db-${range.value}`, {
        instanceId: instance.id,
        description: "from terraform",
    }));
}
const account = new alicloud.rds.Account("account", {
    instanceId: instance.id,
    password: "Test12345",
    description: "from terraform",
});
const privilege = new alicloud.rds.AccountPrivilege("privilege", {
    instanceId: instance.id,
    accountName: account.name,
    privilege: "ReadOnly",
    dbNames: db.map(__item => __item.name),
});

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,
                     db_names: Optional[Sequence[str]] = None,
                     instance_id: Optional[str] = None,
                     privilege: Optional[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:rds: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.

DbNames List<string>

List of specified database name.

InstanceId string

The Id of instance in which account belongs.

Privilege string

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
AccountName string

A specified account name.

DbNames []string

List of specified database name.

InstanceId string

The Id of instance in which account belongs.

Privilege string

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
accountName String

A specified account name.

dbNames List<String>

List of specified database name.

instanceId String

The Id of instance in which account belongs.

privilege String

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
accountName string

A specified account name.

dbNames string[]

List of specified database name.

instanceId string

The Id of instance in which account belongs.

privilege string

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
account_name str

A specified account name.

db_names Sequence[str]

List of specified database name.

instance_id str

The Id of instance in which account belongs.

privilege str

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
accountName String

A specified account name.

dbNames List<String>

List of specified database name.

instanceId String

The Id of instance in which account belongs.

privilege String

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.

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,
        db_names: Optional[Sequence[str]] = None,
        instance_id: Optional[str] = None,
        privilege: Optional[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.

DbNames List<string>

List of specified database name.

InstanceId string

The Id of instance in which account belongs.

Privilege string

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
AccountName string

A specified account name.

DbNames []string

List of specified database name.

InstanceId string

The Id of instance in which account belongs.

Privilege string

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
accountName String

A specified account name.

dbNames List<String>

List of specified database name.

instanceId String

The Id of instance in which account belongs.

privilege String

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
accountName string

A specified account name.

dbNames string[]

List of specified database name.

instanceId string

The Id of instance in which account belongs.

privilege string

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
account_name str

A specified account name.

db_names Sequence[str]

List of specified database name.

instance_id str

The Id of instance in which account belongs.

privilege str

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.
accountName String

A specified account name.

dbNames List<String>

List of specified database name.

instanceId String

The Id of instance in which account belongs.

privilege String

The privilege of one account access database. Valid values:

  • ReadOnly: This value is only for MySQL, MariaDB and SQL Server
  • ReadWrite: This value is only for MySQL, MariaDB and SQL Server
  • DDLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DMLOnly: (Available in 1.64.0+) This value is only for MySQL and MariaDB
  • DBOwner: (Available in 1.64.0+) This value is only for SQL Server and PostgreSQL.

Import

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

 $ pulumi import alicloud:rds/accountPrivilege:AccountPrivilege example "rm-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.