Welcome to Pulumi Registry, your window into the cloud. Read the announcement.

AWS Classic

v4.30.0 published on Tuesday, Nov 30, 2021 by Pulumi

QueryLog

Provides a Route53 query logging configuration resource.

NOTE: There are restrictions on the configuration of query logging. Notably, the CloudWatch log group must be in the us-east-1 region, a permissive CloudWatch log resource policy must be in place, and the Route53 hosted zone must be public. See Configuring Logging for DNS Queries for additional details.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        // Example CloudWatch log group in us-east-1
        var us_east_1 = new Aws.Provider("us-east-1", new Aws.ProviderArgs
        {
            Region = "us-east-1",
        });
        var awsRoute53ExampleCom = new Aws.CloudWatch.LogGroup("awsRoute53ExampleCom", new Aws.CloudWatch.LogGroupArgs
        {
            RetentionInDays = 30,
        }, new CustomResourceOptions
        {
            Provider = aws.Us_east_1,
        });
        // Example CloudWatch log resource policy to allow Route53 to write logs
        // to any log group under /aws/route53/*
        var route53_query_logging_policyPolicyDocument = Output.Create(Aws.Iam.GetPolicyDocument.InvokeAsync(new Aws.Iam.GetPolicyDocumentArgs
        {
            Statements = 
            {
                new Aws.Iam.Inputs.GetPolicyDocumentStatementArgs
                {
                    Actions = 
                    {
                        "logs:CreateLogStream",
                        "logs:PutLogEvents",
                    },
                    Resources = 
                    {
                        "arn:aws:logs:*:*:log-group:/aws/route53/*",
                    },
                    Principals = 
                    {
                        new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalArgs
                        {
                            Identifiers = 
                            {
                                "route53.amazonaws.com",
                            },
                            Type = "Service",
                        },
                    },
                },
            },
        }));
        var route53_query_logging_policyLogResourcePolicy = new Aws.CloudWatch.LogResourcePolicy("route53-query-logging-policyLogResourcePolicy", new Aws.CloudWatch.LogResourcePolicyArgs
        {
            PolicyDocument = route53_query_logging_policyPolicyDocument.Apply(route53_query_logging_policyPolicyDocument => route53_query_logging_policyPolicyDocument.Json),
            PolicyName = "route53-query-logging-policy",
        }, new CustomResourceOptions
        {
            Provider = aws.Us_east_1,
        });
        // Example Route53 zone with query logging
        var exampleComZone = new Aws.Route53.Zone("exampleComZone", new Aws.Route53.ZoneArgs
        {
        });
        var exampleComQueryLog = new Aws.Route53.QueryLog("exampleComQueryLog", new Aws.Route53.QueryLogArgs
        {
            CloudwatchLogGroupArn = awsRoute53ExampleCom.Arn,
            ZoneId = exampleComZone.ZoneId,
        }, new CustomResourceOptions
        {
            DependsOn = 
            {
                route53_query_logging_policyLogResourcePolicy,
            },
        });
    }

}
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/cloudwatch"
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/iam"
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/providers"
	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/route53"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := providers.Newaws(ctx, "us_east_1", &providers.awsArgs{
			Region: "us-east-1",
		})
		if err != nil {
			return err
		}
		awsRoute53ExampleCom, err := cloudwatch.NewLogGroup(ctx, "awsRoute53ExampleCom", &cloudwatch.LogGroupArgs{
			RetentionInDays: pulumi.Int(30),
		}, pulumi.Provider(aws.Us-east-1))
		if err != nil {
			return err
		}
		route53_query_logging_policyPolicyDocument, err := iam.GetPolicyDocument(ctx, &iam.GetPolicyDocumentArgs{
			Statements: []iam.GetPolicyDocumentStatement{
				iam.GetPolicyDocumentStatement{
					Actions: []string{
						"logs:CreateLogStream",
						"logs:PutLogEvents",
					},
					Resources: []string{
						"arn:aws:logs:*:*:log-group:/aws/route53/*",
					},
					Principals: []iam.GetPolicyDocumentStatementPrincipal{
						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"),
		}, pulumi.Provider(aws.Us-east-1))
		if err != nil {
			return err
		}
		exampleComZone, err := route53.NewZone(ctx, "exampleComZone", nil)
		if err != nil {
			return err
		}
		_, err = route53.NewQueryLog(ctx, "exampleComQueryLog", &route53.QueryLogArgs{
			CloudwatchLogGroupArn: awsRoute53ExampleCom.Arn,
			ZoneId:                exampleComZone.ZoneId,
		}, pulumi.DependsOn([]pulumi.Resource{
			route53_query_logging_policyLogResourcePolicy,
		}))
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws
import pulumi_pulumi as pulumi

# Example CloudWatch log group in us-east-1
us_east_1 = pulumi.providers.Aws("us-east-1", region="us-east-1")
aws_route53_example_com = aws.cloudwatch.LogGroup("awsRoute53ExampleCom", retention_in_days=30,
opts=pulumi.ResourceOptions(provider=aws["us-east-1"]))
# Example CloudWatch log resource policy to allow Route53 to write logs
# to any log group under /aws/route53/*
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",
    opts=pulumi.ResourceOptions(provider=aws["us-east-1"]))
# Example Route53 zone with query logging
example_com_zone = aws.route53.Zone("exampleComZone")
example_com_query_log = aws.route53.QueryLog("exampleComQueryLog",
    cloudwatch_log_group_arn=aws_route53_example_com.arn,
    zone_id=example_com_zone.zone_id,
    opts=pulumi.ResourceOptions(depends_on=[route53_query_logging_policy_log_resource_policy]))
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Example CloudWatch log group in us-east-1
const us_east_1 = new aws.Provider("us-east-1", {region: "us-east-1"});
const awsRoute53ExampleCom = new aws.cloudwatch.LogGroup("awsRoute53ExampleCom", {retentionInDays: 30}, {
    provider: aws["us-east-1"],
});
// Example CloudWatch log resource policy to allow Route53 to write logs
// to any log group under /aws/route53/*
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",
}, {
    provider: aws["us-east-1"],
});
// Example Route53 zone with query logging
const exampleComZone = new aws.route53.Zone("exampleComZone", {});
const exampleComQueryLog = new aws.route53.QueryLog("exampleComQueryLog", {
    cloudwatchLogGroupArn: awsRoute53ExampleCom.arn,
    zoneId: exampleComZone.zoneId,
}, {
    dependsOn: [route53_query_logging_policyLogResourcePolicy],
});

Create a QueryLog Resource

new QueryLog(name: string, args: QueryLogArgs, opts?: CustomResourceOptions);
@overload
def QueryLog(resource_name: str,
             opts: Optional[ResourceOptions] = None,
             cloudwatch_log_group_arn: Optional[str] = None,
             zone_id: Optional[str] = None)
@overload
def QueryLog(resource_name: str,
             args: QueryLogArgs,
             opts: Optional[ResourceOptions] = None)
func NewQueryLog(ctx *Context, name string, args QueryLogArgs, opts ...ResourceOption) (*QueryLog, error)
public QueryLog(string name, QueryLogArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args QueryLogArgs
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 QueryLogArgs
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 QueryLogArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args QueryLogArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

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

CloudwatchLogGroupArn string
CloudWatch log group ARN to send query logs.
ZoneId string
Route53 hosted zone ID to enable query logs.
CloudwatchLogGroupArn string
CloudWatch log group ARN to send query logs.
ZoneId string
Route53 hosted zone ID to enable query logs.
cloudwatchLogGroupArn string
CloudWatch log group ARN to send query logs.
zoneId string
Route53 hosted zone ID to enable query logs.
cloudwatch_log_group_arn str
CloudWatch log group ARN to send query logs.
zone_id str
Route53 hosted zone ID to enable query logs.

Outputs

All input properties are implicitly available as output properties. Additionally, the QueryLog resource produces the following output properties:

Arn string
The Amazon Resource Name (ARN) of the Query Logging Config.
Id string
The provider-assigned unique ID for this managed resource.
Arn string
The Amazon Resource Name (ARN) of the Query Logging Config.
Id string
The provider-assigned unique ID for this managed resource.
arn string
The Amazon Resource Name (ARN) of the Query Logging Config.
id string
The provider-assigned unique ID for this managed resource.
arn str
The Amazon Resource Name (ARN) of the Query Logging Config.
id str
The provider-assigned unique ID for this managed resource.

Look up an Existing QueryLog Resource

Get an existing QueryLog 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?: QueryLogState, opts?: CustomResourceOptions): QueryLog
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        arn: Optional[str] = None,
        cloudwatch_log_group_arn: Optional[str] = None,
        zone_id: Optional[str] = None) -> QueryLog
func GetQueryLog(ctx *Context, name string, id IDInput, state *QueryLogState, opts ...ResourceOption) (*QueryLog, error)
public static QueryLog Get(string name, Input<string> id, QueryLogState? state, CustomResourceOptions? opts = null)
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.

The following state arguments are supported:

Arn string
The Amazon Resource Name (ARN) of the Query Logging Config.
CloudwatchLogGroupArn string
CloudWatch log group ARN to send query logs.
ZoneId string
Route53 hosted zone ID to enable query logs.
Arn string
The Amazon Resource Name (ARN) of the Query Logging Config.
CloudwatchLogGroupArn string
CloudWatch log group ARN to send query logs.
ZoneId string
Route53 hosted zone ID to enable query logs.
arn string
The Amazon Resource Name (ARN) of the Query Logging Config.
cloudwatchLogGroupArn string
CloudWatch log group ARN to send query logs.
zoneId string
Route53 hosted zone ID to enable query logs.
arn str
The Amazon Resource Name (ARN) of the Query Logging Config.
cloudwatch_log_group_arn str
CloudWatch log group ARN to send query logs.
zone_id str
Route53 hosted zone ID to enable query logs.

Import

Route53 query logging configurations can be imported using their ID, e.g.,

 $ pulumi import aws:route53/queryLog:QueryLog example_com xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.