-
Notifications
You must be signed in to change notification settings - Fork 0
/
elasticBeanstalkProvider.js
66 lines (60 loc) · 1.81 KB
/
elasticBeanstalkProvider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// @flow strict
/*::
import type { Cast } from '@lukekaalim/cast';
import type { Provider } from '@lukekaalim/terraform-plugin';
*/
const { toObject, toString } = require('@lukekaalim/cast');
const { ElasticBeanstalk } = require('@aws-sdk/client-elastic-beanstalk');
const { S3 } = require('@aws-sdk/client-s3');
const { defaultProvider } = require('@aws-sdk/credential-provider-node');
const {
createProvider, createSchema, createBlock,
createAttribute, types: { string }, marshal
} = require('@lukekaalim/terraform-plugin');
const { applicationVersionResource } = require('./applicationVersion');
/*::
export type ConfiguredProvider = [ElasticBeanstalk, S3];
export type ProviderConfig = {
region: ?string,
profile: ?string,
}
*/
const toProviderConfig/*: Cast<ProviderConfig>*/ = (value) => {
const object = toObject(value);
return {
region: object.region ? toString(object.region) : null,
profile: object.profile ? toString(object.profile) : null,
}
};
const elasticBeanstalkProvider/*: Provider*/ = createProvider({
name: 'immutable-elastic-beanstalk',
resources: [applicationVersionResource],
schema: createSchema({
block: createBlock({
attributes: [
createAttribute({
name: 'region',
required: false,
optional: true,
type: marshal(string),
}),
createAttribute({
name: 'profile',
required: false,
optional: true,
type: marshal(string),
}),
]
}),
}),
async configure(config) {
const { region, profile } = toProviderConfig(config);
const credentials = defaultProvider({ profile });
const eb = new ElasticBeanstalk({ region, credentials });
const s3 = new S3({ region, credentials });
return [eb, s3];
},
});
module.exports = {
elasticBeanstalkProvider,
};