alicloud.rds.AccountPrivilege
Explore with Pulumi AI
Provides an RDS account privilege resource and used to grant several database some access privilege. A database can be granted by multiple account, see What is DB Account Privilege.
NOTE: At present, a database can only have one database owner.
NOTE: Available since v1.5.0.
Example Usage
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using AliCloud = Pulumi.AliCloud;
return await Deployment.RunAsync(() =>
{
var config = new Config();
var name = config.Get("name") ?? "tf_example";
var defaultZones = AliCloud.Rds.GetZones.Invoke(new()
{
Engine = "MySQL",
EngineVersion = "5.6",
});
var defaultNetwork = new AliCloud.Vpc.Network("defaultNetwork", new()
{
VpcName = name,
CidrBlock = "172.16.0.0/16",
});
var defaultSwitch = new AliCloud.Vpc.Switch("defaultSwitch", new()
{
VpcId = defaultNetwork.Id,
CidrBlock = "172.16.0.0/24",
ZoneId = defaultZones.Apply(getZonesResult => getZonesResult.Zones[0]?.Id),
VswitchName = name,
});
var instance = new AliCloud.Rds.Instance("instance", new()
{
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()
{
InstanceId = instance.Id,
Description = "from terraform",
}));
}
var account = new AliCloud.Rds.Account("account", new()
{
DbInstanceId = instance.Id,
AccountName = "tfexample",
AccountPassword = "Example12345",
AccountDescription = "from terraform",
});
var privilege = new AliCloud.Rds.AccountPrivilege("privilege", new()
{
InstanceId = instance.Id,
AccountName = account.Name,
Privilege = "ReadOnly",
DbNames = db.Select(__item => __item.Name).ToList(),
});
});
package main
import (
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/rds"
"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, "")
name := "tf_example"
if param := cfg.Get("name"); param != "" {
name = param
}
defaultZones, err := rds.GetZones(ctx, &rds.GetZonesArgs{
Engine: pulumi.StringRef("MySQL"),
EngineVersion: pulumi.StringRef("5.6"),
}, nil)
if err != nil {
return err
}
defaultNetwork, err := vpc.NewNetwork(ctx, "defaultNetwork", &vpc.NetworkArgs{
VpcName: pulumi.String(name),
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),
VswitchName: pulumi.String(name),
})
if err != nil {
return err
}
instance, err := rds.NewInstance(ctx, "instance", &rds.InstanceArgs{
Engine: pulumi.String("MySQL"),
EngineVersion: pulumi.String("5.6"),
InstanceType: pulumi.String("rds.mysql.s1.small"),
InstanceStorage: pulumi.Int(10),
VswitchId: defaultSwitch.ID(),
InstanceName: pulumi.String(name),
})
if err != nil {
return err
}
var db []*rds.Database
for index := 0; index < 2; index++ {
key0 := index
_ := index
__res, err := rds.NewDatabase(ctx, fmt.Sprintf("db-%v", key0), &rds.DatabaseArgs{
InstanceId: instance.ID(),
Description: pulumi.String("from terraform"),
})
if err != nil {
return err
}
db = append(db, __res)
}
account, err := rds.NewAccount(ctx, "account", &rds.AccountArgs{
DbInstanceId: instance.ID(),
AccountName: pulumi.String("tfexample"),
AccountPassword: pulumi.String("Example12345"),
AccountDescription: pulumi.String("from terraform"),
})
if err != nil {
return err
}
var splat0 pulumi.StringArray
for _, val0 := range db {
splat0 = append(splat0, val0.Name)
}
_, err = rds.NewAccountPrivilege(ctx, "privilege", &rds.AccountPrivilegeArgs{
InstanceId: instance.ID(),
AccountName: account.Name,
Privilege: pulumi.String("ReadOnly"),
DbNames: splat0,
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.rds.RdsFunctions;
import com.pulumi.alicloud.rds.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 name = config.get("name").orElse("tf_example");
final var defaultZones = RdsFunctions.getZones(GetZonesArgs.builder()
.engine("MySQL")
.engineVersion("5.6")
.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()
.dbInstanceId(instance.id())
.accountName("tfexample")
.accountPassword("Example12345")
.accountDescription("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()
name = config.get("name")
if name is None:
name = "tf_example"
default_zones = alicloud.rds.get_zones(engine="MySQL",
engine_version="5.6")
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",
db_instance_id=instance.id,
account_name="tfexample",
account_password="Example12345",
account_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 name = config.get("name") || "tf_example";
const defaultZones = alicloud.rds.getZones({
engine: "MySQL",
engineVersion: "5.6",
});
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", {
dbInstanceId: instance.id,
accountName: "tfexample",
accountPassword: "Example12345",
accountDescription: "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 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:
- Account
Name string A specified account name.
- Db
Names List<string> List of specified database name.
- Instance
Id 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. Default to "ReadOnly".
- Account
Name string A specified account name.
- Db
Names []string List of specified database name.
- Instance
Id 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. Default to "ReadOnly".
- account
Name String A specified account name.
- db
Names List<String> List of specified database name.
- instance
Id 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. Default to "ReadOnly".
- account
Name string A specified account name.
- db
Names string[] List of specified database name.
- instance
Id 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. Default to "ReadOnly".
- 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. Default to "ReadOnly".
- account
Name String A specified account name.
- db
Names List<String> List of specified database name.
- instance
Id 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. 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 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.
- Account
Name string A specified account name.
- Db
Names List<string> List of specified database name.
- Instance
Id 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. Default to "ReadOnly".
- Account
Name string A specified account name.
- Db
Names []string List of specified database name.
- Instance
Id 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. Default to "ReadOnly".
- account
Name String A specified account name.
- db
Names List<String> List of specified database name.
- instance
Id 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. Default to "ReadOnly".
- account
Name string A specified account name.
- db
Names string[] List of specified database name.
- instance
Id 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. Default to "ReadOnly".
- 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. Default to "ReadOnly".
- account
Name String A specified account name.
- db
Names List<String> List of specified database name.
- instance
Id 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. Default to "ReadOnly".
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
- Alibaba Cloud pulumi/pulumi-alicloud
- License
- Apache-2.0
- Notes
This Pulumi package is based on the
alicloud
Terraform Provider.