diff --git a/.changeset/angry-moles-flash.md b/.changeset/angry-moles-flash.md new file mode 100644 index 000000000..a2bded41d --- /dev/null +++ b/.changeset/angry-moles-flash.md @@ -0,0 +1,5 @@ +--- +'@roadiehq/catalog-backend-module-aws': patch +--- + +Add test, debug logging and RDS support for ownerTag mapping diff --git a/plugins/backend/catalog-backend-module-aws/src/providers/AWSLambdaFunctionProvider.test.ts b/plugins/backend/catalog-backend-module-aws/src/providers/AWSLambdaFunctionProvider.test.ts index 88023ff07..bbfa8ebaf 100644 --- a/plugins/backend/catalog-backend-module-aws/src/providers/AWSLambdaFunctionProvider.test.ts +++ b/plugins/backend/catalog-backend-module-aws/src/providers/AWSLambdaFunctionProvider.test.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { Lambda, ListFunctionsCommand } from '@aws-sdk/client-lambda'; +import { + Lambda, + ListFunctionsCommand, + ListTagsCommand, +} from '@aws-sdk/client-lambda'; import { STS, GetCallerIdentityCommand } from '@aws-sdk/client-sts'; import { mockClient } from 'aws-sdk-client-mock'; @@ -31,6 +35,7 @@ const logger = createLogger({ }); describe('AWSLambdaFunctionProvider', () => { + const ownerTag = 'Owner-test'; const config = new ConfigReader({ accountId: '123456789012', roleName: 'arn:aws:iam::123456789012:role/role1', @@ -64,6 +69,7 @@ describe('AWSLambdaFunctionProvider', () => { }); describe('where there are is a function', () => { + const owner = 'engineering'; beforeEach(() => { lambda.on(ListFunctionsCommand).resolves({ Functions: [ @@ -86,6 +92,12 @@ describe('AWSLambdaFunctionProvider', () => { }, ], }); + lambda.on(ListTagsCommand).resolves({ + Tags: { + [ownerTag]: owner, + owner: 'wrong', + }, + }); }); it('creates aws functions', async () => { @@ -130,6 +142,32 @@ describe('AWSLambdaFunctionProvider', () => { }); }); + it('maps owner from custom tag mapping', async () => { + const entityProviderConnection: EntityProviderConnection = { + applyMutation: jest.fn(), + refresh: jest.fn(), + }; + const provider = AWSLambdaFunctionProvider.fromConfig(config, { + logger, + ownerTag, + }); + provider.connect(entityProviderConnection); + await provider.run(); + expect(entityProviderConnection.applyMutation).toHaveBeenCalledWith({ + type: 'full', + entities: [ + expect.objectContaining({ + entity: expect.objectContaining({ + kind: 'Resource', + spec: expect.objectContaining({ + owner: owner, + }), + }), + }), + ], + }); + }); + it('is able to use dynamic config', async () => { const entityProviderConnection: EntityProviderConnection = { applyMutation: jest.fn(), diff --git a/plugins/backend/catalog-backend-module-aws/src/providers/AWSLambdaFunctionProvider.ts b/plugins/backend/catalog-backend-module-aws/src/providers/AWSLambdaFunctionProvider.ts index 74594bda3..19b5d0df8 100644 --- a/plugins/backend/catalog-backend-module-aws/src/providers/AWSLambdaFunctionProvider.ts +++ b/plugins/backend/catalog-backend-module-aws/src/providers/AWSLambdaFunctionProvider.ts @@ -128,6 +128,14 @@ export class AWSLambdaFunctionProvider extends AWSEntityProvider { if (lambdaFunction.Role) { annotations[ANNOTATION_AWS_IAM_ROLE_ARN] = lambdaFunction.Role; } + const owner = ownerFromTags(tags, this.getOwnerTag(), groups); + const relationships = relationshipsFromTags(tags); + this.logger.debug( + `Setting Lambda owner from tags as ${owner} and relationships of ${JSON.stringify( + relationships, + )}`, + ); + lambdaComponents.push({ kind: 'Resource', apiVersion: 'backstage.io/v1beta1', @@ -144,8 +152,8 @@ export class AWSLambdaFunctionProvider extends AWSEntityProvider { labels: this.labelsFromTags(tags), }, spec: { - owner: ownerFromTags(tags, this.getOwnerTag(), groups), - ...relationshipsFromTags(tags), + owner: owner, + ...relationships, type: 'lambda-function', }, }); diff --git a/plugins/backend/catalog-backend-module-aws/src/providers/AWSRDSProvider.ts b/plugins/backend/catalog-backend-module-aws/src/providers/AWSRDSProvider.ts index 34c19d0ca..3ddbac677 100644 --- a/plugins/backend/catalog-backend-module-aws/src/providers/AWSRDSProvider.ts +++ b/plugins/backend/catalog-backend-module-aws/src/providers/AWSRDSProvider.ts @@ -43,6 +43,7 @@ export class AWSRDSProvider extends AWSEntityProvider { providerId?: string; useTemporaryCredentials?: boolean; labelValueMapper?: LabelValueMapper; + ownerTag?: string; }, ) { const accountId = config.getString('accountId');