@cdk8s/cdktf-resolver 0.0.0
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.
- package/.gitattributes +39 -0
- package/.jsii +236 -0
- package/.projenrc.ts +59 -0
- package/API.md +249 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/DCO +34 -0
- package/LICENSE +202 -0
- package/README.md +160 -0
- package/SECURITY.md +5 -0
- package/git-hooks/README.md +9 -0
- package/git-hooks/prepare-commit-msg +18 -0
- package/git-hooks/setup.sh +10 -0
- package/lib/exec.d.ts +7 -0
- package/lib/exec.js +27 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +18 -0
- package/lib/resolve.d.ts +18 -0
- package/lib/resolve.js +112 -0
- package/package.json +165 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# CDK For Terraform Resolver
|
|
2
|
+
|
|
3
|
+
The `CdkTfResolver` is able to resolve any [`TerraformOutput`](https://developer.hashicorp.com/terraform/cdktf/concepts/variables-and-outputs#output-values)
|
|
4
|
+
defined by your CDKTF application. In this example, we create an S3 `Bucket` with the CDKTF, and pass its (deploy time generated)
|
|
5
|
+
name as an environment variable to a Kubernetes `CronJob` resource.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import * as tf from "cdktf";
|
|
9
|
+
import * as aws from "@cdktf/provider-aws";
|
|
10
|
+
import * as k8s from 'cdk8s';
|
|
11
|
+
import * as kplus from 'cdk8s-plus-26';
|
|
12
|
+
|
|
13
|
+
import { CdkTfResolver } from '@cdk8s/cdktf-resolver';
|
|
14
|
+
|
|
15
|
+
const awsApp = new tf.App();
|
|
16
|
+
const stack = new tf.TerraformStack(awsApp, 'aws');
|
|
17
|
+
|
|
18
|
+
const k8sApp = new k8s.App({ resolvers: [new CdkTfResolver()] });
|
|
19
|
+
const manifest = new k8s.Chart(k8sApp, 'Manifest', { resolver });
|
|
20
|
+
|
|
21
|
+
const bucket = new aws.s3Bucket.S3Bucket(stack, 'Bucket');
|
|
22
|
+
const bucketName = new tf.TerraformOutput(constrcut, 'BucketName', {
|
|
23
|
+
value: bucket.bucket,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
new kplus.CronJob(manifest, 'CronJob', {
|
|
27
|
+
schedule: k8s.Cron.daily(),
|
|
28
|
+
containers: [{
|
|
29
|
+
image: 'job',
|
|
30
|
+
envVariables: {
|
|
31
|
+
// directly passing the value of the `TerraformOutput` containing
|
|
32
|
+
// the deploy time bucket name
|
|
33
|
+
BUCKET_NAME: kplus.EnvValue.fromValue(bucketName.value),
|
|
34
|
+
}
|
|
35
|
+
}]
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
awsApp.synth();
|
|
39
|
+
k8sApp.synth();
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
During cdk8s synthesis, the custom resolver will detect that `bucketName.value` is not a concrete value,
|
|
43
|
+
but rather a value of a `TerraformOutput`. It will then perform `cdktf` CLI commands in order to fetch the
|
|
44
|
+
actual value from the deployed infrastructure in your account. This means that in order
|
|
45
|
+
for `cdk8s synth` to succeed, it must be executed *after* the CDKTF resources
|
|
46
|
+
have been deployed. So your deployment workflow should (conceptually) be:
|
|
47
|
+
|
|
48
|
+
1. `cdktf deploy`
|
|
49
|
+
2. `cdk8s synth`
|
|
50
|
+
|
|
51
|
+
> Note that the `CdkTfResolver` is **only** able to fetch tokens that have a `TerraformOutput` defined for them.
|
|
52
|
+
|
|
53
|
+
##### Permissions
|
|
54
|
+
|
|
55
|
+
Since running `cdk8s synth` will now require reading terraform outputs, it must have permissions to do so.
|
|
56
|
+
In case a remote state file is used, this means providing a set of credentials for the account that have access
|
|
57
|
+
to where the state is stored. This will vary depending on your cloud provider, but in most cases will involve giving
|
|
58
|
+
read permissions on a blob storage device (e.g S3 bucket).
|
|
59
|
+
|
|
60
|
+
Note that the permissions cdk8s require are far more scoped down than those normally required for the
|
|
61
|
+
deployment of CDKTF applications. It is therefore recommended to not reuse the same set of credentials,
|
|
62
|
+
and instead create a scoped down `ReadOnly` role dedicated for cdk8s resolvers.
|
|
63
|
+
|
|
64
|
+
Following are the set of commands the resolver will execute:
|
|
65
|
+
|
|
66
|
+
- [`cdktf output`](https://developer.hashicorp.com/terraform/cdktf/cli-reference/commands#output)
|
|
67
|
+
|
|
68
|
+
## Cross Repository Workflow
|
|
69
|
+
|
|
70
|
+
As we've seen, your `cdk8s` application needs access to the objects defined in your cloud application. If both applications
|
|
71
|
+
are defined within the same file, this is trivial to achieve. If they are in different files, a simple `import` statement will suffice.
|
|
72
|
+
However, what if the applications are managed in two separate repositories? This makes it a little trickier, but still possible.
|
|
73
|
+
|
|
74
|
+
In this scenario, `cdktf.ts` in the CDKTF application, stored in a dedicated repository.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import * as tf from "cdktf";
|
|
78
|
+
import * as aws from "@cdktf/provider-aws";
|
|
79
|
+
|
|
80
|
+
import { CdkTfResolver } from '@cdk8s/cdktf-resolver';
|
|
81
|
+
|
|
82
|
+
const awsApp = new tf.App();
|
|
83
|
+
const stack = new tf.TerraformStack(awsApp, 'aws');
|
|
84
|
+
|
|
85
|
+
const bucket = new aws.s3Bucket.S3Bucket(stack, 'Bucket');
|
|
86
|
+
const bucketName = new tf.TerraformOutput(constrcut, 'BucketName', {
|
|
87
|
+
value: bucket.bucket,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
awsApp.synth();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
In order for the `cdk8s` application to have cross repository access, the CDKTF object instances
|
|
94
|
+
that we want to expose need to be available via a package repository. To do this, break up the
|
|
95
|
+
CDKTF application into the following files:
|
|
96
|
+
|
|
97
|
+
`app.ts`
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import * as tf from "cdktf";
|
|
101
|
+
import * as aws from "@cdktf/provider-aws";
|
|
102
|
+
|
|
103
|
+
import { CdkTfResolver } from '@cdk8s/cdktf-resolver';
|
|
104
|
+
|
|
105
|
+
const awsApp = new tf.App();
|
|
106
|
+
const stack = new tf.TerraformStack(awsApp, 'aws');
|
|
107
|
+
|
|
108
|
+
const bucket = new aws.s3Bucket.S3Bucket(stack, 'Bucket');
|
|
109
|
+
// export the thing we want to have available for cdk8s applications
|
|
110
|
+
export const bucketName = new tf.TerraformOutput(constrcut, 'BucketName', {
|
|
111
|
+
value: bucket.bucket,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// note that we don't call awsApp.synth here
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`main.ts`
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { awsApp } from './app.ts'
|
|
121
|
+
|
|
122
|
+
awsApp.synth();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Now, publish the `app.ts` file to a package manager, so that your `cdk8s` application can install and import it.
|
|
126
|
+
This approach might be somewhat counter intuitive, because normally we only publish classes to the package manager,
|
|
127
|
+
not instances. Indeed, these types of applications introduce a new use-case that requires the sharing of instances.
|
|
128
|
+
Conceptually, this is no different than writing state<sup>*</sup> to an SSM parameter or an S3 bucket, and it allows us to remain
|
|
129
|
+
in the boundaries of our programming language, and the typing guarantees it provides.
|
|
130
|
+
|
|
131
|
+
> <sup>*</sup> Actually, we are only publishing instructions for fetching state, not the state itself.
|
|
132
|
+
|
|
133
|
+
Assuming `app.ts` was published as the `my-cdktf-app` package, our `cdk8s` application will now look like so:
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import * as k8s from 'cdk8s';
|
|
137
|
+
import * as kplus from 'cdk8s-plus-27';
|
|
138
|
+
|
|
139
|
+
// import the desired instance from the CDKTF app.
|
|
140
|
+
import { bucketName } from 'my-cdktf-app';
|
|
141
|
+
|
|
142
|
+
import { CdkTfResolver } from '@cdk8s/cdktf-resolver';
|
|
143
|
+
|
|
144
|
+
const k8sApp = new k8s.App({ resolvers: [new CdkTfResolver()] });
|
|
145
|
+
const manifest = new k8s.Chart(k8sApp, 'Manifest');
|
|
146
|
+
|
|
147
|
+
new kplus.CronJob(manifest, 'CronJob', {
|
|
148
|
+
schedule: k8s.Cron.daily(),
|
|
149
|
+
containers: [{
|
|
150
|
+
image: 'job',
|
|
151
|
+
envVariables: {
|
|
152
|
+
// directly passing the value of the `TerraformOutput` containing
|
|
153
|
+
// the deploy time bucket name
|
|
154
|
+
BUCKET_NAME: kplus.EnvValue.fromValue(bucketName.value),
|
|
155
|
+
}
|
|
156
|
+
}]
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
k8sApp.synth();
|
|
160
|
+
```
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Git Hooks
|
|
2
|
+
|
|
3
|
+
This directory contains git hooks that the core team uses for various tasks.
|
|
4
|
+
|
|
5
|
+
- Commit signoff for automatic compliance of the [DCO](../CONTRIBUTING.md#developer-certificate-of-origin-dco).
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
To setup these git hooks, run `./git-hooks/setup.sh` from the root directory of the project.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
|
|
3
|
+
NAME=$(git config user.name)
|
|
4
|
+
EMAIL=$(git config user.email)
|
|
5
|
+
|
|
6
|
+
if [ -z "$NAME" ]; then
|
|
7
|
+
echo "empty git config user.name"
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
|
|
11
|
+
if [ -z "$EMAIL" ]; then
|
|
12
|
+
echo "empty git config user.email"
|
|
13
|
+
exit 1
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
git interpret-trailers --if-exists doNothing --trailer \
|
|
17
|
+
"Signed-off-by: $NAME <$EMAIL>" \
|
|
18
|
+
--in-place "$1"
|
package/lib/exec.d.ts
ADDED
package/lib/exec.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execSync = void 0;
|
|
4
|
+
const child = require("child_process");
|
|
5
|
+
function execSync(command, options = {}) {
|
|
6
|
+
try {
|
|
7
|
+
child.execSync(command, { cwd: options.cwd, env: options.env });
|
|
8
|
+
}
|
|
9
|
+
catch (err) {
|
|
10
|
+
const message = [`Command failed: ${command}`];
|
|
11
|
+
if (err.stderr) {
|
|
12
|
+
message.push('STDERR:');
|
|
13
|
+
message.push('\n');
|
|
14
|
+
message.push('\n');
|
|
15
|
+
message.push(err.stderr.toString().trim());
|
|
16
|
+
}
|
|
17
|
+
if (err.stdout) {
|
|
18
|
+
message.push('STDOUT:');
|
|
19
|
+
message.push('\n');
|
|
20
|
+
message.push('\n');
|
|
21
|
+
message.push(err.stdout.toString().trim());
|
|
22
|
+
}
|
|
23
|
+
throw new Error(message.join('\n\n'));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.execSync = execSync;
|
|
27
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhlYy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9leGVjLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHVDQUF1QztBQU92QyxTQUFnQixRQUFRLENBQUMsT0FBZSxFQUFFLFVBQTJCLEVBQUU7SUFFckUsSUFBSTtRQUNGLEtBQUssQ0FBQyxRQUFRLENBQUMsT0F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ED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./resolve"), exports);
|
|
18
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7OztBQUFBLDRDQUEwQiIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gJy4vcmVzb2x2ZSc7Il19
|
package/lib/resolve.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IResolver, ResolutionContext } from 'cdk8s';
|
|
2
|
+
import { App } from 'cdktf';
|
|
3
|
+
export interface CdktfResolverProps {
|
|
4
|
+
/**
|
|
5
|
+
* The CDKTF App instance in which the outputs are deinfed in.
|
|
6
|
+
*/
|
|
7
|
+
readonly app: App;
|
|
8
|
+
}
|
|
9
|
+
export declare class CdktfResolver implements IResolver {
|
|
10
|
+
private readonly app;
|
|
11
|
+
private _outputs;
|
|
12
|
+
constructor(props: CdktfResolverProps);
|
|
13
|
+
resolve(context: ResolutionContext): void;
|
|
14
|
+
private fetchOutputValue;
|
|
15
|
+
private fetchOutputs;
|
|
16
|
+
private findOutput;
|
|
17
|
+
private isAddressable;
|
|
18
|
+
}
|
package/lib/resolve.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.CdktfResolver = void 0;
|
|
5
|
+
const JSII_RTTI_SYMBOL_1 = Symbol.for("jsii.rtti");
|
|
6
|
+
const fs = require("fs");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const cdktf_1 = require("cdktf");
|
|
10
|
+
const exec_1 = require("./exec");
|
|
11
|
+
class CdktfResolver {
|
|
12
|
+
constructor(props) {
|
|
13
|
+
this.app = props.app;
|
|
14
|
+
}
|
|
15
|
+
resolve(context) {
|
|
16
|
+
// detects full resources being passed as values.
|
|
17
|
+
// this is legit in terraform and should resolve
|
|
18
|
+
// to the resource fqn.
|
|
19
|
+
// see https://github.com/hashicorp/terraform-cdk/blob/main/packages/cdktf/lib/terraform-output.ts#L79
|
|
20
|
+
const addressable = this.isAddressable(context.value);
|
|
21
|
+
if (!cdktf_1.Token.isUnresolved(context.value) && !addressable) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const output = this.findOutput(context.value);
|
|
25
|
+
try {
|
|
26
|
+
const outputValue = this.fetchOutputValue(output);
|
|
27
|
+
context.replaceValue(outputValue);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
// if both cdk8s and CDKTF applications are defined within the same file,
|
|
31
|
+
// a cdk8s synth is going to happen before the CDKTF deployment.
|
|
32
|
+
// in this case we must swallow the error, otherwise the CDKTF deployment
|
|
33
|
+
// won't be able to go through. we replace the value with something to indicate
|
|
34
|
+
// that a fetching attempt was made and failed.
|
|
35
|
+
context.replaceValue(`Failed fetching value for output ${output.node.path}: ${err}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
fetchOutputValue(output) {
|
|
39
|
+
if (!this._outputs) {
|
|
40
|
+
this._outputs = this.fetchOutputs();
|
|
41
|
+
}
|
|
42
|
+
const stack = cdktf_1.TerraformStack.of(output);
|
|
43
|
+
return this._outputs[stack.node.id][output.friendlyUniqueId];
|
|
44
|
+
}
|
|
45
|
+
fetchOutputs() {
|
|
46
|
+
const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), 'cdktf-project-'));
|
|
47
|
+
const outputsFile = 'outputs.json';
|
|
48
|
+
try {
|
|
49
|
+
this.app.synth();
|
|
50
|
+
const cdktfJson = {
|
|
51
|
+
// `cdktf output` doesn't actually use this value,
|
|
52
|
+
// so we can put whatever we want here.
|
|
53
|
+
language: 'python',
|
|
54
|
+
app: 'cdktf.out',
|
|
55
|
+
};
|
|
56
|
+
// create our own copy of the synthesized app so we can safely clean it up
|
|
57
|
+
copyDirectory(this.app.outdir, path.join(projectDir, cdktfJson.app));
|
|
58
|
+
// write the configuration file as it is required for any cdktf command
|
|
59
|
+
fs.writeFileSync(path.join(projectDir, 'cdktf.json'), JSON.stringify(cdktfJson));
|
|
60
|
+
const stacks = this.app.node.findAll().filter(c => cdktf_1.TerraformStack.isStack(c)).map(c => c.node.id);
|
|
61
|
+
const command = ['cdktf output',
|
|
62
|
+
'--skip-synth',
|
|
63
|
+
`--output ${cdktfJson.app}`,
|
|
64
|
+
`--outputs-file ${outputsFile}`,
|
|
65
|
+
`${stacks.join(' ')}`];
|
|
66
|
+
(0, exec_1.execSync)(command.join(' '), { cwd: projectDir });
|
|
67
|
+
return JSON.parse(fs.readFileSync(path.join(projectDir, outputsFile), { encoding: 'utf-8' }));
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
fs.rmSync(projectDir, { recursive: true });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
findOutput(value) {
|
|
74
|
+
const inspectedStacks = this.app.node.findAll().filter(c => cdktf_1.TerraformStack.isStack(c));
|
|
75
|
+
for (const stack of inspectedStacks) {
|
|
76
|
+
const output = stack.node.findAll().filter(c => c instanceof cdktf_1.TerraformOutput && c.value === value)[0];
|
|
77
|
+
// we don't really care if there are more outputs (possibly from different stacks)
|
|
78
|
+
// that point to the same value. the first will suffice.
|
|
79
|
+
if (output)
|
|
80
|
+
return output;
|
|
81
|
+
}
|
|
82
|
+
// This can happen if either:
|
|
83
|
+
// --------------------------
|
|
84
|
+
// 1. User didn't define an output.
|
|
85
|
+
// 2. User defined a complex literal output value (e.g { bucketName: bucket.bucket }).
|
|
86
|
+
throw new Error(`Unable to find output defined for ${value} (Inspected stacks: ${inspectedStacks.map(s => s.node.id).join(',')})`);
|
|
87
|
+
}
|
|
88
|
+
isAddressable(object) {
|
|
89
|
+
return object && typeof object === 'object' && !Array.isArray(object) && 'fqn' in object;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.CdktfResolver = CdktfResolver;
|
|
93
|
+
_a = JSII_RTTI_SYMBOL_1;
|
|
94
|
+
CdktfResolver[_a] = { fqn: "@cdk8s/cdktf-resolver.CdktfResolver", version: "0.0.0" };
|
|
95
|
+
function copyDirectory(sourceDir, targetDir) {
|
|
96
|
+
if (!fs.existsSync(targetDir)) {
|
|
97
|
+
fs.mkdirSync(targetDir);
|
|
98
|
+
}
|
|
99
|
+
const files = fs.readdirSync(sourceDir);
|
|
100
|
+
for (const file of files) {
|
|
101
|
+
const sourceFilePath = path.join(sourceDir, file);
|
|
102
|
+
const targetFilePath = path.join(targetDir, file);
|
|
103
|
+
const stats = fs.statSync(sourceFilePath);
|
|
104
|
+
if (stats.isDirectory()) {
|
|
105
|
+
copyDirectory(sourceFilePath, targetFilePath);
|
|
106
|
+
}
|
|
107
|
+
else if (stats.isFile()) {
|
|
108
|
+
fs.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