-
Notifications
You must be signed in to change notification settings - Fork 6
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
refactor(GuLogShippingPolicy)!: make GuLogShippingPolicy a singleton #337
Conversation
This parameter is written as a singleton as we only ever want one per stack - if there are multiple apps defined in the stack, they'll all share the same parameter (as opposed to the AMI parameter which is app specific).
…ter` parameter Also extend `GuAllowPolicy` to stay DRY.
This policy is now a singleton as we only ever want one per stack. If there are multiple roles defined in this stack that require log shipping permissions, a single policy will be defined and attached to the roles. This DRYness helps keep within the file size limits of cloudformation.
@@ -4,10 +4,10 @@ import type { Stack } from "@aws-cdk/core"; | |||
import { Tags } from "@aws-cdk/core"; | |||
|
|||
// IAM Policies need to be attached to a role, group or user to be created in a stack | |||
export const attachPolicyToTestRole = (stack: Stack, policy: Policy, app: string = "testing"): void => { | |||
const role = new Role(stack, "TestRole", { | |||
export const attachPolicyToTestRole = (stack: Stack, policy: Policy, id: string = "TestRole"): void => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value of the app
param was never overridden, so (safely) removed it.
Type: "AWS::SSM::Parameter::Value<String>", | ||
Default: "/account/services/logging.stream.name", | ||
Description: "SSM parameter containing the Name (not ARN) on the kinesis stream", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Clear changes that make sense and thanks for the PR making it clear how to understand and review this!
🎉 This PR is included in version 4.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Following #337 and part of a bigger bit of work in #332, this makes `GuDistributionBucketParameter` a singleton as we only ever want one of them in a stack. BREAKING CHANGE: * The removal of the static `parameterName` field means `GuDistributionBucketParameter.parameterName` becomes `GuDistributionBucketParameter.getInstance(stack).id`
A `GuInstanceRole` provides the basic permissions needed by EC2, it grants access to: * SSM * Describing tags * Writing to kinesis for log shipping #326 started the work to support the declaration of multiple apps in a stack, where an app is a collection of ASG, LB etc. However, when actually attempting to use the updated constructs in reality, the synth step failed due to multiple constructs using the same ID. This change follows #341 and #337 and converts `GuSSMRunCommandPolicy` and `GuDescribeEC2Policy` to singletons. This means these policies will only get created once regardless of how many roles use them - there will be one policy with multiple roles attached to it. This helps keep the stack DRY and also reduces the chance of reaching the max file size limits of cloudformation. The commits have been crafted to be standalone, reviewing them one by one might make the overall review easier. Requires #341. BREAKING CHANGE: * `GuSSMRunCommandPolicy` and `GuDescribeEC2Policy` can no longer be directly instantiated
What does this change?
This is ultimately part of #332.
This policy is now a singleton as we only ever want one per stack. If there are multiple roles defined in this stack that require log shipping permissions, a single policy will be defined and attached to the roles.
This DRYness helps keep within the file size limits of cloudformation too.
Also included in this change is a new
GuLoggingStreamNameParameter
, also written as a singleton for the same reasons.To make the review easier, each commit can be read in sequence as they have been crafted to tell the story.
Usage hasn't really changed as this policy will never really be used by consumer stacks as they'l be using
GuInstanceRole
instead, which adds this policy by default. However, usage looks roughly like this:It's worth noting that #92 was a naive implementation of singleton parameters and this new style removes the need to have the
getParam
helper function on theGuStack
.BREAKING CHANGE:
GuLogShippingPolicy
has changed. It is now a singleton and direct instantiation is not possible.Does this change require changes to existing projects or CDK CLI?
Yes. They'll need a version bump by as
GuLogShippingPolicy
is provided through theGuInstanceRole
, this should be a no-op.How to test
See updated and new tests. Either by running them or observing CI.
How can we measure success?
A much simpler API and ground work for supporting multiple apps (for example a backend api and frontend web app microservice) within a single stack.
Have we considered potential risks?
n/a