DomainPolicy class
Allows setting policy to an OpenSearch domain while referencing domain attributes (e.g., ARN).
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.opensearch.Domain("example", {
domainName: "tf-test",
engineVersion: "OpenSearch_1.1",
});
const main = aws.iam.getPolicyDocumentOutput({
statements: [{
conditions: [{
test: "IpAddress",
variable: "aws:SourceIp",
values: ["127.0.0.1/32"],
}],
principals: [{
type: "*",
identifiers: ["*"],
}],
effect: "Allow",
actions: ["es:*"],
resources: [pulumi.interpolate`${example.arn}/*`],
}],
});
const mainDomainPolicy = new aws.opensearch.DomainPolicy("main", {
domainName: example.domainName,
accessPolicies: main.json,
});
import pulumi
import pulumi_aws as aws
example = aws.opensearch.Domain("example",
domain_name="tf-test",
engine_version="OpenSearch_1.1")
main = aws.iam.get_policy_document_output(statements=[{
"conditions": [{
"test": "IpAddress",
"variable": "aws:SourceIp",
"values": ["127.0.0.1/32"],
}],
"principals": [{
"type": "*",
"identifiers": ["*"],
}],
"effect": "Allow",
"actions": ["es:*"],
"resources": [example.arn.apply(lambda arn: f"{arn}/*")],
}])
main_domain_policy = aws.opensearch.DomainPolicy("main",
domain_name=example.domain_name,
access_policies=main.json)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.OpenSearch.Domain("example", new()
{
DomainName = "tf-test",
EngineVersion = "OpenSearch_1.1",
});
var main = Aws.Iam.GetPolicyDocument.Invoke(new()
{
Statements = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
{
Conditions = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementConditionInputArgs
{
Test = "IpAddress",
Variable = "aws:SourceIp",
Values = new[]
{
"127.0.0.1/32",
},
},
},
Principals = new[]
{
new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
{
Type = "*",
Identifiers = new[]
{
"*",
},
},
},
Effect = "Allow",
Actions = new[]
{
"es:*",
},
Resources = new[]
{
$"{example.Arn}/*",
},
},
},
});
var mainDomainPolicy = new Aws.OpenSearch.DomainPolicy("main", new()
{
DomainName = example.DomainName,
AccessPolicies = main.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
});
});
package main
import (
"fmt"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/opensearch"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
example, err := opensearch.NewDomain(ctx, "example", &opensearch.DomainArgs{
DomainName: pulumi.String("tf-test"),
EngineVersion: pulumi.String("OpenSearch_1.1"),
})
if err != nil {
return err
}
main := iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
Statements: iam.GetPolicyDocumentStatementArray{
&iam.GetPolicyDocumentStatementArgs{
Conditions: iam.GetPolicyDocumentStatementConditionArray{
&iam.GetPolicyDocumentStatementConditionArgs{
Test: pulumi.String("IpAddress"),
Variable: pulumi.String("aws:SourceIp"),
Values: pulumi.StringArray{
pulumi.String("127.0.0.1/32"),
},
},
},
Principals: iam.GetPolicyDocumentStatementPrincipalArray{
&iam.GetPolicyDocumentStatementPrincipalArgs{
Type: pulumi.String("*"),
Identifiers: pulumi.StringArray{
pulumi.String("*"),
},
},
},
Effect: pulumi.String("Allow"),
Actions: pulumi.StringArray{
pulumi.String("es:*"),
},
Resources: pulumi.StringArray{
example.Arn.ApplyT(func(arn string) (string, error) {
return fmt.Sprintf("%v/*", arn), nil
}).(pulumi.StringOutput),
},
},
},
}, nil)
_, err = opensearch.NewDomainPolicy(ctx, "main", &opensearch.DomainPolicyArgs{
DomainName: example.DomainName,
AccessPolicies: main.Json(),
})
if err != nil {
return err
}
return nil
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
data "aws_iam_getpolicydocument" "main" {
statements {
conditions {
test = "IpAddress"
variable = "aws:SourceIp"
values = ["127.0.0.1/32"]
}
principals {
type = "*"
identifiers = ["*"]
}
effect = "Allow"
actions = ["es:*"]
resources = ["${aws_opensearch_domain.example.arn}/*"]
}
}
resource "aws_opensearch_domain" "example" {
domain_name = "tf-test"
engine_version = "OpenSearch_1.1"
}
resource "aws_opensearch_domainpolicy" "main" {
domain_name = aws_opensearch_domain.example.domain_name
access_policies = data.aws_iam_getpolicydocument.main.json
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.opensearch.Domain;
import com.pulumi.aws.opensearch.DomainArgs;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementConditionArgs;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
import com.pulumi.aws.opensearch.DomainPolicy;
import com.pulumi.aws.opensearch.DomainPolicyArgs;
import java.util.ArrayList;
import java.util.Arrays;
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) {
var example = new Domain("example", DomainArgs.builder()
.domainName("tf-test")
.engineVersion("OpenSearch_1.1")
.build());
final var main = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.conditions(GetPolicyDocumentStatementConditionArgs.builder()
.test("IpAddress")
.variable("aws:SourceIp")
.values("127.0.0.1/32")
.build())
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("*")
.identifiers("*")
.build())
.effect("Allow")
.actions("es:*")
.resources(example.arn().applyValue(_arn -> String.format("%s/*", _arn)))
.build())
.build());
var mainDomainPolicy = new DomainPolicy("mainDomainPolicy", DomainPolicyArgs.builder()
.domainName(example.domainName())
.accessPolicies(main.applyValue(_main -> _main.json()))
.build());
}
}
resources:
example:
type: aws:opensearch:Domain
properties:
domainName: tf-test
engineVersion: OpenSearch_1.1
mainDomainPolicy:
type: aws:opensearch:DomainPolicy
name: main
properties:
domainName: ${example.domainName}
accessPolicies: ${main.json}
variables:
main:
fn::invoke:
function: aws:iam:getPolicyDocument
arguments:
statements:
- conditions:
- test: IpAddress
variable: aws:SourceIp
values:
- 127.0.0.1/32
principals:
- type: '*'
identifiers:
- '*'
effect: Allow
actions:
- es:*
resources:
- ${example.arn}/*
Import
Using pulumi import, import OpenSearch Domain Policy using domainName prefixed with esd-policy-. For example:
$ pulumi import aws:opensearch/domainPolicy:DomainPolicy example esd-policy-tf-test
Constructors
- DomainPolicy(String name, {DomainPolicyArgs? args, CustomResourceOptions? options})
-
Creates a new DomainPolicy.
nameThe Pulumi resource name.argsArguments used to configure this DomainPolicy. The set of arguments for DomainPolicy.optionsResource options controlling this resource's behavior. - DomainPolicy.reference(String urn)
- Creates a typed reference to an existing DomainPolicy resource.
Properties
-
accessPolicies
↔ Output<
String> -
IAM policy document specifying the access policies for the domain
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
domainName
↔ Output<
String> -
Name of the domain.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
id
↔ Output<
String> -
getter/setter pairinherited
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {DomainPolicyState? state, CustomResourceOptions? options}) → DomainPolicy -
Gets an existing DomainPolicy resource's state with the given
nameandid.