Skip to content

Commit

Permalink
chore: working on reducing the noise in the terraform diff
Browse files Browse the repository at this point in the history
  • Loading branch information
gambol99 committed Dec 24, 2024
1 parent d35435c commit 1f1d64a
Show file tree
Hide file tree
Showing 17 changed files with 155 additions and 278 deletions.
2 changes: 1 addition & 1 deletion .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ Frequently (quartley at least) check and upgrade:
| <a name="input_enable_teams"></a> [enable\_teams](#input\_enable\_teams) | To send to teams, set to true | `bool` | `false` | no |
| <a name="input_identity_center_role"></a> [identity\_center\_role](#input\_identity\_center\_role) | The name of the role to use when redirecting through Identity Center | `string` | `null` | no |
| <a name="input_identity_center_start_url"></a> [identity\_center\_start\_url](#input\_identity\_center\_start\_url) | The start URL of your Identity Center instance | `string` | `null` | no |
| <a name="input_post_icons_url"></a> [post\_icons\_url](#input\_post\_icons\_url) | URLs (not base64 encoded!) to publically available icons for highlighting posts of error and/or warning status. Ideally 50px square. Set to non-existent URLs to disable icons | <pre>object({<br/> error_url = string<br/> warning_url = string<br/> })</pre> | <pre>{<br/> "error_url": "https://raw.githubusercontent.com/appvia/terraform-aws-notifications/main/resources/posts-attention-icon.png",<br/> "warning_url": "https://raw.githubusercontent.com/appvia/terraform-aws-notifications/main/resources/posts-warning-icon.png"<br/>}</pre> | no |
| <a name="input_slack"></a> [slack](#input\_slack) | The configuration for Slack notifications | <pre>object({<br/> lambda_name = optional(string, "slack-notify")<br/> # The name of the lambda function to create <br/> lambda_description = optional(string, "Lambda function to send slack notifications")<br/> # The description for the slack lambda<br/> secret_name = optional(string)<br/> # An optional secret name in secrets manager to use for the slack configuration <br/> webhook_url = optional(string)<br/> # The webhook url to post to<br/> filter_policy = optional(string)<br/> # An optional SNS subscription filter policy to apply<br/> filter_policy_scope = optional(string)<br/> # If filter policy provided this is the scope of that policy; either "MessageAttributes" (default) or "MessageBody"<br/> })</pre> | `null` | no |
| <a name="input_slack"></a> [slack](#input\_slack) | The configuration for Slack notifications | <pre>object({<br/> lambda_name = optional(string, "slack-notify")<br/> # The name of the lambda function to create<br/> lambda_description = optional(string, "Lambda function to send slack notifications")<br/> # The description for the slack lambda<br/> secret_name = optional(string)<br/> # An optional secret name in secrets manager to use for the slack configuration<br/> webhook_url = optional(string)<br/> # The webhook url to post to<br/> filter_policy = optional(string)<br/> # An optional SNS subscription filter policy to apply<br/> filter_policy_scope = optional(string)<br/> # If filter policy provided this is the scope of that policy; either "MessageAttributes" (default) or "MessageBody"<br/> })</pre> | `null` | no |
| <a name="input_sns_topic_policy"></a> [sns\_topic\_policy](#input\_sns\_topic\_policy) | The policy to attach to the sns topic, else we default to account root | `string` | `null` | no |
| <a name="input_subscribers"></a> [subscribers](#input\_subscribers) | Optional list of custom subscribers to the SNS topic | <pre>map(object({<br/> protocol = string<br/> # The protocol to use. The possible values for this are: sqs, sms, lambda, application. (http or https are partially supported, see below).<br/> endpoint = string<br/> # The endpoint to send data to, the contents will vary with the protocol. (see below for more information)<br/> endpoint_auto_confirms = bool<br/> # Boolean indicating whether the end point is capable of auto confirming subscription e.g., PagerDuty (default is false)<br/> raw_message_delivery = bool<br/> # Boolean indicating whether or not to enable raw message delivery (the original message is directly passed, not wrapped in JSON with the original message in the message property) (default is false)<br/> }))</pre> | `{}` | no |
| <a name="input_teams"></a> [teams](#input\_teams) | The configuration for teams notifications | <pre>object({<br/> lambda_name = optional(string, "teams-notify")<br/> # The name of the lambda function to create <br/> lambda_description = optional(string, "Lambda function to send teams notifications")<br/> # The description for the teams lambda<br/> secret_name = optional(string)<br/> # An optional secret name in secrets manager to use for the slack configuration <br/> webhook_url = optional(string)<br/> # The webhook url to post to<br/> filter_policy = optional(string)<br/> # An optional SNS subscription filter policy to apply<br/> filter_policy_scope = optional(string)<br/> # If filter policy provided this is the scope of that policy; either "MessageAttributes" (default) or "MessageBody"<br/> })</pre> | `null` | no |
| <a name="input_teams"></a> [teams](#input\_teams) | The configuration for teams notifications | <pre>object({<br/> lambda_name = optional(string, "teams-notify")<br/> # The name of the lambda function to create<br/> lambda_description = optional(string, "Lambda function to send teams notifications")<br/> # The description for the teams lambda<br/> secret_name = optional(string)<br/> # An optional secret name in secrets manager to use for the slack configuration<br/> webhook_url = optional(string)<br/> # The webhook url to post to<br/> filter_policy = optional(string)<br/> # An optional SNS subscription filter policy to apply<br/> filter_policy_scope = optional(string)<br/> # If filter policy provided this is the scope of that policy; either "MessageAttributes" (default) or "MessageBody"<br/> })</pre> | `null` | no |

## Outputs

Expand Down
16 changes: 10 additions & 6 deletions data.tf
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@

## Find the current AWS account ID
## Find the current AWS account ID
data "aws_caller_identity" "current" {}

## Find the current AWS region
data "aws_region" "current" {}

## Provision an SNS IAM policy allowing the account root
## Find the aws partition
data "aws_partition" "current" {}

## Provision an SNS IAM policy allowing the account root
data "aws_iam_policy_document" "current" {
statement {
sid = "AllowAccountRoot"
Expand Down Expand Up @@ -54,28 +58,28 @@ data "aws_iam_policy_document" "current" {
}
}

## Find the slack secret if required
## Find the slack secret if required
data "aws_secretsmanager_secret" "slack" {
count = local.enable_slack_secret ? 1 : 0

name = var.slack.secret_name
}

## Find the latest version of the slack secret if required
## Find the latest version of the slack secret if required
data "aws_secretsmanager_secret_version" "slack" {
count = local.enable_slack_secret ? 1 : 0

secret_id = data.aws_secretsmanager_secret.slack[0].id
}

## Find the teams secret if required
## Find the teams secret if required
data "aws_secretsmanager_secret" "teams" {
count = local.enable_teams_secret ? 1 : 0

name = var.teams.secret_name
}

## Find the latest version of the teams secret if required
## Find the latest version of the teams secret if required
data "aws_secretsmanager_secret_version" "teams" {
count = local.enable_teams_secret ? 1 : 0

Expand Down
4 changes: 3 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ resource "aws_sns_topic_subscription" "subscribers" {
module "notify" {
source = "./modules/notify"

aws_partition = data.aws_partition.current.partition
aws_region = data.aws_region.current.name
aws_account_id = data.aws_caller_identity.current.account_id
accounts_id_to_name = var.accounts_id_to_name
cloudwatch_log_group_kms_key_id = var.cloudwatch_log_group_kms_key_id
cloudwatch_log_group_retention_in_days = var.cloudwatch_log_group_retention
Expand All @@ -53,7 +56,6 @@ module "notify" {
enable_teams = var.enable_teams
identity_center_role = var.identity_center_role
identity_center_start_url = var.identity_center_start_url
post_icons_url = var.post_icons_url
recreate_missing_package = false
sns_topic_name = var.sns_topic_name
tags = var.tags
Expand Down
2 changes: 1 addition & 1 deletion modules/notify/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions modules/notify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,52 +93,43 @@ Subsumed by appvia's GNU V3 license; [see license](../../LICENSE).

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.8 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0.0 |
| <a name="provider_local"></a> [local](#provider\_local) | >= 2.5.0 |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_aws_account_id"></a> [aws\_account\_id](#input\_aws\_account\_id) | The AWS account ID | `string` | n/a | yes |
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | The AWS region to deploy to | `string` | n/a | yes |
| <a name="input_sns_topic_name"></a> [sns\_topic\_name](#input\_sns\_topic\_name) | The name of the SNS topic to create | `string` | n/a | yes |
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | n/a | yes |
| <a name="input_accounts_id_to_name"></a> [accounts\_id\_to\_name](#input\_accounts\_id\_to\_name) | A mapping of account id and account name - used by notification lamdba to map an account ID to a human readable name | `map(string)` | `{}` | no |
| <a name="input_architecture"></a> [architecture](#input\_architecture) | Instruction set architecture for your Lambda function. Valid values are "x86\_64" or "arm64". | `string` | `"arm64"` | no |
| <a name="input_aws_partition"></a> [aws\_partition](#input\_aws\_partition) | The partition in which the resource is located. A partition is a group of AWS Regions. Each AWS account is scoped to one partition. | `string` | `"aws"` | no |
| <a name="input_aws_powertools_service_name"></a> [aws\_powertools\_service\_name](#input\_aws\_powertools\_service\_name) | The service name to use | `string` | `"appvia-notifications"` | no |
| <a name="input_cloudwatch_log_group_kms_key_id"></a> [cloudwatch\_log\_group\_kms\_key\_id](#input\_cloudwatch\_log\_group\_kms\_key\_id) | The ARN of the KMS Key to use when encrypting log data for Lambda | `string` | `null` | no |
| <a name="input_cloudwatch_log_group_retention_in_days"></a> [cloudwatch\_log\_group\_retention\_in\_days](#input\_cloudwatch\_log\_group\_retention\_in\_days) | Specifies the number of days you want to retain log events in log group for Lambda. | `number` | `0` | no |
| <a name="input_create_sns_topic"></a> [create\_sns\_topic](#input\_create\_sns\_topic) | Whether to create new SNS topic | `bool` | `true` | no |
| <a name="input_delivery_channels"></a> [delivery\_channels](#input\_delivery\_channels) | The configuration for Slack notifications | <pre>map(object({<br/> lambda_name = optional(string, "delivery_channel")<br/> # The name of the lambda function to create<br/> lambda_description = optional(string, "Lambda function to send notifications")<br/> # The description for the lambda<br/> secret_name = optional(string)<br/> # An optional secret name in secrets manager to use for the slack configuration<br/> webhook_url = optional(string)<br/> # The webhook url to post to<br/> filter_policy = optional(string)<br/> # An optional SNS subscription filter policy to apply<br/> filter_policy_scope = optional(string)<br/> # If filter policy provided this is the scope of that policy; either "MessageAttributes" (default) or "MessageBody"<br/> }))</pre> | `null` | no |
| <a name="input_enable_slack"></a> [enable\_slack](#input\_enable\_slack) | To send to slack, set to true | `bool` | `false` | no |
| <a name="input_enable_sns_topic_delivery_status_logs"></a> [enable\_sns\_topic\_delivery\_status\_logs](#input\_enable\_sns\_topic\_delivery\_status\_logs) | Whether to enable SNS topic delivery status logs | `bool` | `false` | no |
| <a name="input_enable_teams"></a> [enable\_teams](#input\_enable\_teams) | To send to teams, set to true | `bool` | `false` | no |
| <a name="input_iam_policy_path"></a> [iam\_policy\_path](#input\_iam\_policy\_path) | Path of policies to that should be added to IAM role for Lambda Function | `string` | `null` | no |
| <a name="input_iam_role_boundary_policy_arn"></a> [iam\_role\_boundary\_policy\_arn](#input\_iam\_role\_boundary\_policy\_arn) | The ARN of the policy that is used to set the permissions boundary for the role | `string` | `null` | no |
| <a name="input_iam_role_name_prefix"></a> [iam\_role\_name\_prefix](#input\_iam\_role\_name\_prefix) | A unique role name beginning with the specified prefix | `string` | `"lambda"` | no |
| <a name="input_iam_role_path"></a> [iam\_role\_path](#input\_iam\_role\_path) | Path of IAM role to use for Lambda Function | `string` | `null` | no |
| <a name="input_identity_center_role"></a> [identity\_center\_role](#input\_identity\_center\_role) | The name of the role to use when redirecting through Identity Center | `string` | `null` | no |
| <a name="input_identity_center_start_url"></a> [identity\_center\_start\_url](#input\_identity\_center\_start\_url) | The start URL of your Identity Center instance | `string` | `null` | no |
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | ARN of the KMS key used for decrypting slack webhook url | `string` | `""` | no |
| <a name="input_lambda_attach_dead_letter_policy"></a> [lambda\_attach\_dead\_letter\_policy](#input\_lambda\_attach\_dead\_letter\_policy) | Controls whether SNS/SQS dead letter notification policy should be added to IAM role for Lambda Function | `bool` | `false` | no |
| <a name="input_lambda_dead_letter_target_arn"></a> [lambda\_dead\_letter\_target\_arn](#input\_lambda\_dead\_letter\_target\_arn) | The ARN of an SNS topic or SQS queue to notify when an invocation fails. | `string` | `null` | no |
| <a name="input_lambda_function_ephemeral_storage_size"></a> [lambda\_function\_ephemeral\_storage\_size](#input\_lambda\_function\_ephemeral\_storage\_size) | Amount of ephemeral storage (/tmp) in MB your Lambda Function can use at runtime. Valid value between 512 MB to 10,240 MB (10 GB). | `number` | `512` | no |
| <a name="input_lambda_function_s3_bucket"></a> [lambda\_function\_s3\_bucket](#input\_lambda\_function\_s3\_bucket) | S3 bucket to store artifacts | `string` | `null` | no |
| <a name="input_lambda_function_store_on_s3"></a> [lambda\_function\_store\_on\_s3](#input\_lambda\_function\_store\_on\_s3) | Whether to store produced artifacts on S3 or locally. | `bool` | `false` | no |
| <a name="input_lambda_role"></a> [lambda\_role](#input\_lambda\_role) | IAM role attached to the Lambda Function. If this is set then a role will not be created for you. | `string` | `""` | no |
| <a name="input_lambda_source_path"></a> [lambda\_source\_path](#input\_lambda\_source\_path) | The source path of the custom Lambda function | `string` | `null` | no |
| <a name="input_post_icons_url"></a> [post\_icons\_url](#input\_post\_icons\_url) | URLs (not base64 encoded!) to publically available icons for highlighting posts of error and/or warning status. Ideally 50px square. | <pre>object({<br/> error_url = string<br/> warning_url = string<br/> })</pre> | <pre>{<br/> "error_url": "https://raw.githubusercontent.com/appvia/terraform-aws-notifications/main/resources/posts-attention-icon.png",<br/> "warning_url": "https://raw.githubusercontent.com/appvia/terraform-aws-notifications/main/resources/posts-warning-icon.png"<br/>}</pre> | no |
| <a name="input_powertools_layer_arn_suffix"></a> [powertools\_layer\_arn\_suffix](#input\_powertools\_layer\_arn\_suffix) | The suffix of the ARN to use for AWS Powertools lambda layer (must match the architecture:https://docs.powertools.aws.dev/lambda/python/latest/. | `string` | `"AWSLambdaPowertoolsPythonV2-Arm64:79"` | no |
| <a name="input_python_runtime"></a> [python\_runtime](#input\_python\_runtime) | The lambda python runtime | `string` | `"python3.12"` | no |
| <a name="input_recreate_missing_package"></a> [recreate\_missing\_package](#input\_recreate\_missing\_package) | Whether to recreate missing Lambda package if it is missing locally or not | `bool` | `true` | no |
| <a name="input_reserved_concurrent_executions"></a> [reserved\_concurrent\_executions](#input\_reserved\_concurrent\_executions) | The amount of reserved concurrent executions for this lambda function. A value of 0 disables lambda from being triggered and -1 removes any concurrency limitations | `number` | `-1` | no |
| <a name="input_sns_topic_feedback_role_description"></a> [sns\_topic\_feedback\_role\_description](#input\_sns\_topic\_feedback\_role\_description) | Description of IAM role to use for SNS topic delivery status logging | `string` | `null` | no |
| <a name="input_sns_topic_feedback_role_force_detach_policies"></a> [sns\_topic\_feedback\_role\_force\_detach\_policies](#input\_sns\_topic\_feedback\_role\_force\_detach\_policies) | Specifies to force detaching any policies the IAM role has before destroying it. | `bool` | `true` | no |
| <a name="input_sns_topic_feedback_role_name"></a> [sns\_topic\_feedback\_role\_name](#input\_sns\_topic\_feedback\_role\_name) | Name of the IAM role to use for SNS topic delivery status logging | `string` | `null` | no |
| <a name="input_sns_topic_feedback_role_path"></a> [sns\_topic\_feedback\_role\_path](#input\_sns\_topic\_feedback\_role\_path) | Path of IAM role to use for SNS topic delivery status logging | `string` | `null` | no |
| <a name="input_sns_topic_feedback_role_permissions_boundary"></a> [sns\_topic\_feedback\_role\_permissions\_boundary](#input\_sns\_topic\_feedback\_role\_permissions\_boundary) | The ARN of the policy that is used to set the permissions boundary for the IAM role used by SNS topic delivery status logging | `string` | `null` | no |
| <a name="input_sns_topic_kms_key_id"></a> [sns\_topic\_kms\_key\_id](#input\_sns\_topic\_kms\_key\_id) | ARN of the KMS key used for enabling SSE on the topic | `string` | `""` | no |
| <a name="input_sns_topic_lambda_feedback_role_arn"></a> [sns\_topic\_lambda\_feedback\_role\_arn](#input\_sns\_topic\_lambda\_feedback\_role\_arn) | IAM role for SNS topic delivery status logs. If this is set then a role will not be created for you. | `string` | `""` | no |
| <a name="input_sns_topic_lambda_feedback_sample_rate"></a> [sns\_topic\_lambda\_feedback\_sample\_rate](#input\_sns\_topic\_lambda\_feedback\_sample\_rate) | The percentage of successful deliveries to log | `number` | `100` | no |
| <a name="input_trigger_on_package_timestamp"></a> [trigger\_on\_package\_timestamp](#input\_trigger\_on\_package\_timestamp) | Whether to recreate the Lambda package if the timestamp changes | `bool` | `true` | no |

## Outputs
Expand Down
10 changes: 0 additions & 10 deletions modules/notify/data.tf

This file was deleted.

1 change: 0 additions & 1 deletion modules/notify/functions/src/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
account_id_name_mappings.py
notification_emblems.py
Loading

0 comments on commit 1f1d64a

Please sign in to comment.