Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update APS workspace resource provider to support logging configuration #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion aws-aps-rulegroupsnamespace/.rpdk-config
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"artifact_type": null,
"importpath": "github.com/aws-cloudformation/aws-cloudformation-resource-providers-aps/aws-aps-rulegroupsnamespace",
"protocolVersion": "2.0.0",
"pluginVersion": "2.0.0"
"pluginVersion": "2.0.4"
}
}
8 changes: 7 additions & 1 deletion aws-aps-rulegroupsnamespace/aws-aps-rulegroupsnamespace.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@
"readOnlyProperties": [
"/properties/Arn"
],
"taggable": true,
"tagging": {
"taggable": true,
"tagOnCreate": true,
"tagUpdatable": true,
"cloudFormationSystemTags": true,
"tagProperty": "/properties/Tags"
},
"primaryIdentifier": [
"/properties/Arn"
],
Expand Down
17 changes: 13 additions & 4 deletions aws-aps-rulegroupsnamespace/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
)

const defaultCallbackSeconds = 2
const defaultCallbackSeconds = 10

// Create handles the Create event from the Cloudformation service.
func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) {
Expand Down Expand Up @@ -41,11 +41,15 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
if err != nil {
return internal.NewFailedEvent(err)
}
systemTags := internal.ToAWSStringMap(req.RequestContext.SystemTags)
tags := tagsToStringMap(currentModel.Tags)
internal.MergeMaps(systemTags, tags)

resp, err := client.CreateRuleGroupsNamespace(&prometheusservice.CreateRuleGroupsNamespaceInput{
WorkspaceId: aws.String(workspaceID),
Name: currentModel.Name,
Data: []byte(*currentModel.Data),
Tags: tagsToStringMap(currentModel.Tags),
Tags: tags,
})
if err != nil {
return internal.NewFailedEvent(err)
Expand Down Expand Up @@ -117,7 +121,12 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
}, nil
}

toAdd, toRemove := internal.StringMapDifference(tagsToStringMap(currentModel.Tags), tagsToStringMap(prevModel.Tags))
currentModelTags := tagsToStringMap(currentModel.Tags)
systemTags := internal.ToAWSStringMap(req.RequestContext.SystemTags)

internal.MergeMaps(systemTags, currentModelTags)

toAdd, toRemove := internal.StringMapDifference(currentModelTags, tagsToStringMap(prevModel.Tags))
if len(toRemove) > 0 {
_, err = client.UntagResource(&prometheusservice.UntagResourceInput{
ResourceArn: currentModel.Arn,
Expand Down Expand Up @@ -291,7 +300,7 @@ func buildCallbackContext(model *Model) map[string]interface{} {
}

func stringMapToTags(m map[string]*string) []Tag {
res := []Tag{}
res := make([]Tag, 0)
for key, val := range m {
res = append(res, Tag{
Key: aws.String(key),
Expand Down
13 changes: 10 additions & 3 deletions aws-aps-rulegroupsnamespace/inputs/inputs_1_create.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"Workspace": "{{AlertManagerDefinitionTestWorkspaceArn}}",
"Name": "CustomerObsession",
"Data": "groups:\n - name: example\n interval: 5m\n rules:\n - alert: foo\n expr: job:request_latency_seconds:mean5m{job=\"myjob\"} > 0.5\n for: 10m\n labels:\n severity: page\n annotations:\n summary: High request latency\n"
"Workspace": "{{AlertManagerDefinitionTestWorkspaceArn}}",
"Name": "CustomerObsession",
"Data": "groups:\n - name: example\n interval: 5m\n rules:\n - alert: foo\n expr: job:request_latency_seconds:mean5m{job=\"myjob\"} > 0.5\n for: 10m\n labels:\n severity: page\n annotations:\n summary: High request latency\n",
"Tags": [
{
"Key": "FavoriteDrink",
"Value": "Latte"
}
]
}

245 changes: 136 additions & 109 deletions aws-aps-workspace/aws-aps-workspace.json
Original file line number Diff line number Diff line change
@@ -1,117 +1,144 @@
{
"typeName": "AWS::APS::Workspace",
"description": "Resource Type definition for AWS::APS::Workspace",
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-rpdk.git",
"definitions": {
"Tag": {
"description": "A key-value pair to associate with a resource.",
"type": "object",
"properties": {
"Key": {
"type": "string",
"description": "The key name of the tag. You can specify a value that is 1 to 128 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
"minLength": 1,
"maxLength": 128
"typeName": "AWS::APS::Workspace",
"description": "Resource Type definition for AWS::APS::Workspace",
"sourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-rpdk.git",
"definitions": {
"Tag": {
"description": "A key-value pair to associate with a resource.",
"type": "object",
"properties": {
"Key": {
"type": "string",
"description": "The key name of the tag. You can specify a value that is 1 to 128 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
"minLength": 1,
"maxLength": 128
},
"Value": {
"type": "string",
"description": "The value for the tag. You can specify a value that is 0 to 256 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
"minLength": 0,
"maxLength": 256
}
},
"required": [
"Key",
"Value"
],
"additionalProperties": false
},
"Value": {
"type": "string",
"description": "The value for the tag. You can specify a value that is 0 to 256 Unicode characters in length and cannot be prefixed with aws:. You can use any of the following characters: the set of Unicode letters, digits, whitespace, _, ., /, =, +, and -.",
"minLength": 0,
"maxLength": 256
"LoggingConfiguration": {
"description": "Logging configuration",
"type": "object",
"properties": {
"LogGroupArn": {
"description": "CloudWatch log group ARN",
"type": "string",
"minLength": 0,
"maxLength": 512
}
},
"additionalProperties": false
}
},
"required": [
"Key",
"Value"
],
"additionalProperties": false
}
},
"properties": {
"WorkspaceId": {
"description": "Required to identify a specific APS Workspace.",
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{1,99}\\Z",
"minLength": 1,
"maxLength": 100
},
"Alias": {
"description": "AMP Workspace alias.",
"type": "string",
"minLength": 0,
"maxLength": 100
},
"Arn": {
"description": "Workspace arn.",
"type": "string",
"pattern": "^arn:\b(aws|aws-us-gov|aws-cn)\b:aps:[a-z0-9-]+:[0-9]+:workspace/[a-zA-Z0-9-]+$",
"minLength": 1,
"maxLength": 128
},
"AlertManagerDefinition": {
"description": "The AMP Workspace alert manager definition data",
"type": "string"
},
"PrometheusEndpoint": {
"description": "AMP Workspace prometheus endpoint",
"type": "string"
},
"Tags": {
"description": "An array of key-value pairs to apply to this resource.",
"type": "array",
"uniqueItems": true,
"insertionOrder": false,
"items": {
"$ref": "#/definitions/Tag"
}
}
},
"additionalProperties": false,
"required": [],
"readOnlyProperties": [
"/properties/WorkspaceId",
"/properties/Arn",
"/properties/PrometheusEndpoint"
],
"taggable": true,
"primaryIdentifier": [
"/properties/Arn"
],
"handlers": {
"create": {
"permissions": [
"aps:CreateWorkspace",
"aps:TagResource",
"aps:CreateAlertManagerDefinition"
]
},
"read": {
"permissions": [
"aps:DescribeWorkspace",
"aps:ListTagsForResource",
"aps:DescribeAlertManagerDefinition"
]
},
"update": {
"permissions": [
"aps:UpdateWorkspaceAlias",
"aps:TagResource",
"aps:UntagResource",
"aps:ListTagsForResource",
"aps:PutAlertManagerDefinition"
]
"properties": {
"WorkspaceId": {
"description": "Required to identify a specific APS Workspace.",
"type": "string",
"pattern": "^[a-zA-Z0-9][a-zA-Z0-9_-]{1,99}\\Z",
"minLength": 1,
"maxLength": 100
},
"Alias": {
"description": "AMP Workspace alias.",
"type": "string",
"minLength": 0,
"maxLength": 100
},
"Arn": {
"description": "Workspace arn.",
"type": "string",
"pattern": "^arn:\b(aws|aws-us-gov|aws-cn)\b:aps:[a-z0-9-]+:[0-9]+:workspace/[a-zA-Z0-9-]+$",
"minLength": 1,
"maxLength": 128
},
"AlertManagerDefinition": {
"description": "The AMP Workspace alert manager definition data",
"type": "string"
},
"PrometheusEndpoint": {
"description": "AMP Workspace prometheus endpoint",
"type": "string"
},
"LoggingConfiguration": {
"$ref": "#/definitions/LoggingConfiguration"
},
"Tags": {
"description": "An array of key-value pairs to apply to this resource.",
"type": "array",
"uniqueItems": true,
"insertionOrder": false,
"items": {
"$ref": "#/definitions/Tag"
}
}
},
"delete": {
"permissions": [
"aps:DeleteWorkspace",
"aps:DeleteAlertManagerDefinition"
]
"additionalProperties": false,
"required": [],
"readOnlyProperties": [
"/properties/WorkspaceId",
"/properties/Arn",
"/properties/PrometheusEndpoint"
],
"tagging": {
"taggable": true,
"tagOnCreate": true,
"tagUpdatable": true,
"cloudFormationSystemTags": true,
"tagProperty": "/properties/Tags"
},
"list": {
"permissions": [
"aps:ListWorkspaces",
"aps:ListTagsForResource"
]
"primaryIdentifier": [
"/properties/Arn"
],
"handlers": {
"create": {
"permissions": [
"aps:CreateWorkspace",
"aps:TagResource",
"aps:CreateAlertManagerDefinition",
"aps:DescribeAlertManagerDefinition",
"aps:CreateLoggingConfiguration"
]
},
"read": {
"permissions": [
"aps:DescribeWorkspace",
"aps:ListTagsForResource",
"aps:DescribeAlertManagerDefinition",
"aps:DescribeLoggingConfiguration"
]
},
"update": {
"permissions": [
"aps:UpdateWorkspaceAlias",
"aps:TagResource",
"aps:UntagResource",
"aps:ListTagsForResource",
"aps:PutAlertManagerDefinition",
"aps:UpdateLoggingConfiguration"
]
},
"delete": {
"permissions": [
"aps:DeleteWorkspace",
"aps:DeleteAlertManagerDefinition",
"aps:DeleteLoggingConfiguration"
]
},
"list": {
"permissions": [
"aps:ListWorkspaces",
"aps:ListTagsForResource"
]
}
}
}
}
Loading