From 13db16ac70f8612984ba9abf379f403fcdf5d4d9 Mon Sep 17 00:00:00 2001 From: Manu Chandrasekhar Date: Fri, 19 Jul 2024 14:25:47 -0400 Subject: [PATCH] docs: add examples for awscc_cloudwatch_dashboard --- docs/resources/cloudwatch_dashboard.md | 269 +++++++++++++++++- .../cloudwatch_dashboard.tf | 263 +++++++++++++++++ .../resources/cloudwatch_dashboard.md.tmpl | 25 ++ 3 files changed, 555 insertions(+), 2 deletions(-) create mode 100644 examples/resources/awscc_cloudwatch_dashboard/cloudwatch_dashboard.tf create mode 100644 templates/resources/cloudwatch_dashboard.md.tmpl diff --git a/docs/resources/cloudwatch_dashboard.md b/docs/resources/cloudwatch_dashboard.md index 4be70d1bfa..021f1561c9 100644 --- a/docs/resources/cloudwatch_dashboard.md +++ b/docs/resources/cloudwatch_dashboard.md @@ -1,5 +1,4 @@ --- -# generated by https://github.com/hashicorp/terraform-plugin-docs page_title: "awscc_cloudwatch_dashboard Resource - terraform-provider-awscc" subcategory: "" description: |- @@ -10,7 +9,273 @@ description: |- Resource Type definition for AWS::CloudWatch::Dashboard +## Example Usage based on https://github.com/aws-solutions-library-samples/guidance-for-crossregion-failover-and-graceful-failback-and-observability-on-aws +```terraform +resource "awscc_cloudwatch_dashboard" "example" { + dashboard_body = jsonencode( + { + "widgets" : [ + { + "height" : 2, + "width" : 13, + "y" : 2, + "x" : 0, + "type" : "alarm", + "properties" : { + "title" : "Composite Alarms by Service", + "alarms" : [ + "arn:aws:cloudwatch:us-east-1:${data.aws_caller_identity.current.account_id}:alarm:API Gateway Health", + "arn:aws:cloudwatch:us-east-1:${data.aws_caller_identity.current.account_id}:alarm:Lambda Health", + "arn:aws:cloudwatch:us-east-1:${data.aws_caller_identity.current.account_id}:alarm:RDS Health" + ] + } + }, + { + "height" : 4, + "width" : 15, + "y" : 26, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/RDS", "CPUUtilization", "DBClusterIdentifier", "dbcluster1"], + [".", "Deadlocks", ".", "."], + [".", "FreeableMemory", ".", "."], + [".", "ReadLatency", ".", "."], + [".", "WriteLatency", ".", "."] + ], + "view" : "singleValue", + "region" : "us-east-1", + "yAxis" : { + "left" : { + "min" : 0, + "max" : 100 + } + }, + "title" : "dbcluster1-instance1", + "period" : 300, + "setPeriodToTimeRange" : true, + "sparkline" : false, + "trend" : false, + "stacked" : false, + "stat" : "Average", + "singleValueFullPrecision" : false + } + }, + { + "height" : 1, + "width" : 13, + "y" : 4, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "## Integration" + } + }, + { + "height" : 1, + "width" : 19, + "y" : 24, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "## Storage\n" + } + }, + { + "height" : 1, + "width" : 19, + "y" : 10, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "## Compute\n" + } + }, + { + "height" : 2, + "width" : 13, + "y" : 0, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "# Application Health Dashboard\nCombined Dashboard of **AWS Health** and **health of each service** for the Regional Failover solution.\n \n" + } + }, + { + "height" : 4, + "width" : 12, + "y" : 6, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/ApiGateway", "Count", "ApiName", "Remittance", { "yAxis" : "left", "label" : "API Calls" }], + [".", "Latency", ".", ".", { "stat" : "Average", "label" : "Avg Latency" }], + [".", "4XXError", ".", "."], + [".", "5XXError", ".", "."] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "period" : 300, + "stat" : "Sum", + "setPeriodToTimeRange" : true, + "trend" : false, + "liveData" : false, + "stacked" : false, + "singleValueFullPrecision" : false, + "title" : "Dev Resource APIs" + } + }, + { + "height" : 4, + "width" : 11, + "y" : 20, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/Lambda", "Invocations", "FunctionName", "UpdateRemittance"], + [".", "Errors", ".", "."], + [".", "Duration", ".", ".", { "stat" : "Average" }], + [".", "Throttles", ".", "."] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "period" : 300, + "stat" : "Sum", + "setPeriodToTimeRange" : true, + "trend" : false, + "title" : "UpdateRemittance" + } + }, + { + "height" : 4, + "width" : 11, + "y" : 12, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/Lambda", "Invocations", "FunctionName", "GetRemittances", { "region" : "us-east-1" }], + ["AWS/Lambda", "Errors", "FunctionName", "GetRemittances", { "region" : "us-east-1" }], + ["AWS/Lambda", "Duration", "FunctionName", "GetRemittances", { "stat" : "Average", "region" : "us-east-1" }], + ["AWS/Lambda", "Throttles", "FunctionName", "GetRemittances", { "region" : "us-east-1" }] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "stat" : "Sum", + "period" : 300, + "setPeriodToTimeRange" : true, + "trend" : false, + "title" : "GetRemittance", + "stacked" : false + } + }, + { + "height" : 4, + "width" : 11, + "y" : 16, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/Lambda", "Invocations", "FunctionName", "CreateRemittance"], + [".", "Errors", ".", "."], + [".", "Duration", ".", ".", { "stat" : "Average" }], + [".", "Throttles", ".", "."] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "period" : 300, + "stat" : "Sum", + "setPeriodToTimeRange" : true, + "trend" : false, + "title" : "CreateRemittance" + } + }, + { + "height" : 10, + "width" : 24, + "y" : 30, + "x" : 0, + "type" : "trace", + "properties" : { + "service" : "ServiceLensWidget", + "title" : "Region Failover Solution Traces", + "params" : { + "view" : "tracesTable", + "group" : "Default", + "region" : "us-east-1" + } + } + }, + { + "height" : 1, + "width" : 12, + "y" : 5, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "### API Gateway" + } + }, + { + "height" : 1, + "width" : 18, + "y" : 11, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "### Lambda" + } + }, + { + "height" : 1, + "width" : 15, + "y" : 25, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "### RDS Aurora PostgreSQL\n" + } + }, + { + "height" : 4, + "width" : 7, + "y" : 12, + "x" : 11, + "type" : "metric", + "properties" : { + "metrics" : [ + ["LambdaGetRemittance", "AccessDeniedException", { "color" : "#d62728", "label" : "SecretsManager AccessDeniedException" }], + [".", "DBConnectionTimedOut"] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "title" : "GetRemittance - Function Errors", + "period" : 300, + "stat" : "Sum", + "setPeriodToTimeRange" : true, + "trend" : false + } + } + ] + } + ) + dashboard_name = "example" + +} + + +data "aws_caller_identity" "current" {} +``` ## Schema @@ -33,4 +298,4 @@ Import is supported using the following syntax: ```shell $ terraform import awscc_cloudwatch_dashboard.example -``` +``` \ No newline at end of file diff --git a/examples/resources/awscc_cloudwatch_dashboard/cloudwatch_dashboard.tf b/examples/resources/awscc_cloudwatch_dashboard/cloudwatch_dashboard.tf new file mode 100644 index 0000000000..3c63b95b03 --- /dev/null +++ b/examples/resources/awscc_cloudwatch_dashboard/cloudwatch_dashboard.tf @@ -0,0 +1,263 @@ +resource "awscc_cloudwatch_dashboard" "example" { + dashboard_body = jsonencode( + { + "widgets" : [ + { + "height" : 2, + "width" : 13, + "y" : 2, + "x" : 0, + "type" : "alarm", + "properties" : { + "title" : "Composite Alarms by Service", + "alarms" : [ + "arn:aws:cloudwatch:us-east-1:${data.aws_caller_identity.current.account_id}:alarm:API Gateway Health", + "arn:aws:cloudwatch:us-east-1:${data.aws_caller_identity.current.account_id}:alarm:Lambda Health", + "arn:aws:cloudwatch:us-east-1:${data.aws_caller_identity.current.account_id}:alarm:RDS Health" + ] + } + }, + { + "height" : 4, + "width" : 15, + "y" : 26, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/RDS", "CPUUtilization", "DBClusterIdentifier", "dbcluster1"], + [".", "Deadlocks", ".", "."], + [".", "FreeableMemory", ".", "."], + [".", "ReadLatency", ".", "."], + [".", "WriteLatency", ".", "."] + ], + "view" : "singleValue", + "region" : "us-east-1", + "yAxis" : { + "left" : { + "min" : 0, + "max" : 100 + } + }, + "title" : "dbcluster1-instance1", + "period" : 300, + "setPeriodToTimeRange" : true, + "sparkline" : false, + "trend" : false, + "stacked" : false, + "stat" : "Average", + "singleValueFullPrecision" : false + } + }, + { + "height" : 1, + "width" : 13, + "y" : 4, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "## Integration" + } + }, + { + "height" : 1, + "width" : 19, + "y" : 24, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "## Storage\n" + } + }, + { + "height" : 1, + "width" : 19, + "y" : 10, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "## Compute\n" + } + }, + { + "height" : 2, + "width" : 13, + "y" : 0, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "# Application Health Dashboard\nCombined Dashboard of **AWS Health** and **health of each service** for the Regional Failover solution.\n \n" + } + }, + { + "height" : 4, + "width" : 12, + "y" : 6, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/ApiGateway", "Count", "ApiName", "Remittance", { "yAxis" : "left", "label" : "API Calls" }], + [".", "Latency", ".", ".", { "stat" : "Average", "label" : "Avg Latency" }], + [".", "4XXError", ".", "."], + [".", "5XXError", ".", "."] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "period" : 300, + "stat" : "Sum", + "setPeriodToTimeRange" : true, + "trend" : false, + "liveData" : false, + "stacked" : false, + "singleValueFullPrecision" : false, + "title" : "Dev Resource APIs" + } + }, + { + "height" : 4, + "width" : 11, + "y" : 20, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/Lambda", "Invocations", "FunctionName", "UpdateRemittance"], + [".", "Errors", ".", "."], + [".", "Duration", ".", ".", { "stat" : "Average" }], + [".", "Throttles", ".", "."] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "period" : 300, + "stat" : "Sum", + "setPeriodToTimeRange" : true, + "trend" : false, + "title" : "UpdateRemittance" + } + }, + { + "height" : 4, + "width" : 11, + "y" : 12, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/Lambda", "Invocations", "FunctionName", "GetRemittances", { "region" : "us-east-1" }], + ["AWS/Lambda", "Errors", "FunctionName", "GetRemittances", { "region" : "us-east-1" }], + ["AWS/Lambda", "Duration", "FunctionName", "GetRemittances", { "stat" : "Average", "region" : "us-east-1" }], + ["AWS/Lambda", "Throttles", "FunctionName", "GetRemittances", { "region" : "us-east-1" }] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "stat" : "Sum", + "period" : 300, + "setPeriodToTimeRange" : true, + "trend" : false, + "title" : "GetRemittance", + "stacked" : false + } + }, + { + "height" : 4, + "width" : 11, + "y" : 16, + "x" : 0, + "type" : "metric", + "properties" : { + "metrics" : [ + ["AWS/Lambda", "Invocations", "FunctionName", "CreateRemittance"], + [".", "Errors", ".", "."], + [".", "Duration", ".", ".", { "stat" : "Average" }], + [".", "Throttles", ".", "."] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "period" : 300, + "stat" : "Sum", + "setPeriodToTimeRange" : true, + "trend" : false, + "title" : "CreateRemittance" + } + }, + { + "height" : 10, + "width" : 24, + "y" : 30, + "x" : 0, + "type" : "trace", + "properties" : { + "service" : "ServiceLensWidget", + "title" : "Region Failover Solution Traces", + "params" : { + "view" : "tracesTable", + "group" : "Default", + "region" : "us-east-1" + } + } + }, + { + "height" : 1, + "width" : 12, + "y" : 5, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "### API Gateway" + } + }, + { + "height" : 1, + "width" : 18, + "y" : 11, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "### Lambda" + } + }, + { + "height" : 1, + "width" : 15, + "y" : 25, + "x" : 0, + "type" : "text", + "properties" : { + "markdown" : "### RDS Aurora PostgreSQL\n" + } + }, + { + "height" : 4, + "width" : 7, + "y" : 12, + "x" : 11, + "type" : "metric", + "properties" : { + "metrics" : [ + ["LambdaGetRemittance", "AccessDeniedException", { "color" : "#d62728", "label" : "SecretsManager AccessDeniedException" }], + [".", "DBConnectionTimedOut"] + ], + "sparkline" : false, + "view" : "singleValue", + "region" : "us-east-1", + "title" : "GetRemittance - Function Errors", + "period" : 300, + "stat" : "Sum", + "setPeriodToTimeRange" : true, + "trend" : false + } + } + ] + } + ) + dashboard_name = "example" + +} + + +data "aws_caller_identity" "current" {} \ No newline at end of file diff --git a/templates/resources/cloudwatch_dashboard.md.tmpl b/templates/resources/cloudwatch_dashboard.md.tmpl new file mode 100644 index 0000000000..317396f19d --- /dev/null +++ b/templates/resources/cloudwatch_dashboard.md.tmpl @@ -0,0 +1,25 @@ +--- +page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" +subcategory: "" +description: |- +{{ .Description | plainmarkdown | trimspace | prefixlines " " }} +--- + +# {{.Name}} ({{.Type}}) + +{{ .Description | trimspace }} + +## Example Usage based on https://github.com/aws-solutions-library-samples/guidance-for-crossregion-failover-and-graceful-failback-and-observability-on-aws + +{{ tffile (printf "examples/resources/%s/cloudwatch_dashboard.tf" .Name)}} + +{{ .SchemaMarkdown | trimspace }} +{{- if .HasImport }} + +## Import + +Import is supported using the following syntax: + +{{ codefile "shell" .ImportFile }} + +{{- end }} \ No newline at end of file