Skip to content

Commit c2ff542

Browse files
authored
Add support for customizing tag keys (#1326)
1 parent 22e65d7 commit c2ff542

File tree

8 files changed

+63
-5
lines changed

8 files changed

+63
-5
lines changed

docs/en/DEPLOY_OPTION.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1808,14 +1808,15 @@ EventBridge rules are used for scheduling, and Step Functions for process contro
18081808
18091809
### How to Set Tags
18101810

1811-
GenU supports tags for cost management and other purposes. The key name of the tag is automatically set to `GenU` `. Here are examples of how to set them:
1811+
GenU supports tags for cost management and other purposes. By default, the key name of the tag is set to `GenU`, but you can use a custom tag key by specifying `tagKey`. Here are examples of how to set them:
18121812

18131813
Setting in `cdk.json`:
18141814

18151815
```json
18161816
// cdk.json
18171817
...
18181818
"context": {
1819+
"tagKey": "MyProject", // Custom tag key (optional, default is "GenU")
18191820
"tagValue": "dev",
18201821
...
18211822
```
@@ -1824,6 +1825,7 @@ Setting in `parameter.ts`:
18241825

18251826
```typescript
18261827
...
1828+
tagKey: "MyProject", // Custom tag key (optional, default is "GenU")
18271829
tagValue: "dev",
18281830
...
18291831
```

docs/ja/DEPLOY_OPTION.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ Kendraのインデックスが削除されても、RAG機能はオンのまま
18151815
18161816
### タグを設定する方法
18171817

1818-
GenU ではコスト管理等に使うためのタグをサポートしています。タグのキー名には、自動で `GenU` `が設定されます
1818+
GenU ではコスト管理等に使うためのタグをサポートしています。デフォルトでは、タグのキー名に `GenU` が設定されますが、`tagKey` を指定することでカスタムのタグキーを使用できます
18191819
以下に設定例を示します。
18201820

18211821
`cdk.json` での設定方法
@@ -1824,6 +1824,7 @@ GenU ではコスト管理等に使うためのタグをサポートしていま
18241824
// cdk.json
18251825
...
18261826
"context": {
1827+
"tagKey": "MyProject", // カスタムのタグキー(省略可能、デフォルトは "GenU")
18271828
"tagValue": "dev",
18281829
...
18291830
```
@@ -1832,6 +1833,7 @@ GenU ではコスト管理等に使うためのタグをサポートしていま
18321833

18331834
```typescript
18341835
...
1836+
tagKey: "MyProject", // カスタムのタグキー(省略可能、デフォルトは "GenU")
18351837
tagValue: "dev",
18361838
...
18371839
```

docs/ko/DEPLOY_OPTION.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,14 +1817,15 @@ Kendra 인덱스가 삭제되어도 RAG 기능은 계속 켜져 있습니다.
18171817
18181818
### 태그 설정 방법
18191819

1820-
GenU는 비용 관리 및 기타 목적을 위한 태그를 지원합니다. 태그의 키 이름은 자동으로 `GenU`설정됩니다. 설정 방법의 예시는 다음과 같습니다:
1820+
GenU는 비용 관리 및 기타 목적을 위한 태그를 지원합니다. 기본적으로 태그의 키 이름은 `GenU`설정되지만, `tagKey`를 지정하여 사용자 정의 태그 키를 사용할 수 있습니다. 설정 방법의 예시는 다음과 같습니다:
18211821

18221822
`cdk.json`에서 설정:
18231823

18241824
```json
18251825
// cdk.json
18261826
...
18271827
"context": {
1828+
"tagKey": "MyProject", // 사용자 정의 태그 키 (선택사항, 기본값은 "GenU")
18281829
"tagValue": "dev",
18291830
...
18301831
```
@@ -1833,6 +1834,7 @@ GenU는 비용 관리 및 기타 목적을 위한 태그를 지원합니다. 태
18331834

18341835
```typescript
18351836
...
1837+
tagKey: "MyProject", // 사용자 정의 태그 키 (선택사항, 기본값은 "GenU")
18361838
tagValue: "dev",
18371839
...
18381840
```

packages/cdk/bin/generative-ai-use-cases.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { TAG_KEY } from '../consts';
88
const app = new cdk.App();
99
const params = getParams(app);
1010
if (params.tagValue) {
11-
cdk.Tags.of(app).add(TAG_KEY, params.tagValue, {
11+
const tagKey = params.tagKey || TAG_KEY;
12+
cdk.Tags.of(app).add(tagKey, params.tagValue, {
1213
// Exclude OpenSearchServerless Collection from tagging
1314
excludeResourceTypes: ['AWS::OpenSearchServerless::Collection'],
1415
});

packages/cdk/cdk.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"context": {
1818
"env": "",
19+
"tagKey": null,
1920
"tagValue": null,
2021
"ragEnabled": false,
2122
"kendraIndexArn": null,

packages/cdk/lib/rag-knowledge-base-stack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export class RagKnowledgeBaseStack extends Stack {
145145
ragKnowledgeBaseAdvancedParsingModelId,
146146
ragKnowledgeBaseBinaryVector,
147147
crossAccountBedrockRoleArn,
148+
tagKey,
148149
tagValue,
149150
} = props.params;
150151

@@ -312,7 +313,7 @@ export class RagKnowledgeBaseStack extends Stack {
312313
resourceType: 'Custom::ApplyTags',
313314
properties: {
314315
tag: {
315-
key: TAG_KEY,
316+
key: tagKey || TAG_KEY,
316317
value: tagValue || '', // Pass empty string when tagValue is unset
317318
},
318319
collectionId: collection.ref,

packages/cdk/lib/stack-input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ const baseStackInputSchema = z.object({
185185
// Dashboard
186186
dashboard: z.boolean().default(false),
187187
// Tag
188+
tagKey: z.string().nullish(),
188189
tagValue: z.string().nullish(),
189190
// Closed network
190191
closedNetworkMode: z.boolean().default(false),

packages/cdk/test/generative-ai-use-cases.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ describe('GenerativeAiUseCases', () => {
6262
guardrailEnabled: true,
6363
crossAccountBedrockRoleArn: '',
6464
useCaseBuilderEnabled: true,
65+
tagKey: null,
66+
tagValue: null,
6567
};
6668

6769
test('matches the snapshot', () => {
@@ -160,4 +162,50 @@ describe('GenerativeAiUseCases', () => {
160162
expect(generativeAiUseCasesTemplate.toJSON()).toMatchSnapshot();
161163
expect(dashboardTemplate.toJSON()).toMatchSnapshot();
162164
});
165+
166+
test('tagKey functionality', () => {
167+
// Test with custom tagKey
168+
const appWithCustomTag = new cdk.App();
169+
const paramsWithCustomTag = processedStackInputSchema.parse({
170+
...stackInput,
171+
tagKey: 'CustomTag',
172+
tagValue: 'custom-value',
173+
});
174+
175+
const stacksWithCustomTag = createStacks(
176+
appWithCustomTag,
177+
paramsWithCustomTag
178+
);
179+
180+
// Test without tagKey (should use default)
181+
const appWithoutTagKey = new cdk.App();
182+
const paramsWithoutTagKey = processedStackInputSchema.parse({
183+
...stackInput,
184+
tagKey: null,
185+
tagValue: 'default-value',
186+
});
187+
188+
const stacksWithoutTagKey = createStacks(
189+
appWithoutTagKey,
190+
paramsWithoutTagKey
191+
);
192+
193+
// Assert that both scenarios create stacks successfully
194+
expect(stacksWithCustomTag.generativeAiUseCasesStack).toBeDefined();
195+
expect(stacksWithoutTagKey.generativeAiUseCasesStack).toBeDefined();
196+
197+
// Test that RagKnowledgeBaseStack is created properly with custom tagKey
198+
if (stacksWithCustomTag.ragKnowledgeBaseStack) {
199+
const customTagTemplate = Template.fromStack(
200+
stacksWithCustomTag.ragKnowledgeBaseStack
201+
);
202+
// Check that custom resource uses the custom tag key
203+
customTagTemplate.hasResourceProperties('Custom::ApplyTags', {
204+
tag: {
205+
key: 'CustomTag',
206+
value: 'custom-value',
207+
},
208+
});
209+
}
210+
});
163211
});

0 commit comments

Comments
 (0)