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.42.0 published on Wednesday, Jun 26, 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.42.0 published on Wednesday, Jun 26, 2024 by Pulumi

    Provides a resource to manage a CloudWatch log resource policy.

    Example Usage

    Elasticsearch Log Publishing

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const elasticsearch-log-publishing-policy = 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-policy", {
        policyDocument: elasticsearch_log_publishing_policy.then(elasticsearch_log_publishing_policy => elasticsearch_log_publishing_policy.json),
        policyName: "elasticsearch-log-publishing-policy",
    });
    
    import pulumi
    import pulumi_aws as aws
    
    elasticsearch_log_publishing_policy = aws.iam.get_policy_document(statements=[{
        "actions": [
            "logs:CreateLogStream",
            "logs:PutLogEvents",
            "logs:PutLogEventsBatch",
        ],
        "resources": ["arn:aws:logs:*"],
        "principals": [{
            "identifiers": ["es.amazonaws.com"],
            "type": "Service",
        }],
    }])
    elasticsearch_log_publishing_policy_log_resource_policy = aws.cloudwatch.LogResourcePolicy("elasticsearch-log-publishing-policy",
        policy_document=elasticsearch_log_publishing_policy.json,
        policy_name="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_policy, 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-policy", &cloudwatch.LogResourcePolicyArgs{
    			PolicyDocument: pulumi.String(elasticsearch_log_publishing_policy.Json),
    			PolicyName:     pulumi.String("elasticsearch-log-publishing-policy"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var elasticsearch_log_publishing_policy = 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-policy", new()
        {
            PolicyDocument = elasticsearch_log_publishing_policy.Apply(elasticsearch_log_publishing_policy => elasticsearch_log_publishing_policy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json)),
            PolicyName = "elasticsearch-log-publishing-policy",
        });
    
    });
    
    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-policy = 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_policy.json())
                .policyName("elasticsearch-log-publishing-policy")
                .build());
    
        }
    }
    
    resources:
      elasticsearch-log-publishing-policyLogResourcePolicy:
        type: aws:cloudwatch:LogResourcePolicy
        name: elasticsearch-log-publishing-policy
        properties:
          policyDocument: ${["elasticsearch-log-publishing-policy"].json}
          policyName: elasticsearch-log-publishing-policy
    variables:
      elasticsearch-log-publishing-policy:
        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

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const route53-query-logging-policy = 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-policy", {
        policyDocument: route53_query_logging_policy.then(route53_query_logging_policy => route53_query_logging_policy.json),
        policyName: "route53-query-logging-policy",
    });
    
    import pulumi
    import pulumi_aws as aws
    
    route53_query_logging_policy = aws.iam.get_policy_document(statements=[{
        "actions": [
            "logs:CreateLogStream",
            "logs:PutLogEvents",
        ],
        "resources": ["arn:aws:logs:*:*:log-group:/aws/route53/*"],
        "principals": [{
            "identifiers": ["route53.amazonaws.com"],
            "type": "Service",
        }],
    }])
    route53_query_logging_policy_log_resource_policy = aws.cloudwatch.LogResourcePolicy("route53-query-logging-policy",
        policy_document=route53_query_logging_policy.json,
        policy_name="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_policy, 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-policy", &cloudwatch.LogResourcePolicyArgs{
    			PolicyDocument: pulumi.String(route53_query_logging_policy.Json),
    			PolicyName:     pulumi.String("route53-query-logging-policy"),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Aws = Pulumi.Aws;
    
    return await Deployment.RunAsync(() => 
    {
        var route53_query_logging_policy = 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-policy", new()
        {
            PolicyDocument = route53_query_logging_policy.Apply(route53_query_logging_policy => route53_query_logging_policy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json)),
            PolicyName = "route53-query-logging-policy",
        });
    
    });
    
    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-policy = 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_policy.json())
                .policyName("route53-query-logging-policy")
                .build());
    
        }
    }
    
    resources:
      route53-query-logging-policyLogResourcePolicy:
        type: aws:cloudwatch:LogResourcePolicy
        name: route53-query-logging-policy
        properties:
          policyDocument: ${["route53-query-logging-policy"].json}
          policyName: route53-query-logging-policy
    variables:
      route53-query-logging-policy:
        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

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new LogResourcePolicy(name: string, args: LogResourcePolicyArgs, opts?: CustomResourceOptions);
    @overload
    def LogResourcePolicy(resource_name: str,
                          args: LogResourcePolicyArgs,
                          opts: Optional[ResourceOptions] = None)
    
    @overload
    def LogResourcePolicy(resource_name: str,
                          opts: Optional[ResourceOptions] = None,
                          policy_document: Optional[str] = None,
                          policy_name: Optional[str] = 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.
    
    

    Parameters

    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.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var logResourcePolicyResource = new Aws.CloudWatch.LogResourcePolicy("logResourcePolicyResource", new()
    {
        PolicyDocument = "string",
        PolicyName = "string",
    });
    
    example, err := cloudwatch.NewLogResourcePolicy(ctx, "logResourcePolicyResource", &cloudwatch.LogResourcePolicyArgs{
    	PolicyDocument: pulumi.Any("string"),
    	PolicyName:     pulumi.String("string"),
    })
    
    var logResourcePolicyResource = new LogResourcePolicy("logResourcePolicyResource", LogResourcePolicyArgs.builder()
        .policyDocument("string")
        .policyName("string")
        .build());
    
    log_resource_policy_resource = aws.cloudwatch.LogResourcePolicy("logResourcePolicyResource",
        policy_document="string",
        policy_name="string")
    
    const logResourcePolicyResource = new aws.cloudwatch.LogResourcePolicy("logResourcePolicyResource", {
        policyDocument: "string",
        policyName: "string",
    });
    
    type: aws:cloudwatch:LogResourcePolicy
    properties:
        policyDocument: string
        policyName: string
    

    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 | 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 | 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 | 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 | PolicyDocument
    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 | 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 | 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 | 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 | 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 | PolicyDocument
    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 | 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
    

    To learn more about importing existing cloud resources, see Importing resources.

    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.42.0 published on Wednesday, Jun 26, 2024 by Pulumi