Skip to content

Commit

Permalink
Merge pull request #106 from nimblehq/feature/63-add-terraform-addon
Browse files Browse the repository at this point in the history
[#63] Add Terraform codebase
  • Loading branch information
hoangmirs authored Aug 29, 2022
2 parents 9702623 + 79a989c commit d4e2252
Show file tree
Hide file tree
Showing 27 changed files with 211 additions and 778 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
run: npm ci

- name: Run tests
shell: bash
run: npm run test '--ignore-scripts' -- --watchAll=false --coverage --ci

- name: Upload test coverage
Expand Down
877 changes: 127 additions & 750 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
"@oclif/plugin-plugins": "^2.0.1",
"@types/dedent": "^0.7.0",
"dedent": "^0.7.0",
"inquirer": "^9.1.0"
"inquirer": "^8.2.4"
},
"devDependencies": {
"@nimblehq/eslint-config-nimble": "^2.4.0",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/inquirer": "^9.0.0",
"@types/inquirer": "^8.2.1",
"@types/jest": "^28.1.6",
"@types/node": "^18.7.6",
"chai": "^4.3.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:

env:
TERRAFORM_VERSION: "1.2.4"
TERRAFORM_VERSION: "1.2.8"

jobs:
linting:
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions skeleton/core/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform 1.2.8
2 changes: 1 addition & 1 deletion skeleton/aws/main.tf → skeleton/core/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ terraform {
}

# Terraform version
required_version = "~> 1.2.4"
required_version = "~> 1.2.8"
}
File renamed without changes.
2 changes: 1 addition & 1 deletion skeleton/aws/variables.tf → skeleton/core/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ variable "owner" {
}

variable "namespace" {
description = "The namespace for the application infrastructure on AWS, e.g. acme-web"
description = "The namespace for the application infrastructure on the selected provider, e.g. acme-web"
type = string
}

Expand Down
1 change: 1 addition & 0 deletions src/commands/generate/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('Generator command', () => {
it('creates expected files', () => {
const expectedFiles = [
'.gitignore',
'.tool-versions',
'main.tf',
'variables.tf',
'providers.tf',
Expand Down
6 changes: 4 additions & 2 deletions src/commands/generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
versionControlChoices,
} from '../../templates/addons/versionControl';
import { generateAwsTemplate } from '../../templates/aws';
import { applyCore } from '../../templates/core';

type GeneralOptions = {
projectName: string;
Expand Down Expand Up @@ -59,7 +60,7 @@ export default class Generator extends Command {
};

try {
this.applyCore(generalOptions);
this.applyGeneralParts(generalOptions);

switch (generalOptions.provider) {
case 'aws':
Expand All @@ -79,7 +80,8 @@ export default class Generator extends Command {
}
}

private applyCore(generalOptions: GeneralOptions): void {
private applyGeneralParts(generalOptions: GeneralOptions): void {
applyCore(generalOptions);
applyVersionControl(generalOptions);
}

Expand Down
1 change: 0 additions & 1 deletion src/templates/addons/versionControl/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('Version control add-on', () => {
'.github/PULL_REQUEST_TEMPLATE/release_template.md',
'.github/workflows/lint.yml',
'.github/PULL_REQUEST_TEMPLATE.md',
'.gitignore',
];

expect(projectDir).toHaveFiles(expectedFiles);
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/alb.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyAlb, {
albModuleContent,
albOutputsContent,
Expand All @@ -19,6 +20,7 @@ describe('ALB add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applyAlb(awsOptions);
});
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/bastion.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyBastion, {
bastionModuleContent,
bastionVariablesContent,
Expand All @@ -18,6 +19,7 @@ describe('Bastion add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applyBastion(awsOptions);
});
Expand Down
11 changes: 2 additions & 9 deletions src/templates/aws/addons/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ describe('Common add-on', () => {
remove('/', projectDir);
});

it('creates expected files', () => {
const expectedFiles = [
'main.tf',
'providers.tf',
'outputs.tf',
'variables.tf',
];

expect(projectDir).toHaveFiles(expectedFiles);
it('creates the expected file', () => {
expect(projectDir).toHaveFile('providers.tf');
});
});
});
12 changes: 1 addition & 11 deletions src/templates/aws/addons/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ import { AwsOptions } from '..';
import { copy } from '../../../helpers/file';

const applyCommon = ({ projectName }: AwsOptions) => {
const filesToCopy = [
'main.tf',
'outputs.tf',
'providers.tf',
'variables.tf',
'README.md',
];

filesToCopy.forEach((fileName) => {
copy(`aws/${fileName}`, fileName, projectName);
});
copy('aws/providers.tf', 'providers.tf', projectName);
};

export default applyCommon;
2 changes: 2 additions & 0 deletions src/templates/aws/addons/ecr.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyCommon from './common';
import applyEcr, { ecrModuleContent, ecrVariablesContent } from './ecr';

Expand All @@ -15,6 +16,7 @@ describe('ECR add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applyEcr(awsOptions);
});
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/ecs.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyCommon from './common';
import applyEcs, { ecsModuleContent, ecsVariablesContent } from './ecs';

Expand All @@ -15,6 +16,7 @@ describe('ECS add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applyEcs(awsOptions);
});
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/log.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyCommon from './common';
import applyLog, { logModuleContent } from './log';

Expand All @@ -15,6 +16,7 @@ describe('Log add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applyLog(awsOptions);
});
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/rds.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyCommon from './common';
import applyRds, { rdsModuleContent, rdsVariablesContent } from './rds';

Expand All @@ -15,6 +16,7 @@ describe('RDS add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applyRds(awsOptions);
});
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/region.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyCommon from './common';
import applyRegion, { regionVariablesContent } from './region';

Expand All @@ -16,6 +17,7 @@ describe('Region add-on', () => {
awsRegion,
};

applyCore(awsOptions);
applyCommon(awsOptions);
applyRegion(awsOptions);
});
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/s3.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyCommon from './common';
import applyS3, { s3ModuleContent, s3OutputsContent } from './s3';

Expand All @@ -15,6 +16,7 @@ describe('S3 add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applyS3(awsOptions);
});
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/securityGroup.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyCommon from './common';
import applySecurityGroup, {
securityGroupModuleContent,
Expand All @@ -18,6 +19,7 @@ describe('Security group add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applySecurityGroup(awsOptions);
});
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/ssm.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyCommon from './common';
import applySsm, { ssmModuleContent, ssmVariablesContent } from './ssm';

Expand All @@ -15,6 +16,7 @@ describe('SSM add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applySsm(awsOptions);
});
Expand Down
2 changes: 2 additions & 0 deletions src/templates/aws/addons/vpc.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AwsOptions } from '..';
import { remove } from '../../../helpers/file';
import { applyCore } from '../../core';
import applyCommon from './common';
import applyVpc, { vpcModuleContent, vpcOutputsContent } from './vpc';

Expand All @@ -15,6 +16,7 @@ describe('VPC add-on', () => {
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
applyCommon(awsOptions);
applyVpc(awsOptions);
});
Expand Down
37 changes: 37 additions & 0 deletions src/templates/core/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { applyCore } from '.';
import { remove } from '../../helpers/file';
import { AwsOptions } from '../aws';

describe('Core codebase', () => {
describe('given valid AwsOptions', () => {
const projectDir = 'core-test';

beforeAll(() => {
const awsOptions: AwsOptions = {
projectName: projectDir,
provider: 'aws',
infrastructureType: 'advanced',
awsRegion: 'ap-southeast-1',
};

applyCore(awsOptions);
});

afterAll(() => {
jest.clearAllMocks();
remove('/', projectDir);
});

it('creates expected files', () => {
const expectedFiles = [
'.gitignore',
'.tool-versions',
'main.tf',
'outputs.tf',
'variables.tf',
];

expect(projectDir).toHaveFiles(expectedFiles);
});
});
});
10 changes: 10 additions & 0 deletions src/templates/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { GeneralOptions } from '../../commands/generate';
import { copy } from '../../helpers/file';

const applyCore = (generalOptions: GeneralOptions): void => {
const { projectName } = generalOptions;

copy('core/', '.', projectName);
};

export { applyCore };

0 comments on commit d4e2252

Please sign in to comment.