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

feat: provide tags on create app #6381

Merged
merged 1 commit into from
Jan 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 15 additions & 11 deletions packages/amplify-e2e-tests/src/__tests__/tags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import {
createNewProjectDir,
deleteProject,
deleteProjectDir,
amplifyPushWithoutCodegen,
getProjectMeta,
getProjectTags,
describeCloudFormationStack,
addDEVHosting,
} from 'amplify-e2e-core';
import _ from 'lodash';
import { Amplify } from 'aws-sdk';

describe('generated tags test', () => {
let projRoot: string;
Expand All @@ -23,22 +23,26 @@ describe('generated tags test', () => {
});

it('should compare the nested stack tags key with the tags.json file and return true', async () => {
const projName = 'tagsTest';
const envName = 'devtag';
await initJSProjectWithProfile(projRoot, { name: projName, envName });
await addDEVHosting(projRoot);
await amplifyPushWithoutCodegen(projRoot);
await initJSProjectWithProfile(projRoot, { disableAmplifyAppCreation: false });

// This block of code gets the necessary info to compare the values of both the local tags from the JSON file and tags on the stack
const amplifyMeta = getProjectMeta(projRoot);
const meta = amplifyMeta.providers.awscloudformation;
const rootStackInfo = await describeCloudFormationStack(meta.StackName, meta.Region);
const localTags = getProjectTags(projRoot);

// Currently only checks to make sure that thhe pushed tags have the same amount and name of keys than the ones added locally on the tags.json file
expect(checkEquality(localTags, rootStackInfo.Tags)).toBe(true);
expect(rootStackInfo.Tags.filter(r => r.Key === 'user:Stack')[0].Value).toEqual(envName);
expect(rootStackInfo.Tags.filter(r => r.Key === 'user:Application')[0].Value).toEqual(projName);
expect(checkEquality(localTags, rootStackInfo.Tags)).toBeTruthy();
const { AmplifyAppId, Region } = meta;
const amplify = new Amplify({ region: Region });
const amplifyApp = await amplify.getApp({ appId: AmplifyAppId }).promise();
const tagMap = amplifyApp.app.tags;
const amplifyTags = Object.keys(tagMap).map(key => {
return {
Key: key,
Value: tagMap[key],
};
});
expect(checkEquality(localTags, amplifyTags)).toBeTruthy();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function init(amplifyServiceParams) {
let deploymentBucketName = `${stackName}-deployment`;

const amplifyClient = await getConfiguredAmplifyClient(context, awsConfig);
logger('init.getConfiguredAmplifyClient', [!!amplifyClient])();
if (!amplifyClient) {
// This happens when the Amplify service is not available in the region
return {
Expand All @@ -28,6 +29,7 @@ async function init(amplifyServiceParams) {
}

const hasPermission = await checkAmplifyServiceIAMPermission(context, amplifyClient);
logger('init.checkAmplifyServiceIAMPermission', [hasPermission])();
if (!hasPermission) {
return {
amplifyAppId,
Expand Down Expand Up @@ -115,13 +117,18 @@ async function init(amplifyServiceParams) {
}

if (!amplifyAppId) {
logger('in if', [amplifyAppId])();

const createAppParams = {
name: projectName,
tags: getTagMap(context),
environmentVariables: { _LIVE_PACKAGE_UPDATES: '[{"pkg":"@aws-amplify/cli","type":"npm","version":"latest"}]' },
};
logger('after create params', [amplifyAppId])();
const log = logger('init.amplifyClient.createApp', [createAppParams]);

try {
logger('amplifyAppCreationEnabled', [amplifyAppCreationEnabled()])();
if (amplifyAppCreationEnabled()) {
log();
const createAppResponse = await amplifyClient.createApp(createAppParams).promise();
Expand Down Expand Up @@ -202,6 +209,14 @@ async function init(amplifyServiceParams) {
deploymentBucketName,
};
}
function getTagMap(context) {
const tags = context.amplify.getTags(context);
const tagMap = tags.reduce((obj, tag) => {
obj[tag.Key] = tag.Value;
return obj;
}, {});
return tagMap;
}

async function deleteEnv(context, envName, awsConfig) {
if (stateManager.teamProviderInfoExists()) {
Expand Down Expand Up @@ -291,6 +306,7 @@ async function postPushCheck(context) {
if (!amplifyAppId) {
const createAppParams = {
name: projectConfig.projectName,
tags: getTagMap(context),
environmentVariables: { _LIVE_PACKAGE_UPDATES: '[{"pkg":"@aws-amplify/cli","type":"npm","version":"latest"}]' },
};
const log = logger('postPushCheck.amplifyClient.createApp', [createAppParams]);
Expand Down