1. Packages
  2. AWS Classic
  3. API Docs
  4. cloudwatch
  5. LogResourcePolicy

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.23.0 published on Thursday, Feb 22, 2024 by Pulumi

aws.cloudwatch.LogResourcePolicy

Explore with Pulumi AI

aws logo

Try AWS Native preview for resources not in the classic version.

AWS Classic v6.23.0 published on Thursday, Feb 22, 2024 by Pulumi

    Provides a resource to manage a CloudWatch log resource policy.

    Example Usage

    Elasticsearch Log Publishing

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var elasticsearch_log_publishing_policyPolicyDocument = Aws.Iam.GetPolicyDocument.Invoke(new()
        {
            Statements = new[]
            {
                new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
                {
                    Actions = new[]
                    {
                        "logs:CreateLogStream",
                        "logs:PutLogEvents",
                        "logs:PutLogEventsBatch",
                    },
                    Resources = new[]
                    {
                        "arn:aws:logs:*",
                    },
                    Principals = new[]
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                        {
                            Identifiers = new[]
                            {
                                "es.amazonaws.com",
                            },
                            Type = "Service",
                        },
                    },
                },
            },
        });
    
        var elasticsearch_log_publishing_policyLogResourcePolicy = new Aws.CloudWatch.LogResourcePolicy("elasticsearch-log-publishing-policyLogResourcePolicy", new()
        {
            PolicyDocument = elasticsearch_log_publishing_policyPolicyDocument.Apply(elasticsearch_log_publishing_policyPolicyDocument => elasticsearch_log_publishing_policyPolicyDocument.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json)),
            PolicyName = "elasticsearch-log-publishing-policy",
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cloudwatch"
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		elasticsearch_log_publishing_policyPolicyDocument, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
    			Statements: []iam.GetPolicyDocumentStatement{
    				{
    					Actions: []string{
    						"logs:CreateLogStream",
    						"logs:PutLogEvents",
    						"logs:PutLogEventsBatch",
    					},
    					Resources: []string{
    						"arn:aws:logs:*",
    					},
    					Principals: []iam.GetPolicyDocumentStatementPrincipal{
    						{
    							Identifiers: []string{
    								"es.amazonaws.com",
    							},
    							Type: "Service",
    						},
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = cloudwatch.NewLogResourcePolicy(ctx, "elasticsearch-log-publishing-policyLogResourcePolicy", &cloudwatch.LogResourcePolicyArgs{
    			PolicyDocument: *pulumi.String(elasticsearch_log_publishing_policyPolicyDocument.Json),
    			PolicyName:     pulumi.String("elasticsearch-log-publishing-policy"),
    		})
    		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.aws.iam.IamFunctions;
    import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
    import com.pulumi.aws.cloudwatch.LogResourcePolicy;
    import com.pulumi.aws.cloudwatch.LogResourcePolicyArgs;
    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 elasticsearch-log-publishing-policyPolicyDocument = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                .statements(GetPolicyDocumentStatementArgs.builder()
                    .actions(                
                        "logs:CreateLogStream",
                        "logs:PutLogEvents",
                        "logs:PutLogEventsBatch")
                    .resources("arn:aws:logs:*")
                    .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                        .identifiers("es.amazonaws.com")
                        .type("Service")
                        .build())
                    .build())
                .build());
    
            var elasticsearch_log_publishing_policyLogResourcePolicy = new LogResourcePolicy("elasticsearch-log-publishing-policyLogResourcePolicy", LogResourcePolicyArgs.builder()        
                .policyDocument(elasticsearch_log_publishing_policyPolicyDocument.json())
                .policyName("elasticsearch-log-publishing-policy")
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_aws as aws
    
    elasticsearch_log_publishing_policy_policy_document = aws.iam.get_policy_document(statements=[aws.iam.GetPolicyDocumentStatementArgs(
        actions=[
            "logs:CreateLogStream",
            "logs:PutLogEvents",
            "logs:PutLogEventsBatch",
        ],
        resources=["arn:aws:logs:*"],
        principals=[aws.iam.GetPolicyDocumentStatementPrincipalArgs(
            identifiers=["es.amazonaws.com"],
            type="Service",
        )],
    )])
    elasticsearch_log_publishing_policy_log_resource_policy = aws.cloudwatch.LogResourcePolicy("elasticsearch-log-publishing-policyLogResourcePolicy",
        policy_document=elasticsearch_log_publishing_policy_policy_document.json,
        policy_name="elasticsearch-log-publishing-policy")
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const elasticsearch-log-publishing-policyPolicyDocument = aws.iam.getPolicyDocument({
        statements: [{
            actions: [
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "logs:PutLogEventsBatch",
            ],
            resources: ["arn:aws:logs:*"],
            principals: [{
                identifiers: ["es.amazonaws.com"],
                type: "Service",
            }],
        }],
    });
    const elasticsearch_log_publishing_policyLogResourcePolicy = new aws.cloudwatch.LogResourcePolicy("elasticsearch-log-publishing-policyLogResourcePolicy", {
        policyDocument: elasticsearch_log_publishing_policyPolicyDocument.then(elasticsearch_log_publishing_policyPolicyDocument => elasticsearch_log_publishing_policyPolicyDocument.json),
        policyName: "elasticsearch-log-publishing-policy",
    });
    
    resources:
      elasticsearch-log-publishing-policyLogResourcePolicy:
        type: aws:cloudwatch:LogResourcePolicy
        properties:
          policyDocument: ${["elasticsearch-log-publishing-policyPolicyDocument"].json}
          policyName: elasticsearch-log-publishing-policy
    variables:
      elasticsearch-log-publishing-policyPolicyDocument:
        fn::invoke:
          Function: aws:iam:getPolicyDocument
          Arguments:
            statements:
              - actions:
                  - logs:CreateLogStream
                  - logs:PutLogEvents
                  - logs:PutLogEventsBatch
                resources:
                  - arn:aws:logs:*
                principals:
                  - identifiers:
                      - es.amazonaws.com
                    type: Service
    

    Route53 Query Logging

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var route53_query_logging_policyPolicyDocument = Aws.Iam.GetPolicyDocument.Invoke(new()
        {
            Statements = new[]
            {
                new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
                {
                    Actions = new[]
                    {
                        "logs:CreateLogStream",
                        "logs:PutLogEvents",
                    },
                    Resources = new[]
                    {
                        "arn:aws:logs:*:*:log-group:/aws/route53/*",
                    },
                    Principals = new[]
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                        {
                            Identifiers = new[]
                            {
                                "route53.amazonaws.com",
                            },
                            Type = "Service",
                        },
                    },
                },
            },
        });
    
        var route53_query_logging_policyLogResourcePolicy = new Aws.CloudWatch.LogResourcePolicy("route53-query-logging-policyLogResourcePolicy", new()
        {
            PolicyDocument = route53_query_logging_policyPolicyDocument.Apply(route53_query_logging_policyPolicyDocument => route53_query_logging_policyPolicyDocument.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json)),
            PolicyName = "route53-query-logging-policy",
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cloudwatch"
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		route53_query_logging_policyPolicyDocument, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
    			Statements: []iam.GetPolicyDocumentStatement{
    				{
    					Actions: []string{
    						"logs:CreateLogStream",
    						"logs:PutLogEvents",
    					},
    					Resources: []string{
    						"arn:aws:logs:*:*:log-group:/aws/route53/*",
    					},
    					Principals: []iam.GetPolicyDocumentStatementPrincipal{
    						{
    							Identifiers: []string{
    								"route53.amazonaws.com",
    							},
    							Type: "Service",
    						},
    					},
    				},
    			},
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = cloudwatch.NewLogResourcePolicy(ctx, "route53-query-logging-policyLogResourcePolicy", &cloudwatch.LogResourcePolicyArgs{
    			PolicyDocument: *pulumi.String(route53_query_logging_policyPolicyDocument.Json),
    			PolicyName:     pulumi.String("route53-query-logging-policy"),
    		})
    		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.aws.iam.IamFunctions;
    import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
    import com.pulumi.aws.cloudwatch.LogResourcePolicy;
    import com.pulumi.aws.cloudwatch.LogResourcePolicyArgs;
    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 route53-query-logging-policyPolicyDocument = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                .statements(GetPolicyDocumentStatementArgs.builder()
                    .actions(                
                        "logs:CreateLogStream",
                        "logs:PutLogEvents")
                    .resources("arn:aws:logs:*:*:log-group:/aws/route53/*")
                    .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                        .identifiers("route53.amazonaws.com")
                        .type("Service")
                        .build())
                    .build())
                .build());
    
            var route53_query_logging_policyLogResourcePolicy = new LogResourcePolicy("route53-query-logging-policyLogResourcePolicy", LogResourcePolicyArgs.builder()        
                .policyDocument(route53_query_logging_policyPolicyDocument.json())
                .policyName("route53-query-logging-policy")
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_aws as aws
    
    route53_query_logging_policy_policy_document = aws.iam.get_policy_document(statements=[aws.iam.GetPolicyDocumentStatementArgs(
        actions=[
            "logs:CreateLogStream",
            "logs:PutLogEvents",
        ],
        resources=["arn:aws:logs:*:*:log-group:/aws/route53/*"],
        principals=[aws.iam.GetPolicyDocumentStatementPrincipalArgs(
            identifiers=["route53.amazonaws.com"],
            type="Service",
        )],
    )])
    route53_query_logging_policy_log_resource_policy = aws.cloudwatch.LogResourcePolicy("route53-query-logging-policyLogResourcePolicy",
        policy_document=route53_query_logging_policy_policy_document.json,
        policy_name="route53-query-logging-policy")
    
    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const route53-query-logging-policyPolicyDocument = aws.iam.getPolicyDocument({
        statements: [{
            actions: [
                "logs:CreateLogStream",
                "logs:PutLogEvents",
            ],
            resources: ["arn:aws:logs:*:*:log-group:/aws/route53/*"],
            principals: [{
                identifiers: ["route53.amazonaws.com"],
                type: "Service",
            }],
        }],
    });
    const route53_query_logging_policyLogResourcePolicy = new aws.cloudwatch.LogResourcePolicy("route53-query-logging-policyLogResourcePolicy", {
        policyDocument: route53_query_logging_policyPolicyDocument.then(route53_query_logging_policyPolicyDocument => route53_query_logging_policyPolicyDocument.json),
        policyName: "route53-query-logging-policy",
    });
    
    resources:
      route53-query-logging-policyLogResourcePolicy:
        type: aws:cloudwatch:LogResourcePolicy
        properties:
          policyDocument: ${["route53-query-logging-policyPolicyDocument"].json}
          policyName: route53-query-logging-policy
    variables:
      route53-query-logging-policyPolicyDocument:
        fn::invoke:
          Function: aws:iam:getPolicyDocument
          Arguments:
            statements:
              - actions:
                  - logs:CreateLogStream
                  - logs:PutLogEvents
                resources:
                  - arn:aws:logs:*:*:log-group:/aws/route53/*
                principals:
                  - identifiers:
                      - route53.amazonaws.com
                    type: Service
    

    Create LogResourcePolicy Resource

    new LogResourcePolicy(name: string, args: LogResourcePolicyArgs, opts?: CustomResourceOptions);
    @overload
    def LogResourcePolicy(resource_name: str,
                          opts: Optional[ResourceOptions] = None,
                          policy_document: Optional[str] = None,
                          policy_name: Optional[str] = None)
    @overload
    def LogResourcePolicy(resource_name: str,
                          args: LogResourcePolicyArgs,
                          opts: Optional[ResourceOptions] = None)
    func NewLogResourcePolicy(ctx *Context, name string, args LogResourcePolicyArgs, opts ...ResourceOption) (*LogResourcePolicy, error)
    public LogResourcePolicy(string name, LogResourcePolicyArgs args, CustomResourceOptions? opts = null)
    public LogResourcePolicy(String name, LogResourcePolicyArgs args)
    public LogResourcePolicy(String name, LogResourcePolicyArgs args, CustomResourceOptions options)
    
    type: aws:cloudwatch:LogResourcePolicy
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    
    name string
    The unique name of the resource.
    args LogResourcePolicyArgs
    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 LogResourcePolicyArgs
    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 LogResourcePolicyArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args LogResourcePolicyArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args LogResourcePolicyArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    LogResourcePolicy 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 LogResourcePolicy resource accepts the following input properties:

    PolicyDocument string
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    PolicyName string
    Name of the resource policy.
    PolicyDocument string
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    PolicyName string
    Name of the resource policy.
    policyDocument String
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    policyName String
    Name of the resource policy.
    policyDocument string
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    policyName string
    Name of the resource policy.
    policy_document str
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    policy_name str
    Name of the resource policy.
    policyDocument String
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    policyName String
    Name of the resource policy.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the LogResourcePolicy 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 LogResourcePolicy Resource

    Get an existing LogResourcePolicy 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?: LogResourcePolicyState, opts?: CustomResourceOptions): LogResourcePolicy
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            policy_document: Optional[str] = None,
            policy_name: Optional[str] = None) -> LogResourcePolicy
    func GetLogResourcePolicy(ctx *Context, name string, id IDInput, state *LogResourcePolicyState, opts ...ResourceOption) (*LogResourcePolicy, error)
    public static LogResourcePolicy Get(string name, Input<string> id, LogResourcePolicyState? state, CustomResourceOptions? opts = null)
    public static LogResourcePolicy get(String name, Output<String> id, LogResourcePolicyState 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:
    PolicyDocument string
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    PolicyName string
    Name of the resource policy.
    PolicyDocument string
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    PolicyName string
    Name of the resource policy.
    policyDocument String
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    policyName String
    Name of the resource policy.
    policyDocument string
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    policyName string
    Name of the resource policy.
    policy_document str
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    policy_name str
    Name of the resource policy.
    policyDocument String
    Details of the resource policy, including the identity of the principal that is enabled to put logs to this account. This is formatted as a JSON string. Maximum length of 5120 characters.
    policyName String
    Name of the resource policy.

    Import

    Using pulumi import, import CloudWatch log resource policies using the policy name. For example:

     $ pulumi import aws:cloudwatch/logResourcePolicy:LogResourcePolicy MyPolicy MyPolicy
    

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo

    Try AWS Native preview for resources not in the classic version.

    AWS Classic v6.23.0 published on Thursday, Feb 22, 2024 by Pulumi