alicloud.mongodb.ReplicaSetRole
Explore with Pulumi AI
Provides an Alicloud MongoDB replica set role resource to modify the connection string of the replica set.
For information about how to modify connection string of MongoDB, see Modify Connection String.
NOTE: Available since v1.248.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.mongodb.getZones({});
const index = _default.then(_default => _default.zones).length.apply(length => length - 1);
const zoneId = _default.then(_default => _default.zones[index].id);
const defaultNetwork = new alicloud.vpc.Network("default", {
cidrBlock: "10.0.0.0/8",
vpcName: name,
});
const defaultSwitch = new alicloud.vpc.Switch("default", {
vpcId: defaultNetwork.id,
zoneId: zoneId,
cidrBlock: "10.0.0.0/24",
});
const defaultInstance = new alicloud.mongodb.Instance("default", {
engineVersion: "4.4",
storageType: "cloud_essd1",
vswitchId: defaultSwitch.id,
dbInstanceStorage: 20,
vpcId: defaultNetwork.id,
dbInstanceClass: "mdb.shard.4x.large.d",
storageEngine: "WiredTiger",
networkType: "VPC",
zoneId: zoneId,
});
const defaultPublicNetworkAddress = new alicloud.mongodb.PublicNetworkAddress("default", {dbInstanceId: defaultInstance.id});
// modify private network address.
const _private = new alicloud.mongodb.ReplicaSetRole("private", {
dbInstanceId: defaultInstance.id,
roleId: defaultInstance.replicaSets.apply(replicaSets => replicaSets[0].roleId),
connectionPrefix: "test-tf-private-change",
connectionPort: 3718,
networkType: "VPC",
});
// modify public network address.
const _public = new alicloud.mongodb.ReplicaSetRole("public", {
dbInstanceId: defaultInstance.id,
roleId: defaultPublicNetworkAddress.replicaSets.apply(replicaSets => replicaSets[0].roleId),
connectionPrefix: "test-tf-public-0",
connectionPort: 3719,
networkType: "Public",
});
import pulumi
import pulumi_alicloud as alicloud
config = pulumi.Config()
name = config.get("name")
if name is None:
name = "tf-example"
default = alicloud.mongodb.get_zones()
index = len(default.zones).apply(lambda length: length - 1)
zone_id = default.zones[index].id
default_network = alicloud.vpc.Network("default",
cidr_block="10.0.0.0/8",
vpc_name=name)
default_switch = alicloud.vpc.Switch("default",
vpc_id=default_network.id,
zone_id=zone_id,
cidr_block="10.0.0.0/24")
default_instance = alicloud.mongodb.Instance("default",
engine_version="4.4",
storage_type="cloud_essd1",
vswitch_id=default_switch.id,
db_instance_storage=20,
vpc_id=default_network.id,
db_instance_class="mdb.shard.4x.large.d",
storage_engine="WiredTiger",
network_type="VPC",
zone_id=zone_id)
default_public_network_address = alicloud.mongodb.PublicNetworkAddress("default", db_instance_id=default_instance.id)
# modify private network address.
private = alicloud.mongodb.ReplicaSetRole("private",
db_instance_id=default_instance.id,
role_id=default_instance.replica_sets[0].role_id,
connection_prefix="test-tf-private-change",
connection_port=3718,
network_type="VPC")
# modify public network address.
public = alicloud.mongodb.ReplicaSetRole("public",
db_instance_id=default_instance.id,
role_id=default_public_network_address.replica_sets[0].role_id,
connection_prefix="test-tf-public-0",
connection_port=3719,
network_type="Public")
package main
import (
"github.com/pulumi/pulumi-alicloud/sdk/v3/go/alicloud/mongodb"
"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 := mongodb.GetZones(ctx, &mongodb.GetZonesArgs{}, nil)
if err != nil {
return err
}
index := len(_default.Zones).ApplyT(func(length int) (float64, error) {
return length - 1, nil
}).(pulumi.Float64Output)
zoneId := _default.Zones[index].Id
defaultNetwork, err := vpc.NewNetwork(ctx, "default", &vpc.NetworkArgs{
CidrBlock: pulumi.String("10.0.0.0/8"),
VpcName: pulumi.String(name),
})
if err != nil {
return err
}
defaultSwitch, err := vpc.NewSwitch(ctx, "default", &vpc.SwitchArgs{
VpcId: defaultNetwork.ID(),
ZoneId: pulumi.String(zoneId),
CidrBlock: pulumi.String("10.0.0.0/24"),
})
if err != nil {
return err
}
defaultInstance, err := mongodb.NewInstance(ctx, "default", &mongodb.InstanceArgs{
EngineVersion: pulumi.String("4.4"),
StorageType: pulumi.String("cloud_essd1"),
VswitchId: defaultSwitch.ID(),
DbInstanceStorage: pulumi.Int(20),
VpcId: defaultNetwork.ID(),
DbInstanceClass: pulumi.String("mdb.shard.4x.large.d"),
StorageEngine: pulumi.String("WiredTiger"),
NetworkType: pulumi.String("VPC"),
ZoneId: pulumi.String(zoneId),
})
if err != nil {
return err
}
defaultPublicNetworkAddress, err := mongodb.NewPublicNetworkAddress(ctx, "default", &mongodb.PublicNetworkAddressArgs{
DbInstanceId: defaultInstance.ID(),
})
if err != nil {
return err
}
// modify private network address.
_, err = mongodb.NewReplicaSetRole(ctx, "private", &mongodb.ReplicaSetRoleArgs{
DbInstanceId: defaultInstance.ID(),
RoleId: pulumi.String(defaultInstance.ReplicaSets.ApplyT(func(replicaSets []mongodb.InstanceReplicaSet) (*string, error) {
return &replicaSets[0].RoleId, nil
}).(pulumi.StringPtrOutput)),
ConnectionPrefix: pulumi.String("test-tf-private-change"),
ConnectionPort: pulumi.Int(3718),
NetworkType: pulumi.String("VPC"),
})
if err != nil {
return err
}
// modify public network address.
_, err = mongodb.NewReplicaSetRole(ctx, "public", &mongodb.ReplicaSetRoleArgs{
DbInstanceId: defaultInstance.ID(),
RoleId: pulumi.String(defaultPublicNetworkAddress.ReplicaSets.ApplyT(func(replicaSets []mongodb.PublicNetworkAddressReplicaSet) (*string, error) {
return &replicaSets[0].RoleId, nil
}).(pulumi.StringPtrOutput)),
ConnectionPrefix: pulumi.String("test-tf-public-0"),
ConnectionPort: pulumi.Int(3719),
NetworkType: pulumi.String("Public"),
})
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.MongoDB.GetZones.Invoke();
var index = @default.Apply(@default => @default.Apply(getZonesResult => getZonesResult.Zones)).Length.Apply(length => length - 1);
var zoneId = @default.Apply(@default => @default.Apply(getZonesResult => getZonesResult.Zones)[index].Id);
var defaultNetwork = new AliCloud.Vpc.Network("default", new()
{
CidrBlock = "10.0.0.0/8",
VpcName = name,
});
var defaultSwitch = new AliCloud.Vpc.Switch("default", new()
{
VpcId = defaultNetwork.Id,
ZoneId = zoneId,
CidrBlock = "10.0.0.0/24",
});
var defaultInstance = new AliCloud.MongoDB.Instance("default", new()
{
EngineVersion = "4.4",
StorageType = "cloud_essd1",
VswitchId = defaultSwitch.Id,
DbInstanceStorage = 20,
VpcId = defaultNetwork.Id,
DbInstanceClass = "mdb.shard.4x.large.d",
StorageEngine = "WiredTiger",
NetworkType = "VPC",
ZoneId = zoneId,
});
var defaultPublicNetworkAddress = new AliCloud.MongoDB.PublicNetworkAddress("default", new()
{
DbInstanceId = defaultInstance.Id,
});
// modify private network address.
var @private = new AliCloud.MongoDB.ReplicaSetRole("private", new()
{
DbInstanceId = defaultInstance.Id,
RoleId = defaultInstance.ReplicaSets.Apply(replicaSets => replicaSets[0].RoleId),
ConnectionPrefix = "test-tf-private-change",
ConnectionPort = 3718,
NetworkType = "VPC",
});
// modify public network address.
var @public = new AliCloud.MongoDB.ReplicaSetRole("public", new()
{
DbInstanceId = defaultInstance.Id,
RoleId = defaultPublicNetworkAddress.ReplicaSets.Apply(replicaSets => replicaSets[0].RoleId),
ConnectionPrefix = "test-tf-public-0",
ConnectionPort = 3719,
NetworkType = "Public",
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.alicloud.mongodb.MongodbFunctions;
import com.pulumi.alicloud.mongodb.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.mongodb.Instance;
import com.pulumi.alicloud.mongodb.InstanceArgs;
import com.pulumi.alicloud.mongodb.PublicNetworkAddress;
import com.pulumi.alicloud.mongodb.PublicNetworkAddressArgs;
import com.pulumi.alicloud.mongodb.ReplicaSetRole;
import com.pulumi.alicloud.mongodb.ReplicaSetRoleArgs;
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 = MongodbFunctions.getZones(GetZonesArgs.builder()
.build());
final var index = default_.zones().length().applyValue(_length -> _length - 1);
final var zoneId = default_.zones()[index].id();
var defaultNetwork = new Network("defaultNetwork", NetworkArgs.builder()
.cidrBlock("10.0.0.0/8")
.vpcName(name)
.build());
var defaultSwitch = new Switch("defaultSwitch", SwitchArgs.builder()
.vpcId(defaultNetwork.id())
.zoneId(zoneId)
.cidrBlock("10.0.0.0/24")
.build());
var defaultInstance = new Instance("defaultInstance", InstanceArgs.builder()
.engineVersion("4.4")
.storageType("cloud_essd1")
.vswitchId(defaultSwitch.id())
.dbInstanceStorage(20)
.vpcId(defaultNetwork.id())
.dbInstanceClass("mdb.shard.4x.large.d")
.storageEngine("WiredTiger")
.networkType("VPC")
.zoneId(zoneId)
.build());
var defaultPublicNetworkAddress = new PublicNetworkAddress("defaultPublicNetworkAddress", PublicNetworkAddressArgs.builder()
.dbInstanceId(defaultInstance.id())
.build());
// modify private network address.
var private_ = new ReplicaSetRole("private", ReplicaSetRoleArgs.builder()
.dbInstanceId(defaultInstance.id())
.roleId(defaultInstance.replicaSets().applyValue(_replicaSets -> _replicaSets[0].roleId()))
.connectionPrefix("test-tf-private-change")
.connectionPort(3718)
.networkType("VPC")
.build());
// modify public network address.
var public_ = new ReplicaSetRole("public", ReplicaSetRoleArgs.builder()
.dbInstanceId(defaultInstance.id())
.roleId(defaultPublicNetworkAddress.replicaSets().applyValue(_replicaSets -> _replicaSets[0].roleId()))
.connectionPrefix("test-tf-public-0")
.connectionPort(3719)
.networkType("Public")
.build());
}
}
Coming soon!
Create ReplicaSetRole Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new ReplicaSetRole(name: string, args: ReplicaSetRoleArgs, opts?: CustomResourceOptions);
@overload
def ReplicaSetRole(resource_name: str,
args: ReplicaSetRoleArgs,
opts: Optional[ResourceOptions] = None)
@overload
def ReplicaSetRole(resource_name: str,
opts: Optional[ResourceOptions] = None,
db_instance_id: Optional[str] = None,
network_type: Optional[str] = None,
role_id: Optional[str] = None,
connection_port: Optional[int] = None,
connection_prefix: Optional[str] = None)
func NewReplicaSetRole(ctx *Context, name string, args ReplicaSetRoleArgs, opts ...ResourceOption) (*ReplicaSetRole, error)
public ReplicaSetRole(string name, ReplicaSetRoleArgs args, CustomResourceOptions? opts = null)
public ReplicaSetRole(String name, ReplicaSetRoleArgs args)
public ReplicaSetRole(String name, ReplicaSetRoleArgs args, CustomResourceOptions options)
type: alicloud:mongodb:ReplicaSetRole
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 ReplicaSetRoleArgs
- 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 ReplicaSetRoleArgs
- 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 ReplicaSetRoleArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args ReplicaSetRoleArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args ReplicaSetRoleArgs
- 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 replicaSetRoleResource = new AliCloud.MongoDB.ReplicaSetRole("replicaSetRoleResource", new()
{
DbInstanceId = "string",
NetworkType = "string",
RoleId = "string",
ConnectionPort = 0,
ConnectionPrefix = "string",
});
example, err := mongodb.NewReplicaSetRole(ctx, "replicaSetRoleResource", &mongodb.ReplicaSetRoleArgs{
DbInstanceId: pulumi.String("string"),
NetworkType: pulumi.String("string"),
RoleId: pulumi.String("string"),
ConnectionPort: pulumi.Int(0),
ConnectionPrefix: pulumi.String("string"),
})
var replicaSetRoleResource = new ReplicaSetRole("replicaSetRoleResource", ReplicaSetRoleArgs.builder()
.dbInstanceId("string")
.networkType("string")
.roleId("string")
.connectionPort(0)
.connectionPrefix("string")
.build());
replica_set_role_resource = alicloud.mongodb.ReplicaSetRole("replicaSetRoleResource",
db_instance_id="string",
network_type="string",
role_id="string",
connection_port=0,
connection_prefix="string")
const replicaSetRoleResource = new alicloud.mongodb.ReplicaSetRole("replicaSetRoleResource", {
dbInstanceId: "string",
networkType: "string",
roleId: "string",
connectionPort: 0,
connectionPrefix: "string",
});
type: alicloud:mongodb:ReplicaSetRole
properties:
connectionPort: 0
connectionPrefix: string
dbInstanceId: string
networkType: string
roleId: string
ReplicaSetRole Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.
The ReplicaSetRole resource accepts the following input properties:
- Db
Instance stringId - The instance ID.
- Network
Type string - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- Role
Id string - The role ID in the replica set.
- Connection
Port int - The port of the connection string, will be computed if not specified.`
- Connection
Prefix string - The prefix of the connection string, will be computed if not specified.
- Db
Instance stringId - The instance ID.
- Network
Type string - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- Role
Id string - The role ID in the replica set.
- Connection
Port int - The port of the connection string, will be computed if not specified.`
- Connection
Prefix string - The prefix of the connection string, will be computed if not specified.
- db
Instance StringId - The instance ID.
- network
Type String - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- role
Id String - The role ID in the replica set.
- connection
Port Integer - The port of the connection string, will be computed if not specified.`
- connection
Prefix String - The prefix of the connection string, will be computed if not specified.
- db
Instance stringId - The instance ID.
- network
Type string - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- role
Id string - The role ID in the replica set.
- connection
Port number - The port of the connection string, will be computed if not specified.`
- connection
Prefix string - The prefix of the connection string, will be computed if not specified.
- db_
instance_ strid - The instance ID.
- network_
type str - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- role_
id str - The role ID in the replica set.
- connection_
port int - The port of the connection string, will be computed if not specified.`
- connection_
prefix str - The prefix of the connection string, will be computed if not specified.
- db
Instance StringId - The instance ID.
- network
Type String - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- role
Id String - The role ID in the replica set.
- connection
Port Number - The port of the connection string, will be computed if not specified.`
- connection
Prefix String - The prefix of the connection string, will be computed if not specified.
Outputs
All input properties are implicitly available as output properties. Additionally, the ReplicaSetRole resource produces the following output properties:
- Connection
Domain string - The connection address of the role.
- Id string
- The provider-assigned unique ID for this managed resource.
- string
- The role of the related connection string.
- Connection
Domain string - The connection address of the role.
- Id string
- The provider-assigned unique ID for this managed resource.
- Replica
Set stringRole - The role of the related connection string.
- connection
Domain String - The connection address of the role.
- id String
- The provider-assigned unique ID for this managed resource.
- replica
Set StringRole - The role of the related connection string.
- connection
Domain string - The connection address of the role.
- id string
- The provider-assigned unique ID for this managed resource.
- replica
Set stringRole - The role of the related connection string.
- connection_
domain str - The connection address of the role.
- id str
- The provider-assigned unique ID for this managed resource.
- replica_
set_ strrole - The role of the related connection string.
- connection
Domain String - The connection address of the role.
- id String
- The provider-assigned unique ID for this managed resource.
- replica
Set StringRole - The role of the related connection string.
Look up Existing ReplicaSetRole Resource
Get an existing ReplicaSetRole 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?: ReplicaSetRoleState, opts?: CustomResourceOptions): ReplicaSetRole
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
connection_domain: Optional[str] = None,
connection_port: Optional[int] = None,
connection_prefix: Optional[str] = None,
db_instance_id: Optional[str] = None,
network_type: Optional[str] = None,
replica_set_role: Optional[str] = None,
role_id: Optional[str] = None) -> ReplicaSetRole
func GetReplicaSetRole(ctx *Context, name string, id IDInput, state *ReplicaSetRoleState, opts ...ResourceOption) (*ReplicaSetRole, error)
public static ReplicaSetRole Get(string name, Input<string> id, ReplicaSetRoleState? state, CustomResourceOptions? opts = null)
public static ReplicaSetRole get(String name, Output<String> id, ReplicaSetRoleState state, CustomResourceOptions options)
resources: _: type: alicloud:mongodb:ReplicaSetRole get: id: ${id}
- 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.
- Connection
Domain string - The connection address of the role.
- Connection
Port int - The port of the connection string, will be computed if not specified.`
- Connection
Prefix string - The prefix of the connection string, will be computed if not specified.
- Db
Instance stringId - The instance ID.
- Network
Type string - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- string
- The role of the related connection string.
- Role
Id string - The role ID in the replica set.
- Connection
Domain string - The connection address of the role.
- Connection
Port int - The port of the connection string, will be computed if not specified.`
- Connection
Prefix string - The prefix of the connection string, will be computed if not specified.
- Db
Instance stringId - The instance ID.
- Network
Type string - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- Replica
Set stringRole - The role of the related connection string.
- Role
Id string - The role ID in the replica set.
- connection
Domain String - The connection address of the role.
- connection
Port Integer - The port of the connection string, will be computed if not specified.`
- connection
Prefix String - The prefix of the connection string, will be computed if not specified.
- db
Instance StringId - The instance ID.
- network
Type String - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- replica
Set StringRole - The role of the related connection string.
- role
Id String - The role ID in the replica set.
- connection
Domain string - The connection address of the role.
- connection
Port number - The port of the connection string, will be computed if not specified.`
- connection
Prefix string - The prefix of the connection string, will be computed if not specified.
- db
Instance stringId - The instance ID.
- network
Type string - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- replica
Set stringRole - The role of the related connection string.
- role
Id string - The role ID in the replica set.
- connection_
domain str - The connection address of the role.
- connection_
port int - The port of the connection string, will be computed if not specified.`
- connection_
prefix str - The prefix of the connection string, will be computed if not specified.
- db_
instance_ strid - The instance ID.
- network_
type str - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- replica_
set_ strrole - The role of the related connection string.
- role_
id str - The role ID in the replica set.
- connection
Domain String - The connection address of the role.
- connection
Port Number - The port of the connection string, will be computed if not specified.`
- connection
Prefix String - The prefix of the connection string, will be computed if not specified.
- db
Instance StringId - The instance ID.
- network
Type String - The network type of the connection string. Valid values:
VPC
: private network address.Public
: public network address.
- replica
Set StringRole - The role of the related connection string.
- role
Id String - The role ID in the replica set.
Import
MongoDB replica set role can be imported using the id, e.g. Composed of instance ID, network type and role ID with format <db_instance_id>:<network_type>:<role_id>
.
$ pulumi import alicloud:mongodb/replicaSetRole:ReplicaSetRole example <id>
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.