-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat(stack): GuStack accepts Stack value as prop #243
Conversation
As we look to reduce the number of parameters requiring manual updating and maintaining in CFN, this allows library users to hard-code stack and stage variables so we can reason with their values in other parts of the codebase
I think we'd always want I also wonder if it would be simpler to remove the |
Agreed, but would it not be nice to make it possible to have it defined at declaration? I agree that for the Guardian, we would almost never use this, but I can envision certain circumstances where maybe an external user might want to create very specific stacks per stage, and have them hard-coded in the file.
Yeah, I think it would be better to remove the parameter altogether. However, would this cause a breaking change for stacks that have it as a parameter currently? If so, I would maybe suggest allowing it for now then maybe removing it later, although it could be better to just make the necessary changes in the stacks and make this our best practice. I think it should be fine to remove parameters, whereas adding one causes issues iirc. |
Default values can help alleviate this pain, I think? Whilst we should consider external use, I'm not sure we should be overly concerned with those use cases at the moment. That is, I think we should build for our internal use to make adoption easy and once the library is mature, we can focus on external parties. Maybe we can add a TODO to remind us that this feature might be tricky for external users?
Semver releases solve this 😉. We also don't have too many stacks on CDK so should be easy to manage this change?
Great point! Maybe this warrants an ADR? |
Since stack is not a sensitive object and would be stable between stages, we can state it explicitly in the CDK declaration BREAKING CHANGE: This would require existing stacks to declare the stack name in their stacks (we need better terms), but I think the removal of a CFN parameter should be safe
You're right, that makes sense. I've made a change for the stage value to be only a parameter, while the stack one should only be passed in. It makes sense, and is in line with our best practices.
Sure! How do we go about that again? |
src/constructs/core/stack.test.ts
Outdated
const stack = simpleGuStackForTesting(); | ||
it("requires passing the stack value as props", function () { | ||
const stack = simpleGuStackForTesting({ stack: "some-stack" }); | ||
expect(stack.stack).toEqual("some-stack"); | ||
|
||
const json = SynthUtils.toCloudFormation(stack) as SynthedStack; | ||
|
||
expect(json.Parameters).toEqual({ |
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.
I don't think we need the expect(json.Parameters)
assertion here, as it's tested as part of "should have a stage parameter"
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.
This looks good to me. I've made one suggestion which allows us to simplify the tests slightly. Feel free to merge this once that's been tidied up 👍
What does this change?
As we look to reduce the number of parameters requiring manual updating and maintaining in CFN, this allows library users to hard-code stack and stage variables so we can reason with their values in other parts of the codebase.
If a user would like to avoid having the stack and stage as tokens (which later gets resolved at deployment by writing the values in the CFN UI), you could now simply state these values in the stack declaration:
Since we don't often (or ever) write stage-specific CDK declarations, I expect the
stage
prop will not be used often. However, being able to provide thestack
as a hardcoded string I think provides value in a) having more configuration explicit in the repository, b) remove a parameter from CFN UI and c) remove a tiny bit of cognitive load in the processDoes this change require changes to existing projects or CDK CLI?
No, this shouldn't affect existing projects.
How to test
./script/test
from the root of the repository.How can we measure success?
More projects can be explicit about what stack (and perhaps rarely stage) the CDK stacks belong to.