@gradientedge/cdk-utils 8.145.0 → 8.146.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ export declare enum RemoteBackend {
2
+ local = "local",
3
+ s3 = "s3"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RemoteBackend = void 0;
4
+ var RemoteBackend;
5
+ (function (RemoteBackend) {
6
+ RemoteBackend["local"] = "local";
7
+ RemoteBackend["s3"] = "s3";
8
+ })(RemoteBackend || (exports.RemoteBackend = RemoteBackend = {}));
@@ -24,7 +24,11 @@ export declare class CommonCloudflareConstruct extends TerraformStack {
24
24
  * @summary Determine the account id based on the cdktf.json context
25
25
  */
26
26
  protected determineAccountId(): void;
27
+ /**
28
+ * @summary Determine the api token based on the cdktf.json context
29
+ */
27
30
  protected determineApiToken(): void;
31
+ protected determineRemoteBackend(): void;
28
32
  /**
29
33
  * @summary Utility method to determine if the initialisation is in development (dev) stage
30
34
  * This is determined by the stage property injected via cdk context
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommonCloudflareConstruct = void 0;
4
- const provider_1 = require("@cdktf/provider-cloudflare/lib/provider");
4
+ const provider_1 = require("@cdktf/provider-aws/lib/provider");
5
+ const provider_2 = require("@cdktf/provider-cloudflare/lib/provider");
5
6
  const cdktf_1 = require("cdktf");
6
7
  const common_1 = require("../../common");
7
8
  const services_1 = require("../services");
9
+ const constants_1 = require("./constants");
8
10
  class CommonCloudflareConstruct extends cdktf_1.TerraformStack {
9
11
  id;
10
12
  fullyQualifiedDomainName;
@@ -33,7 +35,8 @@ class CommonCloudflareConstruct extends cdktf_1.TerraformStack {
33
35
  this.determineFullyQualifiedDomain();
34
36
  this.determineAccountId();
35
37
  this.determineApiToken();
36
- new provider_1.CloudflareProvider(this, `${this.id}-provider`, this.props);
38
+ this.determineRemoteBackend();
39
+ new provider_2.CloudflareProvider(this, `${this.id}-provider`, this.props);
37
40
  }
38
41
  /**
39
42
  * @summary Determine the fully qualified domain name based on domainName & subDomain
@@ -49,9 +52,36 @@ class CommonCloudflareConstruct extends cdktf_1.TerraformStack {
49
52
  determineAccountId() {
50
53
  this.props.accountId = new cdktf_1.TerraformVariable(this, `accountId`, {}).stringValue;
51
54
  }
55
+ /**
56
+ * @summary Determine the api token based on the cdktf.json context
57
+ */
52
58
  determineApiToken() {
53
59
  this.props.apiToken = new cdktf_1.TerraformVariable(this, `apiToken`, {}).stringValue;
54
60
  }
61
+ determineRemoteBackend() {
62
+ const debug = this.node.tryGetContext('debug');
63
+ switch (this.props.remoteBackend?.type) {
64
+ case constants_1.RemoteBackend.s3:
65
+ new provider_1.AwsProvider(this, `${this.id}-aws-provider`, {
66
+ profile: process.env.AWS_PROFILE ?? 'default',
67
+ region: this.props.remoteBackend.region,
68
+ });
69
+ new cdktf_1.S3Backend(this, {
70
+ bucket: this.props.remoteBackend.bucketName,
71
+ dynamodbTable: this.props.remoteBackend.tableName,
72
+ key: `${this.id}`,
73
+ profile: process.env.AWS_PROFILE ?? 'default',
74
+ region: this.props.remoteBackend.region,
75
+ });
76
+ break;
77
+ case constants_1.RemoteBackend.local:
78
+ if (debug)
79
+ console.debug(`Using local backend for ${this.id}`);
80
+ break;
81
+ default:
82
+ break;
83
+ }
84
+ }
55
85
  /**
56
86
  * @summary Utility method to determine if the initialisation is in development (dev) stage
57
87
  * This is determined by the stage property injected via cdk context
@@ -1,3 +1,4 @@
1
+ export * from './constants';
1
2
  export * from './construct';
2
3
  export * from './stack';
3
4
  export * from './types';
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./constants"), exports);
17
18
  __exportStar(require("./construct"), exports);
18
19
  __exportStar(require("./stack"), exports);
19
20
  __exportStar(require("./types"), exports);
@@ -38,6 +38,7 @@ class CommonCloudflareStack extends cdktf_1.TerraformStack {
38
38
  * @returns The stack properties
39
39
  */
40
40
  determineConstructProps(props) {
41
+ const stage = this.node.tryGetContext('stage');
41
42
  return {
42
43
  accountId: this.node.tryGetContext('accountId'),
43
44
  apiToken: this.node.tryGetContext('apiToken'),
@@ -46,7 +47,7 @@ class CommonCloudflareStack extends cdktf_1.TerraformStack {
46
47
  features: this.node.tryGetContext('features'),
47
48
  name: this.node.tryGetContext('resourceGroupName'),
48
49
  skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
49
- stage: this.node.tryGetContext('stage'),
50
+ stage: stage,
50
51
  subDomain: this.node.tryGetContext('subDomain'),
51
52
  };
52
53
  }
@@ -1,9 +1,17 @@
1
1
  import { CloudflareProviderConfig } from '@cdktf/provider-cloudflare/lib/provider';
2
2
  import { BaseProps } from '../../common';
3
+ import { RemoteBackend } from './constants';
4
+ export interface RemoteBackendProps {
5
+ bucketName: string;
6
+ region: string;
7
+ tableName: string;
8
+ type: RemoteBackend;
9
+ }
3
10
  /**
4
11
  */
5
12
  export interface CommonCloudflareStackProps extends BaseProps, CloudflareProviderConfig {
6
13
  accountId: string;
7
14
  apiToken: string;
15
+ remoteBackend?: RemoteBackendProps;
8
16
  useExistingZone?: boolean;
9
17
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "8.145.0",
3
+ "version": "8.146.1",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -50,6 +50,7 @@
50
50
  "@aws-sdk/client-secrets-manager": "^3.458.0",
51
51
  "@aws-sdk/credential-providers": "^3.458.0",
52
52
  "@aws-sdk/types": "^3.451.0",
53
+ "@cdktf/provider-aws": "^18.0.6",
53
54
  "@cdktf/provider-azurerm": "^11.0.6",
54
55
  "@cdktf/provider-cloudflare": "^10.0.3",
55
56
  "@types/lodash": "^4.14.202",
@@ -0,0 +1,4 @@
1
+ export enum RemoteBackend {
2
+ local = 'local',
3
+ s3 = 's3',
4
+ }
@@ -1,5 +1,6 @@
1
+ import { AwsProvider } from '@cdktf/provider-aws/lib/provider'
1
2
  import { CloudflareProvider } from '@cdktf/provider-cloudflare/lib/provider'
2
- import { TerraformStack, TerraformVariable } from 'cdktf'
3
+ import { S3Backend, TerraformStack, TerraformVariable } from 'cdktf'
3
4
  import { Construct } from 'constructs'
4
5
  import { isDevStage, isPrdStage, isTestStage, isUatStage } from '../../common'
5
6
  import {
@@ -13,6 +14,7 @@ import {
13
14
  CloudflareWorkerManager,
14
15
  CloudflareZoneManager,
15
16
  } from '../services'
17
+ import { RemoteBackend } from './constants'
16
18
  import { CommonCloudflareStackProps } from './types'
17
19
 
18
20
  export class CommonCloudflareConstruct extends TerraformStack {
@@ -47,13 +49,14 @@ export class CommonCloudflareConstruct extends TerraformStack {
47
49
  this.determineFullyQualifiedDomain()
48
50
  this.determineAccountId()
49
51
  this.determineApiToken()
52
+ this.determineRemoteBackend()
50
53
  new CloudflareProvider(this, `${this.id}-provider`, this.props)
51
54
  }
52
55
 
53
56
  /**
54
57
  * @summary Determine the fully qualified domain name based on domainName & subDomain
55
58
  */
56
- protected determineFullyQualifiedDomain(): void {
59
+ protected determineFullyQualifiedDomain() {
57
60
  this.fullyQualifiedDomainName = this.props.subDomain
58
61
  ? `${this.props.subDomain}.${this.props.domainName}`
59
62
  : this.props.domainName
@@ -62,14 +65,41 @@ export class CommonCloudflareConstruct extends TerraformStack {
62
65
  /**
63
66
  * @summary Determine the account id based on the cdktf.json context
64
67
  */
65
- protected determineAccountId(): void {
68
+ protected determineAccountId() {
66
69
  this.props.accountId = new TerraformVariable(this, `accountId`, {}).stringValue
67
70
  }
68
71
 
69
- protected determineApiToken(): void {
72
+ /**
73
+ * @summary Determine the api token based on the cdktf.json context
74
+ */
75
+ protected determineApiToken() {
70
76
  this.props.apiToken = new TerraformVariable(this, `apiToken`, {}).stringValue
71
77
  }
72
78
 
79
+ protected determineRemoteBackend() {
80
+ const debug = this.node.tryGetContext('debug')
81
+ switch (this.props.remoteBackend?.type) {
82
+ case RemoteBackend.s3:
83
+ new AwsProvider(this, `${this.id}-aws-provider`, {
84
+ profile: process.env.AWS_PROFILE ?? 'default',
85
+ region: this.props.remoteBackend.region,
86
+ })
87
+ new S3Backend(this, {
88
+ bucket: this.props.remoteBackend.bucketName,
89
+ dynamodbTable: this.props.remoteBackend.tableName,
90
+ key: `${this.id}`,
91
+ profile: process.env.AWS_PROFILE ?? 'default',
92
+ region: this.props.remoteBackend.region,
93
+ })
94
+ break
95
+ case RemoteBackend.local:
96
+ if (debug) console.debug(`Using local backend for ${this.id}`)
97
+ break
98
+ default:
99
+ break
100
+ }
101
+ }
102
+
73
103
  /**
74
104
  * @summary Utility method to determine if the initialisation is in development (dev) stage
75
105
  * This is determined by the stage property injected via cdk context
@@ -1,3 +1,4 @@
1
+ export * from './constants'
1
2
  export * from './construct'
2
3
  export * from './stack'
3
4
  export * from './types'
@@ -7,6 +7,7 @@ import { TerraformStack } from 'cdktf'
7
7
  import { Construct } from 'constructs'
8
8
  import _ from 'lodash'
9
9
  import { isDevStage } from '../../common'
10
+ import { RemoteBackend } from './constants'
10
11
 
11
12
  /**
12
13
  * @classdesc Common stack to use as a base for all higher level constructs.
@@ -42,6 +43,7 @@ export class CommonCloudflareStack extends TerraformStack {
42
43
  * @returns The stack properties
43
44
  */
44
45
  protected determineConstructProps(props: CommonCloudflareStackProps) {
46
+ const stage = this.node.tryGetContext('stage')
45
47
  return {
46
48
  accountId: this.node.tryGetContext('accountId'),
47
49
  apiToken: this.node.tryGetContext('apiToken'),
@@ -50,7 +52,7 @@ export class CommonCloudflareStack extends TerraformStack {
50
52
  features: this.node.tryGetContext('features'),
51
53
  name: this.node.tryGetContext('resourceGroupName'),
52
54
  skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
53
- stage: this.node.tryGetContext('stage'),
55
+ stage: stage,
54
56
  subDomain: this.node.tryGetContext('subDomain'),
55
57
  }
56
58
  }
@@ -1,10 +1,19 @@
1
1
  import { CloudflareProviderConfig } from '@cdktf/provider-cloudflare/lib/provider'
2
2
  import { BaseProps } from '../../common'
3
+ import { RemoteBackend } from './constants'
4
+
5
+ export interface RemoteBackendProps {
6
+ bucketName: string
7
+ region: string
8
+ tableName: string
9
+ type: RemoteBackend
10
+ }
3
11
 
4
12
  /**
5
13
  */
6
14
  export interface CommonCloudflareStackProps extends BaseProps, CloudflareProviderConfig {
7
15
  accountId: string
8
16
  apiToken: string
17
+ remoteBackend?: RemoteBackendProps
9
18
  useExistingZone?: boolean
10
19
  }