Skip to content

Commit 69fbcfa

Browse files
author
Joeri Malmberg
committed
v1
1 parent 9385635 commit 69fbcfa

File tree

10 files changed

+196
-17
lines changed

10 files changed

+196
-17
lines changed

.config/.terraform-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ sections:
1414
- modules
1515

1616
content: |-
17-
# <Cloud> <Main resource> Terraform module
18-
A Terraform module which configures your <Cloud> <Main resource>. <Relevant docs>
17+
# AWS Cloudwatch OAM Terraform module
18+
A Terraform module which configures your AWS Cloudwatch OAM. Read [this](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Unified-Cross-Account.html) page for more information.
1919
{{ .Header }}
2020
2121
## Example

.tflint.hcl

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
config {
2+
module = true
3+
}
4+
5+
plugin "aws" {
6+
enabled = true
7+
version = "0.20.0"
8+
source = "github.com/terraform-linters/tflint-ruleset-aws"
9+
}
10+
11+
rule "terraform_required_providers" {
12+
enabled = true
13+
}
14+
15+
rule "terraform_deprecated_index" {
16+
enabled = true
17+
}
18+
19+
rule "terraform_deprecated_interpolation" {
20+
enabled = true
21+
}
22+
23+
rule "terraform_unused_declarations" {
24+
enabled = true
25+
}
26+
27+
rule "terraform_comment_syntax" {
28+
enabled = true
29+
}
30+
31+
rule "terraform_documented_outputs" {
32+
enabled = true
33+
}
34+
35+
rule "terraform_documented_variables" {
36+
enabled = true
37+
}
38+
39+
rule "terraform_typed_variables" {
40+
enabled = true
41+
}
42+
43+
rule "terraform_module_pinned_source" {
44+
enabled = true
45+
}
46+
47+
rule "terraform_naming_convention" {
48+
enabled = true
49+
}
50+
51+
rule "terraform_required_version" {
52+
enabled = true
53+
}
54+
55+
rule "terraform_standard_module_structure" {
56+
enabled = true
57+
}
58+
59+
rule "terraform_workspace_remote" {
60+
enabled = true
61+
}

README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,54 @@
1-
<!-- BEGIN_TF_DOCS -->
2-
# <Cloud> <Main resource> Terraform module
3-
A Terraform module which configures your <Cloud> <Main resource>. <Relevant docs>
1+
# AWS Cloudwatch OAM Terraform module
2+
A Terraform module which configures your AWS Cloudwatch OAM. Read [this](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Unified-Cross-Account.html) page for more information.
43
[![blackbird-logo](https://raw.githubusercontent.com/blackbird-cloud/terraform-module-template/main/.config/logo_simple.png)](https://www.blackbird.cloud)
54

65
## Example
76
```hcl
8-
7+
module "sink" {
8+
# source = "blackbird-cloud/cloudwatch-oam/aws"
9+
# version = "~> 1"
10+
11+
source = "../"
12+
name = "mysink"
13+
organization_id = "o-a1235"
14+
}
915
```
1016

1117
## Requirements
1218

1319
| Name | Version |
1420
|------|---------|
15-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1 |
21+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.2 |
22+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5 |
1623

1724
## Providers
1825

19-
No providers.
26+
| Name | Version |
27+
|------|---------|
28+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.5.0 |
2029

2130
## Resources
2231

23-
No resources.
32+
| Name | Type |
33+
|------|------|
34+
| [aws_oam_sink.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/oam_sink) | resource |
35+
| [aws_oam_sink_policy.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/oam_sink_policy) | resource |
36+
| [aws_caller_identity.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
2437

2538
## Inputs
2639

27-
No inputs.
40+
| Name | Description | Type | Default | Required |
41+
|------|-------------|------|---------|:--------:|
42+
| <a name="input_name"></a> [name](#input\_name) | The Name of the Cloudwatch OAM sink. | `string` | n/a | yes |
43+
| <a name="input_organization_id"></a> [organization\_id](#input\_organization\_id) | Your AWS Organization ID, used in the AWS Cloudwatch Sink Access policy to accept incoming Cloudwatch metrics and logs, and XRay traces. | `string` | n/a | yes |
44+
| <a name="input_tags"></a> [tags](#input\_tags) | 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. | `map(string)` | `{}` | no |
2845

2946
## Outputs
3047

31-
No outputs.
48+
| Name | Description |
49+
|------|-------------|
50+
| <a name="output_sink"></a> [sink](#output\_sink) | The Cloudwatch OAM Sink |
51+
| <a name="output_stackset_template"></a> [stackset\_template](#output\_stackset\_template) | The AWS Cloudformation Stackset template to use for creating AWS Cloudwatch OAM links. |
3252

3353
## About
3454

@@ -38,5 +58,4 @@ Checkout our other :point\_right: [terraform modules](https://registry.terraform
3858

3959
## Copyright
4060

41-
Copyright © 2017-2023 [Blackbird Cloud](https://www.blackbird.cloud)
42-
<!-- END_TF_DOCS -->
61+
Copyright © 2017-2023 [Blackbird Cloud](https://www.blackbird.cloud)

example/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module "sink" {
2+
# source = "blackbird-cloud/cloudwatch-oam/aws"
3+
# version = "~> 1"
4+
5+
source = "../"
6+
name = "mysink"
7+
organization_id = "o-a1235"
8+
}

example/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "sink" {
2+
value = module.sink.sink
3+
description = "The Cloudwatch OAM Sink"
4+
}
5+
6+
output "stackset_template" {
7+
value = module.sink.stackset_template
8+
description = "The AWS Cloudformation Stackset template to use for creating AWS Cloudwatch OAM links."
9+
}

main.tf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
data "aws_caller_identity" "default" {}
2+
3+
resource "aws_oam_sink" "default" {
4+
name = var.name
5+
tags = var.tags
6+
}
7+
8+
resource "aws_oam_sink_policy" "default" {
9+
sink_identifier = aws_oam_sink.default.id
10+
policy = jsonencode({
11+
Version = "2012-10-17"
12+
Statement = [
13+
{
14+
Action = [
15+
"oam:CreateLink",
16+
"oam:UpdateLink"
17+
]
18+
Effect = "Allow"
19+
Resource = "*"
20+
Principal = "*"
21+
Condition = {
22+
"ForAllValues:StringEquals" = {
23+
"oam:ResourceTypes" = [
24+
"AWS::Logs::LogGroup",
25+
"AWS::CloudWatch::Metric",
26+
"AWS::XRay::Trace"
27+
]
28+
}
29+
"ForAnyValue:StringEquals" : {
30+
"aws:PrincipalOrgID" : "${var.organization_id}"
31+
}
32+
}
33+
}
34+
]
35+
})
36+
}

outputs.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
output "sink" {
2+
value = aws_oam_sink.default
3+
description = "The Cloudwatch OAM Sink"
4+
}
15

6+
output "stackset_template" {
7+
value = templatefile("${path.module}/stackset.tmpl", {
8+
account_id = data.aws_caller_identity.default.account_id
9+
sink_arn = aws_oam_sink.default.arn
10+
})
11+
description = "The AWS Cloudformation Stackset template to use for creating AWS Cloudwatch OAM links."
12+
}

stackset.tmpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
AWSTemplateFormatVersion: 2010-09-09
2+
3+
Conditions:
4+
SkipMonitoringAccount: !Not
5+
- !Equals
6+
- !Ref AWS::AccountId
7+
- "${account_id}"
8+
9+
Resources:
10+
Link:
11+
Type: AWS::Oam::Link
12+
Condition: SkipMonitoringAccount
13+
Properties:
14+
LabelTemplate: "$AccountName"
15+
ResourceTypes:
16+
- "AWS::CloudWatch::Metric"
17+
- "AWS::Logs::LogGroup"
18+
- "AWS::XRay::Trace"
19+
SinkIdentifier: "${sink_arn}"

variables.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
variable "name" {
2+
type = string
3+
description = "The Name of the Cloudwatch OAM sink."
4+
}
5+
6+
variable "organization_id" {
7+
type = string
8+
description = "Your AWS Organization ID, used in the AWS Cloudwatch Sink Access policy to accept incoming Cloudwatch metrics and logs, and XRay traces."
9+
}
10+
11+
variable "tags" {
12+
type = map(string)
13+
description = "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."
14+
default = {}
15+
}

versions.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
terraform {
2-
required_version = ">= 1"
3-
42
required_providers {
5-
6-
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5"
6+
}
77
}
8+
required_version = ">= 1.2"
89
}

0 commit comments

Comments
 (0)