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
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 default = alicloud.rds.getZones({
engine: "MySQL",
engineVersion: "5.6",
});
const defaultNetwork = new alicloud.vpc.Network("default", {
vpcName: name,
cidrBlock: "172.16.0.0/16",
});
const defaultSwitch = new alicloud.vpc.Switch("default", {
vpcId: defaultNetwork.id,
cidrBlock: "172.16.0.0/24",
zoneId: _default.then(_default => _default.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,
name: `${name}_${range.value}`,
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.accountName,
privilege: "ReadOnly",
dbNames: db.map(__item => __item.name),
});
import pulumi
import pulumi_alicloud as alicloud
config = pulumi.Config()
name = config.get("name")
if name is None:
name = "tf_example"
default = alicloud.rds.get_zones(engine="MySQL",
engine_version="5.6")
default_network = alicloud.vpc.Network("default",
vpc_name=name,
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=default.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,
name=f"{name}_{range['value']}",
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.account_name,
privilege="ReadOnly",
db_names=[__item.name for __item in db])
package main
import (
"fmt"
"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
}
_default, 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, "default", &vpc.NetworkArgs{
VpcName: pulumi.String(name),
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(_default.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
val0 := index
__res, err := rds.NewDatabase(ctx, fmt.Sprintf("db-%v", key0), &rds.DatabaseArgs{
InstanceId: instance.ID(),
Name: pulumi.Sprintf("%v_%v", name, val0),
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.AccountName,
Privilege: pulumi.String("ReadOnly"),
DbNames: splat0,
})
if err != nil {
return err
}
return nil
})
}
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 @default = AliCloud.Rds.GetZones.Invoke(new()
{
Engine = "MySQL",
EngineVersion = "5.6",
});
var defaultNetwork = new AliCloud.Vpc.Network("default", new()
{
VpcName = name,
CidrBlock = "172.16.0.0/16",
});
var defaultSwitch = new AliCloud.Vpc.Switch("default", new()
{
VpcId = defaultNetwork.Id,
CidrBlock = "172.16.0.0/24",
ZoneId = @default.Apply(@default => @default.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,
Name = $"{name}_{range.Value}",
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.AccountName,
Privilege = "ReadOnly",
DbNames = db.Select(__item => __item.Name).ToList(),
});
});
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 default = 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(default_.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())
.name(String.format("%s_%s", name,range.value()))
.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.accountName())
.privilege("ReadOnly")
.dbNames(db.stream().map(element -> element.name()).collect(toList()))
.build());
}
}
Coming soon!
Create AccountPrivilege Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new AccountPrivilege(name: string, args: AccountPrivilegeArgs, opts?: CustomResourceOptions);
@overload
def AccountPrivilege(resource_name: str,
args: AccountPrivilegeArgs,
opts: Optional[ResourceOptions] = None)
@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)
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.
Parameters
- 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.
Constructor example
The following reference example uses placeholder values for all input properties.
var alicloudAccountPrivilegeResource = new AliCloud.Rds.AccountPrivilege("alicloudAccountPrivilegeResource", new()
{
AccountName = "string",
DbNames = new[]
{
"string",
},
InstanceId = "string",
Privilege = "string",
});
example, err := rds.NewAccountPrivilege(ctx, "alicloudAccountPrivilegeResource", &rds.AccountPrivilegeArgs{
AccountName: pulumi.String("string"),
DbNames: pulumi.StringArray{
pulumi.String("string"),
},
InstanceId: pulumi.String("string"),
Privilege: pulumi.String("string"),
})
var alicloudAccountPrivilegeResource = new AccountPrivilege("alicloudAccountPrivilegeResource", AccountPrivilegeArgs.builder()
.accountName("string")
.dbNames("string")
.instanceId("string")
.privilege("string")
.build());
alicloud_account_privilege_resource = alicloud.rds.AccountPrivilege("alicloudAccountPrivilegeResource",
account_name="string",
db_names=["string"],
instance_id="string",
privilege="string")
const alicloudAccountPrivilegeResource = new alicloud.rds.AccountPrivilege("alicloudAccountPrivilegeResource", {
accountName: "string",
dbNames: ["string"],
instanceId: "string",
privilege: "string",
});
type: alicloud:rds:AccountPrivilege
properties:
accountName: string
dbNames:
- string
instanceId: string
privilege: string
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"
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- Alibaba Cloud pulumi/pulumi-alicloud
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
alicloud
Terraform Provider.