Created
February 2, 2023 07:11
-
-
Save waiyanwh/4c5cef430805d72afb105b44bcf97ad6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_cloudwatch_log_group" "example" { | |
name = "example-log-group" | |
} | |
resource "aws_iam_policy" "example" { | |
name = "example-policy" | |
policy = jsonencode({ | |
Version = "2012-10-17", | |
Statement = [ | |
{ | |
Action = "logs:CreateLogStream", | |
Resource = "${aws_cloudwatch_log_group.example.arn}/*", | |
Effect = "Allow" | |
}, | |
{ | |
Action = "logs:PutLogEvents", | |
Resource = "${aws_cloudwatch_log_group.example.arn}/*", | |
Effect = "Allow" | |
} | |
] | |
}) | |
} | |
resource "aws_iam_role" "example" { | |
name = "example-role" | |
assume_role_policy = jsonencode({ | |
Version = "2012-10-17", | |
Statement = [ | |
{ | |
Action = "sts:AssumeRole", | |
Principal = { | |
Service = "sns.amazonaws.com" | |
}, | |
Effect = "Allow" | |
} | |
] | |
}) | |
} | |
resource "aws_sns_topic" "example" { | |
name = "example-topic" | |
delivery_policy = jsonencode({ | |
version = "2010-03-31", | |
statement = [ | |
{ | |
resource = "${aws_cloudwatch_log_group.example.arn}", | |
effect = "Allow", | |
principals = { | |
type = "Service", | |
identifiers = ["sns.amazonaws.com"] | |
}, | |
actions = ["logs:CreateLogStream", "logs:PutLogEvents"] | |
} | |
] | |
}) | |
} | |
resource "aws_iam_role_policy_attachment" "example" { | |
role = aws_iam_role.example.name | |
policy_arn = aws_iam_policy.example.arn | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment