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

fix: compatiblity mode for v0 tagging behavior #33

Merged
merged 5 commits into from
Nov 20, 2024
Merged
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
3 changes: 3 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ new TextFile(project, 'sonar-project.properties', {
'sonar.sources=./src',
'sonar.tests=./test',
'sonar.test.inclusions=**/*.test.*',
'sonar.issue.ignore.multicriteria=e1',
aripalo marked this conversation as resolved.
Show resolved Hide resolved
'sonar.issue.ignore.multicriteria.e1.ruleKey=typescript:S1874',
'sonar.issue.ignore.multicriteria.e1.resourceKey=src/smartstack/tags/*.ts',
],
});

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,21 @@ Generally speaking you would be most interested in the following:
- AccountContext (AC)
- EnvironmentContext (EC)
- Name / UrlName / PathName

## Migration

### v0 to v1

#### Tagging behavior

Due to a bug in `v0`, the `Contact` and `Organization` tags were NOT applied as they should have. This means that by default, upgrading from v0→v1 introduces CloudFormation diff. Basically adding the `Contact` and `Organization` tags to all resources. This should be safe operation, but we allow disabling it via a feature flag (note that `Contact` and `Organization` tags will most likely be enforced in future `v2`).

```diff
// cdk.json
{
"context": {
// existing context keys
+ "@alma-cdk/project:compatibility:v0:tags": true
},
}
```
5 changes: 4 additions & 1 deletion sonar-project.properties

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

34 changes: 34 additions & 0 deletions src/smartstack/tags/checks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useCompatibilityV0Tags, useLegacyTags } from './checks';
import { TestableResource } from './test-helpers/TestableResource';

describe('useLegacyTags', () => {
test('returns false if the context key is not set', () => {
const scope = new TestableResource();
expect(useLegacyTags(scope)).toBe(false);
});

test('returns true if the context key is set', () => {
const scope = new TestableResource({
context: {
'@alma-cdk/project:legacyTags': true,
},
});
expect(useLegacyTags(scope)).toBe(true);
});
});

describe('useCompatibilityV0Tags', () => {
test('returns false if the context key is not set', () => {
const scope = new TestableResource();
expect(useCompatibilityV0Tags(scope)).toBe(false);
});

test('returns true if the context key is set', () => {
const scope = new TestableResource({
context: {
'@alma-cdk/project:compatibility:v0:tags': true,
},
});
expect(useCompatibilityV0Tags(scope)).toBe(true);
});
});
19 changes: 19 additions & 0 deletions src/smartstack/tags/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,26 @@ export function hasEnvironment(values: Values): boolean {
return isNonEmptyString(values.environmentType);
}

/**
* Enforces usage of https://github.com/almamedia/alma-cdk-jsii-tag-and-name
* (for AWS CDK v1) compatible tagging behavior.
*
* @deprecated This behavior is not encouraged and will be removed in v2. Additionally according to GitHub search, this is not used anymore.
*/
export function useLegacyTags(scope: Construct): boolean {
const contextKey = '@alma-cdk/project:legacyTags';
return scope.node.tryGetContext(contextKey) === true;
}

/**
* Compatibility flag for v0 tagging behavior.
* Due to a bug in v0, the `Contact` and `Organization` tags were NOT applied as they should have.
* This flag can be used to enforce behavior that matches v0 implementation:
* I.e. `Contact` and `Organization` tags are NOT applied.
*
* @deprecated This behavior is not encouraged and will be removed in v2.
*/
export function useCompatibilityV0Tags(scope: Construct): boolean {
const contextKey = '@alma-cdk/project:compatibility:v0:tags';
return scope.node.tryGetContext(contextKey) === true;
}
aripalo marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading