Skip to content

Commit

Permalink
Add gh action files
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Nguyen committed Sep 9, 2021
1 parent 212046a commit c7fc828
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/deploy-integ-appstream-egress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ jobs:
run: |
cp ./main/end-to-end-tests/e2eGitHubConfig.AppStreamEgress.yml ./main/config/settings/${STAGE_NAME}.yml
./scripts/environment-deploy.sh ${STAGE_NAME}
infrastructure-test:
name: Infrastructure test
runs-on: ubuntu-18.04
# needs: deploy
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 12
- name: Install pnpm and system libraries
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
working-directory: main/infrastructure-tests
- name: Run infrastructure tests
run: pnpm run testAppStreamEgressEnabled -- --stage=github
working-directory: ./main/infrastructure-tests
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_APPSTREAM_EGRESS }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_APPSTREAM_EGRESS }}
INFRA_TESTS_HOSTING_ACCOUNT_ID: ${{ secrets.INFRA_TESTS_HOSTING_ACCOUNT_ID }}
INFRA_TESTS_HOSTING_ACCOUNT_STACK_NAME: ${{ secrets.INFRA_TESTS_HOSTING_ACCOUNT_STACK_NAME }}
integration-test:
name: Integration test
runs-on: ubuntu-18.04
Expand Down
1 change: 0 additions & 1 deletion main/infrastructure-tests/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Infrastructure Tests for SWB

This test suite checks if the hosting account Cloudformation stack is set up with the correct security settings. Tests were added
to ensure that if AppStream and Egress are enabled, the stack does not have subnets and security group with internet connectivity.

Expand Down
2 changes: 1 addition & 1 deletion main/infrastructure-tests/config/settings/example.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The AWS region where the service workbench application is deployed
awsRegion: us-east-1

# AWS profile to use for deployment. You must provide this value if isBuildServer = false
# AWS profile with permissions to the main account. Example: default
awsProfile:

# Make sure that the solutionName matches the one you are using in /main/config/settings
Expand Down
18 changes: 18 additions & 0 deletions main/infrastructure-tests/config/settings/github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# The AWS region where the service workbench application is deployed
awsRegion: eu-west-1

# AWS profile to use for deployment. You must provide this value if isBuildServer = false
awsProfile: default

# Make sure that the solutionName matches the one you are using in /main/config/settings
solutionName: sw

# Required. Usually, this is the same as the stage name that you used when you deployed the service
# workbench application
envName: thingut3

# Make sure that the envType matches the one you are using in /main/config/settings
envType: dev

# ExternalId set for the trust relationship of the assumed role in the hosting account. By default it's `workbench`
externalId: workbench
11 changes: 6 additions & 5 deletions main/infrastructure-tests/support/setupAws.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const AWS = require('aws-sdk');

const { getSettings } = require('./utilities');
// Setup AWS SDK to assume credentials of hosting account
async function setupAws() {
// eslint-disable-next-line no-undef
const { awsProfile, awsRegion, envName, externalId, hostingAccountId, hostingAccountStackName } = __settings__;

const { awsProfile, awsRegion, envName, externalId, hostingAccountId, hostingAccountStackName } = getSettings();
// Get main account credentials
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: awsProfile });
// For github actions the AWS creds are provided through environment variables, for local dev environments it's provided through awsProfile
if (awsProfile) {
AWS.config.credentials = new AWS.SharedIniFileCredentials({ profile: awsProfile });
}
AWS.config.region = awsRegion;

// Assume credentials of hosting account
Expand Down
19 changes: 18 additions & 1 deletion main/infrastructure-tests/support/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const _ = require('lodash');

async function getCFStackResources() {
// eslint-disable-next-line no-undef
const { hostingAccountStackName } = __settings__;
const { hostingAccountStackName } = getSettings();
const cloudformation = new AWS.CloudFormation();
return cloudformation
.describeStackResources({
Expand All @@ -25,7 +25,24 @@ async function getStackResourcesByType(resourceType, stackResources = {}) {
});
}

function getSettings() {
// eslint-disable-next-line no-undef
const { awsProfile, awsRegion, envName, externalId } = __settings__;
// eslint-disable-next-line no-undef
let { hostingAccountId, hostingAccountStackName } = __settings__;

if (hostingAccountId === undefined) {
hostingAccountId = process.env.INFRA_TESTS_HOSTING_ACCOUNT_ID;
}
if (hostingAccountStackName === undefined) {
hostingAccountStackName = process.env.INFRA_TESTS_HOSTING_ACCOUNT_STACK_NAME;
}

return { awsProfile, awsRegion, envName, externalId, hostingAccountId, hostingAccountStackName };
}

module.exports = {
getSettings,
getCFStackResources,
getStackResourcesByType,
};

0 comments on commit c7fc828

Please sign in to comment.