Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.pulumi.aws.cloudwatch.kotlin.EventRule.kt Maven / Gradle / Ivy
@file:Suppress("NAME_SHADOWING", "DEPRECATION")
package com.pulumi.aws.cloudwatch.kotlin
import com.pulumi.core.Output
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.Deprecated
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.Map
/**
* Builder for [EventRule].
*/
@PulumiTagMarker
public class EventRuleResourceBuilder internal constructor() {
public var name: String? = null
public var args: EventRuleArgs = EventRuleArgs()
public var opts: CustomResourceOptions = CustomResourceOptions()
/**
* @param name The _unique_ name of the resulting resource.
*/
public fun name(`value`: String) {
this.name = value
}
/**
* @param block The arguments to use to populate this resource's properties.
*/
public suspend fun args(block: suspend EventRuleArgsBuilder.() -> Unit) {
val builder = EventRuleArgsBuilder()
block(builder)
this.args = builder.build()
}
/**
* @param block A bag of options that control this resource's behavior.
*/
public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
}
internal fun build(): EventRule {
val builtJavaResource = com.pulumi.aws.cloudwatch.EventRule(
this.name,
this.args.toJava(),
this.opts.toJava(),
)
return EventRule(builtJavaResource)
}
}
/**
* Provides an EventBridge Rule resource.
* > **Note:** EventBridge was formerly known as CloudWatch Events. The functionality is identical.
* ## Example Usage
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
* const console = new aws.cloudwatch.EventRule("console", {
* name: "capture-aws-sign-in",
* description: "Capture each AWS Console Sign In",
* eventPattern: JSON.stringify({
* "detail-type": ["AWS Console Sign In via CloudTrail"],
* }),
* });
* const awsLogins = new aws.sns.Topic("aws_logins", {name: "aws-console-logins"});
* const sns = new aws.cloudwatch.EventTarget("sns", {
* rule: console.name,
* targetId: "SendToSNS",
* arn: awsLogins.arn,
* });
* const snsTopicPolicy = awsLogins.arn.apply(arn => aws.iam.getPolicyDocumentOutput({
* statements: [{
* effect: "Allow",
* actions: ["SNS:Publish"],
* principals: [{
* type: "Service",
* identifiers: ["events.amazonaws.com"],
* }],
* resources: [arn],
* }],
* }));
* const _default = new aws.sns.TopicPolicy("default", {
* arn: awsLogins.arn,
* policy: snsTopicPolicy.apply(snsTopicPolicy => snsTopicPolicy.json),
* });
* ```
* ```python
* import pulumi
* import json
* import pulumi_aws as aws
* console = aws.cloudwatch.EventRule("console",
* name="capture-aws-sign-in",
* description="Capture each AWS Console Sign In",
* event_pattern=json.dumps({
* "detail-type": ["AWS Console Sign In via CloudTrail"],
* }))
* aws_logins = aws.sns.Topic("aws_logins", name="aws-console-logins")
* sns = aws.cloudwatch.EventTarget("sns",
* rule=console.name,
* target_id="SendToSNS",
* arn=aws_logins.arn)
* sns_topic_policy = aws_logins.arn.apply(lambda arn: aws.iam.get_policy_document_output(statements=[{
* "effect": "Allow",
* "actions": ["SNS:Publish"],
* "principals": [{
* "type": "Service",
* "identifiers": ["events.amazonaws.com"],
* }],
* "resources": [arn],
* }]))
* default = aws.sns.TopicPolicy("default",
* arn=aws_logins.arn,
* policy=sns_topic_policy.json)
* ```
* ```csharp
* using System.Collections.Generic;
* using System.Linq;
* using System.Text.Json;
* using Pulumi;
* using Aws = Pulumi.Aws;
* return await Deployment.RunAsync(() =>
* {
* var console = new Aws.CloudWatch.EventRule("console", new()
* {
* Name = "capture-aws-sign-in",
* Description = "Capture each AWS Console Sign In",
* EventPattern = JsonSerializer.Serialize(new Dictionary
* {
* ["detail-type"] = new[]
* {
* "AWS Console Sign In via CloudTrail",
* },
* }),
* });
* var awsLogins = new Aws.Sns.Topic("aws_logins", new()
* {
* Name = "aws-console-logins",
* });
* var sns = new Aws.CloudWatch.EventTarget("sns", new()
* {
* Rule = console.Name,
* TargetId = "SendToSNS",
* Arn = awsLogins.Arn,
* });
* var snsTopicPolicy = Aws.Iam.GetPolicyDocument.Invoke(new()
* {
* Statements = new[]
* {
* new Aws.Iam.Inputs.GetPolicyDocumentStatementInputArgs
* {
* Effect = "Allow",
* Actions = new[]
* {
* "SNS:Publish",
* },
* Principals = new[]
* {
* new Aws.Iam.Inputs.GetPolicyDocumentStatementPrincipalInputArgs
* {
* Type = "Service",
* Identifiers = new[]
* {
* "events.amazonaws.com",
* },
* },
* },
* Resources = new[]
* {
* awsLogins.Arn,
* },
* },
* },
* });
* var @default = new Aws.Sns.TopicPolicy("default", new()
* {
* Arn = awsLogins.Arn,
* Policy = snsTopicPolicy.Apply(getPolicyDocumentResult => getPolicyDocumentResult.Json),
* });
* });
* ```
* ```go
* package main
* import (
* "encoding/json"
* "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/cloudwatch"
* "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/iam"
* "github.com/pulumi/pulumi-aws/sdk/v6/go/aws/sns"
* "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
* )
* func main() {
* pulumi.Run(func(ctx *pulumi.Context) error {
* tmpJSON0, err := json.Marshal(map[string]interface{}{
* "detail-type": []string{
* "AWS Console Sign In via CloudTrail",
* },
* })
* if err != nil {
* return err
* }
* json0 := string(tmpJSON0)
* console, err := cloudwatch.NewEventRule(ctx, "console", &cloudwatch.EventRuleArgs{
* Name: pulumi.String("capture-aws-sign-in"),
* Description: pulumi.String("Capture each AWS Console Sign In"),
* EventPattern: pulumi.String(json0),
* })
* if err != nil {
* return err
* }
* awsLogins, err := sns.NewTopic(ctx, "aws_logins", &sns.TopicArgs{
* Name: pulumi.String("aws-console-logins"),
* })
* if err != nil {
* return err
* }
* _, err = cloudwatch.NewEventTarget(ctx, "sns", &cloudwatch.EventTargetArgs{
* Rule: console.Name,
* TargetId: pulumi.String("SendToSNS"),
* Arn: awsLogins.Arn,
* })
* if err != nil {
* return err
* }
* snsTopicPolicy := awsLogins.Arn.ApplyT(func(arn string) (iam.GetPolicyDocumentResult, error) {
* return iam.GetPolicyDocumentResult(interface{}(iam.GetPolicyDocumentOutput(ctx, iam.GetPolicyDocumentOutputArgs{
* Statements: []iam.GetPolicyDocumentStatement{
* {
* Effect: "Allow",
* Actions: []string{
* "SNS:Publish",
* },
* Principals: []iam.GetPolicyDocumentStatementPrincipal{
* {
* Type: "Service",
* Identifiers: []string{
* "events.amazonaws.com",
* },
* },
* },
* Resources: interface{}{
* arn,
* },
* },
* },
* }, nil))), nil
* }).(iam.GetPolicyDocumentResultOutput)
* _, err = sns.NewTopicPolicy(ctx, "default", &sns.TopicPolicyArgs{
* Arn: awsLogins.Arn,
* Policy: pulumi.String(snsTopicPolicy.ApplyT(func(snsTopicPolicy iam.GetPolicyDocumentResult) (*string, error) {
* return &snsTopicPolicy.Json, nil
* }).(pulumi.StringPtrOutput)),
* })
* if err != nil {
* return err
* }
* return nil
* })
* }
* ```
* ```java
* package generated_program;
* import com.pulumi.Context;
* import com.pulumi.Pulumi;
* import com.pulumi.core.Output;
* import com.pulumi.aws.cloudwatch.EventRule;
* import com.pulumi.aws.cloudwatch.EventRuleArgs;
* import com.pulumi.aws.sns.Topic;
* import com.pulumi.aws.sns.TopicArgs;
* import com.pulumi.aws.cloudwatch.EventTarget;
* import com.pulumi.aws.cloudwatch.EventTargetArgs;
* import com.pulumi.aws.iam.IamFunctions;
* import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
* import com.pulumi.aws.sns.TopicPolicy;
* import com.pulumi.aws.sns.TopicPolicyArgs;
* import static com.pulumi.codegen.internal.Serialization.*;
* 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) {
* var console = new EventRule("console", EventRuleArgs.builder()
* .name("capture-aws-sign-in")
* .description("Capture each AWS Console Sign In")
* .eventPattern(serializeJson(
* jsonObject(
* jsonProperty("detail-type", jsonArray("AWS Console Sign In via CloudTrail"))
* )))
* .build());
* var awsLogins = new Topic("awsLogins", TopicArgs.builder()
* .name("aws-console-logins")
* .build());
* var sns = new EventTarget("sns", EventTargetArgs.builder()
* .rule(console.name())
* .targetId("SendToSNS")
* .arn(awsLogins.arn())
* .build());
* final var snsTopicPolicy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
* .statements(GetPolicyDocumentStatementArgs.builder()
* .effect("Allow")
* .actions("SNS:Publish")
* .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
* .type("Service")
* .identifiers("events.amazonaws.com")
* .build())
* .resources(awsLogins.arn())
* .build())
* .build());
* var default_ = new TopicPolicy("default", TopicPolicyArgs.builder()
* .arn(awsLogins.arn())
* .policy(snsTopicPolicy.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult).applyValue(snsTopicPolicy -> snsTopicPolicy.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json())))
* .build());
* }
* }
* ```
* ```yaml
* resources:
* console:
* type: aws:cloudwatch:EventRule
* properties:
* name: capture-aws-sign-in
* description: Capture each AWS Console Sign In
* eventPattern:
* fn::toJSON:
* detail-type:
* - AWS Console Sign In via CloudTrail
* sns:
* type: aws:cloudwatch:EventTarget
* properties:
* rule: ${console.name}
* targetId: SendToSNS
* arn: ${awsLogins.arn}
* awsLogins:
* type: aws:sns:Topic
* name: aws_logins
* properties:
* name: aws-console-logins
* default:
* type: aws:sns:TopicPolicy
* properties:
* arn: ${awsLogins.arn}
* policy: ${snsTopicPolicy.json}
* variables:
* snsTopicPolicy:
* fn::invoke:
* Function: aws:iam:getPolicyDocument
* Arguments:
* statements:
* - effect: Allow
* actions:
* - SNS:Publish
* principals:
* - type: Service
* identifiers:
* - events.amazonaws.com
* resources:
* - ${awsLogins.arn}
* ```
*
* ## Import
* Using `pulumi import`, import EventBridge Rules using the `event_bus_name/rule_name` (if you omit `event_bus_name`, the `default` event bus will be used). For example:
* ```sh
* $ pulumi import aws:cloudwatch/eventRule:EventRule console example-event-bus/capture-console-sign-in
* ```
*/
public class EventRule internal constructor(
override val javaResource: com.pulumi.aws.cloudwatch.EventRule,
) : KotlinCustomResource(javaResource, EventRuleMapper) {
/**
* The Amazon Resource Name (ARN) of the rule.
*/
public val arn: Output
get() = javaResource.arn().applyValue({ args0 -> args0 })
/**
* The description of the rule.
*/
public val description: Output?
get() = javaResource.description().applyValue({ args0 ->
args0.map({ args0 ->
args0
}).orElse(null)
})
/**
* The name or ARN of the event bus to associate with this rule.
* If you omit this, the `default` event bus is used.
*/
public val eventBusName: Output?
get() = javaResource.eventBusName().applyValue({ args0 ->
args0.map({ args0 ->
args0
}).orElse(null)
})
/**
* The event pattern described a JSON object. At least one of `schedule_expression` or `event_pattern` is required. See full documentation of [Events and Event Patterns in EventBridge](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html) for details. **Note**: The event pattern size is 2048 by default but it is adjustable up to 4096 characters by submitting a service quota increase request. See [Amazon EventBridge quotas](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-quota.html) for details.
*/
public val eventPattern: Output?
get() = javaResource.eventPattern().applyValue({ args0 ->
args0.map({ args0 ->
args0
}).orElse(null)
})
/**
* Used to delete managed rules created by AWS. Defaults to `false`.
*/
public val forceDestroy: Output?
get() = javaResource.forceDestroy().applyValue({ args0 ->
args0.map({ args0 ->
args0
}).orElse(null)
})
/**
* Whether the rule should be enabled.
* Defaults to `true`.
* Conflicts with `state`.
*/
@Deprecated(
message = """
Use "state" instead
""",
)
public val isEnabled: Output?
get() = javaResource.isEnabled().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })
/**
* The name of the rule. If omitted, this provider will assign a random, unique name. Conflicts with `name_prefix`.
*/
public val name: Output
get() = javaResource.name().applyValue({ args0 -> args0 })
/**
* Creates a unique name beginning with the specified prefix. Conflicts with `name`. **Note**: Due to the length of the generated suffix, must be 38 characters or less.
*/
public val namePrefix: Output
get() = javaResource.namePrefix().applyValue({ args0 -> args0 })
/**
* The Amazon Resource Name (ARN) associated with the role that is used for target invocation.
*/
public val roleArn: Output?
get() = javaResource.roleArn().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })
/**
* The scheduling expression. For example, `cron(0 20 * * ? *)` or `rate(5 minutes)`. At least one of `schedule_expression` or `event_pattern` is required. Can only be used on the default event bus. For more information, refer to the AWS documentation [Schedule Expressions for Rules](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html).
*/
public val scheduleExpression: Output?
get() = javaResource.scheduleExpression().applyValue({ args0 ->
args0.map({ args0 ->
args0
}).orElse(null)
})
/**
* State of the rule.
* Valid values are `DISABLED`, `ENABLED`, and `ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS`.
* When state is `ENABLED`, the rule is enabled for all events except those delivered by CloudTrail.
* To also enable the rule for events delivered by CloudTrail, set `state` to `ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS`.
* Defaults to `ENABLED`.
* Conflicts with `is_enabled`.
* **NOTE:** The rule state `ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS` cannot be used in conjunction with the `schedule_expression` argument.
*/
public val state: Output?
get() = javaResource.state().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })
/**
* A map of tags to assign to the resource. .If configured with a provider `default_tags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
*/
public val tags: Output>?
get() = javaResource.tags().applyValue({ args0 ->
args0.map({ args0 ->
args0.map({ args0 ->
args0.key.to(args0.value)
}).toMap()
}).orElse(null)
})
/**
* A map of tags assigned to the resource, including those inherited from the provider `default_tags` configuration block.
*/
@Deprecated(
message = """
Please use `tags` instead.
""",
)
public val tagsAll: Output>
get() = javaResource.tagsAll().applyValue({ args0 ->
args0.map({ args0 ->
args0.key.to(args0.value)
}).toMap()
})
}
public object EventRuleMapper : ResourceMapper {
override fun supportsMappingOfType(javaResource: Resource): Boolean =
com.pulumi.aws.cloudwatch.EventRule::class == javaResource::class
override fun map(javaResource: Resource): EventRule = EventRule(
javaResource as
com.pulumi.aws.cloudwatch.EventRule,
)
}
/**
* @see [EventRule].
* @param name The _unique_ name of the resulting resource.
* @param block Builder for [EventRule].
*/
public suspend fun eventRule(name: String, block: suspend EventRuleResourceBuilder.() -> Unit): EventRule {
val builder = EventRuleResourceBuilder()
builder.name(name)
block(builder)
return builder.build()
}
/**
* @see [EventRule].
* @param name The _unique_ name of the resulting resource.
*/
public fun eventRule(name: String): EventRule {
val builder = EventRuleResourceBuilder()
builder.name(name)
return builder.build()
}