Skip to content

Commit fbccfa7

Browse files
authored
Tfcloud migrate (#638)
* fix(tf): Move terraform state to S3. * Remove pageryduty. * Pagerduty fixes. * More pagerduty fixes. * Fix lint. * Fix lint and improve the lint commands. * Remove fix-dry-run from lint-check.
1 parent 73dc0d6 commit fbccfa7

7 files changed

+21
-84
lines changed

.aws/src/backfillLambda.ts

-14
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,6 @@ export class BackfillLambda extends Resource {
8080
],
8181
},
8282
],
83-
alarms: {
84-
errors: {
85-
// The backfill lambda is throttled to concurrency of 10.
86-
evaluationPeriods: 1,
87-
comparisonOperator: 'GreaterThanOrEqualToThreshold',
88-
period: 1800, // 30 minutes
89-
// approx. 5% failure rate (taken from test runs on EN_INTL,
90-
// which is the shortest backfill run)
91-
threshold: 150,
92-
actions: config.isDev
93-
? []
94-
: [pagerDuty!.snsNonCriticalAlarmTopic.arn],
95-
},
96-
},
9783
},
9884
tags: config.tags,
9985
});

.aws/src/datasyncLambda.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,8 @@ export class DatasyncLambda extends Resource {
260260
period: period,
261261
threshold: threshold,
262262
statistic: 'Sum',
263-
alarmActions: config.isDev
264-
? []
265-
: [this.pagerDuty.snsCriticalAlarmTopic.arn],
266-
okActions: config.isDev ? [] : [this.pagerDuty.snsCriticalAlarmTopic.arn],
263+
alarmActions: [],
264+
okActions: [],
267265
});
268266
}
269267

.aws/src/main.ts

+8-51
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
import { Construct } from 'constructs';
2-
import {
3-
App,
4-
DataTerraformRemoteState,
5-
RemoteBackend,
6-
TerraformStack,
7-
} from 'cdktf';
2+
import { App, S3Backend, TerraformStack } from 'cdktf';
83
import { AwsProvider } from '@cdktf/provider-aws/lib/provider';
94
import { S3Bucket } from '@cdktf/provider-aws/lib/s3-bucket';
105
import { config } from './config';
11-
import { PocketPagerDuty, PocketVPC } from '@pocket-tools/terraform-modules';
12-
import { PagerdutyProvider } from '@cdktf/provider-pagerduty/lib/provider';
6+
import { PocketVPC } from '@pocket-tools/terraform-modules';
137
import { LocalProvider } from '@cdktf/provider-local/lib/provider';
148
import { NullProvider } from '@cdktf/provider-null/lib/provider';
159
import { ArchiveProvider } from '@cdktf/provider-archive/lib/provider';
@@ -23,35 +17,33 @@ class CurationToolsDataSync extends TerraformStack {
2317
super(scope, name);
2418

2519
new AwsProvider(this, 'aws', { region: 'us-east-1' });
26-
new PagerdutyProvider(this, 'pagerduty_provider', { token: undefined });
2720
new LocalProvider(this, 'local_provider');
2821
new NullProvider(this, 'null_provider');
2922
new ArchiveProvider(this, 'archive_provider');
3023

31-
new RemoteBackend(this, {
32-
hostname: 'app.terraform.io',
33-
organization: 'Pocket',
34-
workspaces: [{ prefix: `${config.name}-` }],
24+
new S3Backend(this, {
25+
bucket: `mozilla-content-team-${config.environment.toLowerCase()}-terraform-state`,
26+
dynamodbTable: `mozilla-content-team-${config.environment.toLowerCase()}-terraform-state`,
27+
key: config.name,
28+
region: 'us-east-1',
3529
});
3630

3731
// ** shared infrastructure between backfill and datasync
3832
const vpc = new PocketVPC(this, 'pocket-shared-vpc');
39-
const pagerDuty = this.createPagerDuty();
4033
//dynamo db to map curatedRecId - scheduledItem's externalId and store approvedItem's externalId
4134
const idMapperDynamoDb = new DynamoDB(this, 'curation-migration-id-mapper');
4235

4336
// ** infrastructure for backfill process **
4437
//bucket for storing all the required csv files
4538
this.createMigrationBucket();
4639

47-
new BackfillAuthorsLambda(this, 'backfill-author-lambda', vpc, pagerDuty);
40+
new BackfillAuthorsLambda(this, 'backfill-author-lambda', vpc);
4841

4942
new BackfillLambda(
5043
this,
5144
'backfill-lambda',
5245
vpc,
5346
idMapperDynamoDb.curationMigrationTable,
54-
pagerDuty,
5547
);
5648

5749
// ** infrastructure for datasync process **
@@ -60,44 +52,9 @@ class CurationToolsDataSync extends TerraformStack {
6052
'datasync-lambda',
6153
vpc,
6254
idMapperDynamoDb.curationMigrationTable,
63-
pagerDuty,
6455
);
6556
}
6657

67-
/**
68-
* Create PagerDuty service for alerts
69-
* @private
70-
*/
71-
private createPagerDuty() {
72-
// don't create any pagerduty resources if in dev
73-
if (config.isDev) {
74-
return undefined;
75-
}
76-
77-
const incidentManagement = new DataTerraformRemoteState(
78-
this,
79-
'incident_management',
80-
{
81-
organization: 'Pocket',
82-
workspaces: {
83-
name: 'incident-management',
84-
},
85-
},
86-
);
87-
88-
return new PocketPagerDuty(this, 'pagerduty', {
89-
prefix: config.prefix,
90-
service: {
91-
criticalEscalationPolicyId: incidentManagement
92-
.get('policy_default_critical_id')
93-
.toString(),
94-
nonCriticalEscalationPolicyId: incidentManagement
95-
.get('policy_default_non_critical_id')
96-
.toString(),
97-
},
98-
});
99-
}
100-
10158
/**
10259
* Create the migration S3 bucket
10360
* This bucket is used to store all the required csv files

bin/load-queued-items.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function getRandomInt(min, max) {
5353
async function insertIntoCuratedFeedItem(
5454
queuedItem,
5555
timeLive,
56-
trx: Knex.Transaction
56+
trx: Knex.Transaction,
5757
) {
5858
const now = Math.floor(new Date().getTime() / 1000);
5959

@@ -107,7 +107,7 @@ async function moveQueuedItems(feedId, baseTime) {
107107
const curatedRecId = await insertIntoCuratedFeedItem(
108108
queuedItem,
109109
i * 3600 + baseTime,
110-
trx
110+
trx,
111111
);
112112
await updateQueuedItem(queuedItem['queued_id'], trx);
113113
await insertTileSource(curatedRecId, trx);
@@ -116,7 +116,9 @@ async function moveQueuedItems(feedId, baseTime) {
116116
} catch (e) {
117117
await trx.rollback();
118118
console.log(
119-
`Number of items emptied from the queue before error occurred: ${i - 1}`
119+
`Number of items emptied from the queue before error occurred: ${
120+
i - 1
121+
}`,
120122
);
121123
console.log(`Failed at queued item ID: ${queuedItem['queued_id']}`);
122124
console.log(`Failed for the time_live: ${i * 3600 + baseTime}`);
@@ -137,7 +139,7 @@ async function load() {
137139
const count = await moveQueuedItems(
138140
feedId,
139141
// Starting from the next hour
140-
startTime
142+
startTime,
141143
);
142144

143145
return { count, startTime };

bin/rollback-queued-items.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async function rollbackQueuedItems(queuedIds: number[], trx: Knex.Transaction) {
2828

2929
async function rollbackTileSource(
3030
curatedRecIds: number[],
31-
trx: Knex.Transaction
31+
trx: Knex.Transaction,
3232
) {
3333
await dbClient('tile_source')
3434
.delete()
@@ -38,7 +38,7 @@ async function rollbackTileSource(
3838

3939
async function rollbackCuratedItems(
4040
curatedRecIds: number[],
41-
trx: Knex.Transaction
41+
trx: Knex.Transaction,
4242
) {
4343
return trx('curated_feed_items')
4444
.delete()
@@ -70,7 +70,7 @@ async function rollback() {
7070
rollback()
7171
.then((res) => {
7272
console.log(
73-
`Successfully rollback feed ID: ${res.feedId} after time_live: ${res.timeLive}`
73+
`Successfully rollback feed ID: ${res.feedId} after time_live: ${res.timeLive}`,
7474
);
7575
console.log(`Number of items affected back: ${res.curatedRecIds.length}`);
7676
console.log('Curated Rec IDs: ', JSON.stringify(res.curatedRecIds));

buildspec.yml

-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ env:
2323
USERNAME: 'codebuild'
2424
secrets-manager:
2525
#Pull in the default terraform cloud token
26-
TERRAFORM_TOKEN: 'CodeBuild/Default:terraform_token'
2726
PAGERDUTY_TOKEN: 'CodeBuild/Default:mozilla_pagerduty_token'
2827
GITHUB_ACCESS_TOKEN: 'CodeBuild/Default:github_access_token'
2928

@@ -35,11 +34,6 @@ phases:
3534
- |
3635
. /home/circleci/.codebuild_shims_wrapper.sh
3736
echo $CODEBUILD_WEBHOOK_HEAD_REF
38-
echo Setting Up Terraform Token
39-
rc="credentials \"app.terraform.io\" { "
40-
rc="${rc} token=\"$TERRAFORM_TOKEN\" "
41-
rc="${rc}}"
42-
echo "$rc" > ~/.terraformrc
4337
echo Setting Github Access Token
4438
echo "//npm.pkg.github.com/:_authToken=${GITHUB_ACCESS_TOKEN}" > ~/.npmrc
4539
echo Setting environment variables

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"test-integration": "jest \"\\.integration\\.ts\" --runInBand",
1313
"test-all": "npm run test-spec && npm run test-integration",
1414
"postinstall": "(cd bin && npm install); (cd curation-authors-backfill && npm install); (cd curation-migration-backfill && npm install); (cd curation-migration-datasync && npm install)",
15-
"lint-check": "eslint --fix-dry-run \"curation-*/**/*.ts\"",
16-
"lint-fix": "eslint --fix \"curation*/**/*.ts\""
15+
"lint-check": "eslint \"**/*.ts\"",
16+
"lint-fix": "eslint --fix \"**/*.ts\""
1717
},
1818
"repository": {
1919
"type": "git",

0 commit comments

Comments
 (0)