LogSubscription class

Provides a Log subscription for AWS Directory Service that pushes logs to cloudwatch.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const example = new aws.cloudwatch.LogGroup("example", {
    name: `/aws/directoryservice/${exampleAwsDirectoryServiceDirectory.id}`,
    retentionInDays: 14,
});
const ad_log_policy = aws.iam.getPolicyDocumentOutput({
    statements: [{
        principals: [{
            identifiers: ["ds.amazonaws.com"],
            type: "Service",
        }],
        actions: [
            "logs:CreateLogStream",
            "logs:PutLogEvents",
        ],
        resources: [pulumi.interpolate`${example.arn}:*`],
        effect: "Allow",
    }],
});
const ad_log_policyLogResourcePolicy = new aws.cloudwatch.LogResourcePolicy("ad-log-policy", {
    policyDocument: ad_log_policy.json,
    policyName: "ad-log-policy",
});
const exampleLogSubscription = new aws.directoryservice.LogSubscription("example", {
    directoryId: exampleAwsDirectoryServiceDirectory.id,
    logGroupName: example.name,
});
import pulumi
import pulumi_aws as aws

example = aws.cloudwatch.LogGroup("example",
    name=f"/aws/directoryservice/{example_aws_directory_service_directory['id']}",
    retention_in_days=14)
ad_log_policy = aws.iam.get_policy_document_output(statements=[{
    "principals": [{
        "identifiers": ["ds.amazonaws.com"],
        "type": "Service",
    }],
    "actions": [
        "logs:CreateLogStream",
        "logs:PutLogEvents",
    ],
    "resources": [example.arn.apply(lambda arn: f"{arn}:*")],
    "effect": "Allow",
}])
ad_log_policy_log_resource_policy = aws.cloudwatch.LogResourcePolicy("ad-log-policy",
    policy_document=ad_log_policy.json,
    policy_name="ad-log-policy")
example_log_subscription = aws.directoryservice.LogSubscription("example",
    directory_id=example_aws_directory_service_directory["id"],
    log_group_name=example.name)
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() =>
{
    var example = new Aws.CloudWatch.LogGroup("example", new()
    {
        Name = $"/aws/directoryservice/{exampleAwsDirectoryServiceDirectory.Id}",
        RetentionInDays = 14,
    });

    var ad_log_policy = Aws.Iam.GetPolicyDocument.Invoke(new()
    {
        Statements = new[]
        {
            new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
            {
                Principals = new[]
                {
                    new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
                    {
                        Identifiers = new[]
                        {
                            "ds.amazonaws.com",
                        },
                        Type = "Service",
                    },
                },
                Actions = new[]
                {
                    "logs:CreateLogStream",
                    "logs:PutLogEvents",
                },
                Resources = new[]
                {
                    $"{example.Arn}:*",
                },
                Effect = "Allow",
            },
        },
    });

    var ad_log_policyLogResourcePolicy = new Aws.CloudWatch.LogResourcePolicy("ad-log-policy", new()
    {
        PolicyDocument = ad_log_policy.Apply(ad_log_policy => ad_log_policy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json)),
        PolicyName = "ad-log-policy",
    });

    var exampleLogSubscription = new Aws.DirectoryService.LogSubscription("example", new()
    {
        DirectoryId = exampleAwsDirectoryServiceDirectory.Id,
        LogGroupName = example.Name,
    });

});
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/cloudwatch"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/directoryservice"
	"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/iam"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		example, err := cloudwatch.NewLogGroup(ctx, "example", &cloudwatch.LogGroupArgs{
			Name:            pulumi.Sprintf("/aws/directoryservice/%v", exampleAwsDirectoryServiceDirectory.Id),
			RetentionInDays: pulumi.Int(14),
		})
		if err != nil {
			return err
		}
		ad_log_policy := iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
			Statements: iam.GetPolicyDocumentStatementArray{
				&iam.GetPolicyDocumentStatementArgs{
					Principals: iam.GetPolicyDocumentStatementPrincipalArray{
						&iam.GetPolicyDocumentStatementPrincipalArgs{
							Identifiers: pulumi.StringArray{
								pulumi.String("ds.amazonaws.com"),
							},
							Type: pulumi.String("Service"),
						},
					},
					Actions: pulumi.StringArray{
						pulumi.String("logs:CreateLogStream"),
						pulumi.String("logs:PutLogEvents"),
					},
					Resources: pulumi.StringArray{
						example.Arn.ApplyT(func(arn string) (string, error) {
							return fmt.Sprintf("%v:*", arn), nil
						}).(pulumi.StringOutput),
					},
					Effect: pulumi.String("Allow"),
				},
			},
		}, nil)
		_, err = cloudwatch.NewLogResourcePolicy(ctx, "ad-log-policy", &cloudwatch.LogResourcePolicyArgs{
			PolicyDocument: ad_log_policy.Json(),
			PolicyName:     pulumi.String("ad-log-policy"),
		})
		if err != nil {
			return err
		}
		_, err = directoryservice.NewLogSubscription(ctx, "example", &directoryservice.LogSubscriptionArgs{
			DirectoryId:  pulumi.Any(exampleAwsDirectoryServiceDirectory.Id),
			LogGroupName: example.Name,
		})
		if err != nil {
			return err
		}
		return nil
	})
}
pulumi {
  required_providers {
    aws = {
      source = "pulumi/aws"
    }
  }
}

data "aws_iam_getpolicydocument" "ad-log-policy" {
  statements {
    principals {
      identifiers = ["ds.amazonaws.com"]
      type        = "Service"
    }
    actions   = ["logs:CreateLogStream", "logs:PutLogEvents"]
    resources = ["${aws_cloudwatch_loggroup.example.arn}:*"]
    effect    = "Allow"
  }
}

resource "aws_cloudwatch_loggroup" "example" {
  name              ="/aws/directoryservice/${exampleAwsDirectoryServiceDirectory.id}"
  retention_in_days = 14
}
resource "aws_cloudwatch_logresourcepolicy" "ad-log-policy" {
  policy_document = data.aws_iam_getpolicydocument.ad-log-policy.json
  policy_name     = "ad-log-policy"
}
resource "aws_directoryservice_logsubscription" "example" {
  directory_id   = exampleAwsDirectoryServiceDirectory.id
  log_group_name = aws_cloudwatch_loggroup.example.name
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.cloudwatch.LogGroup;
import com.pulumi.aws.cloudwatch.LogGroupArgs;
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.GetPolicyDocumentStatementPrincipalArgs;
import com.pulumi.aws.cloudwatch.LogResourcePolicy;
import com.pulumi.aws.cloudwatch.LogResourcePolicyArgs;
import com.pulumi.aws.directoryservice.LogSubscription;
import com.pulumi.aws.directoryservice.LogSubscriptionArgs;
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 LogGroup("example", LogGroupArgs.builder()
            .name(String.format("/aws/directoryservice/%s", exampleAwsDirectoryServiceDirectory.id()))
            .retentionInDays(14)
            .build());

        final var ad-log-policy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
            .statements(GetPolicyDocumentStatementArgs.builder()
                .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                    .identifiers("ds.amazonaws.com")
                    .type("Service")
                    .build())
                .actions(
                    "logs:CreateLogStream",
                    "logs:PutLogEvents")
                .resources(example.arn().applyValue(_arn -> String.format("%s:*", _arn)))
                .effect("Allow")
                .build())
            .build());

        var ad_log_policyLogResourcePolicy = new LogResourcePolicy("ad-log-policyLogResourcePolicy", LogResourcePolicyArgs.builder()
            .policyDocument(ad_log_policy.applyValue(_ad_log_policy -> _ad_log_policy.json()))
            .policyName("ad-log-policy")
            .build());

        var exampleLogSubscription = new LogSubscription("exampleLogSubscription", LogSubscriptionArgs.builder()
            .directoryId(exampleAwsDirectoryServiceDirectory.id())
            .logGroupName(example.name())
            .build());

    }
}
resources:
  example:
    type: aws:cloudwatch:LogGroup
    properties:
      name: /aws/directoryservice/${exampleAwsDirectoryServiceDirectory.id}
      retentionInDays: 14
  ad-log-policyLogResourcePolicy:
    type: aws:cloudwatch:LogResourcePolicy
    name: ad-log-policy
    properties:
      policyDocument: ${["ad-log-policy"].json}
      policyName: ad-log-policy
  exampleLogSubscription:
    type: aws:directoryservice:LogSubscription
    name: example
    properties:
      directoryId: ${exampleAwsDirectoryServiceDirectory.id}
      logGroupName: ${example.name}
variables:
  ad-log-policy:
    fn::invoke:
      function: aws:iam:getPolicyDocument
      arguments:
        statements:
          - principals:
              - identifiers:
                  - ds.amazonaws.com
                type: Service
            actions:
              - logs:CreateLogStream
              - logs:PutLogEvents
            resources:
              - ${example.arn}:*
            effect: Allow

Import

Using pulumi import, import Directory Service Log Subscriptions using the directory id. For example:

$ pulumi import aws:directoryservice/logSubscription:LogSubscription msad d-1234567890

Constructors

LogSubscription(String name, {LogSubscriptionArgs? args, CustomResourceOptions? options})
Creates a new LogSubscription. name The Pulumi resource name. args Arguments used to configure this LogSubscription. The set of arguments for LogSubscription. options Resource options controlling this resource's behavior.
LogSubscription.reference(String urn)
Creates a typed reference to an existing LogSubscription resource.

Properties

childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
directoryId ↔ Output<String>
ID of directory.
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
logGroupName ↔ Output<String>
Name of the cloudwatch log group to which the logs should be published. The log group should be already created and the directory service principal should be provided with required permission to create stream and publish logs. Changing this value would delete the current subscription and create a new one. A directory can only have one log subscription at a time.
latefinal
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, {LogSubscriptionState? state, CustomResourceOptions? options}) → LogSubscription
Gets an existing LogSubscription resource's state with the given name and id.