cdktn-cli 0.0.1 → 0.21.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/README.md +1 -0
- package/ambient.d.ts +13 -0
- package/build.js +139 -0
- package/bundle/bin/cdktn +2 -0
- package/bundle/bin/cdktn.js +89 -0
- package/bundle/bin/cdktn.js.map +7 -0
- package/bundle/bin/cmds/handlers.js +740 -0
- package/bundle/bin/cmds/handlers.js.map +7 -0
- package/bundle/templates/csharp/.hooks.sscaff.js +63 -0
- package/bundle/templates/csharp/MainStack.cs +15 -0
- package/bundle/templates/csharp/MyTerraformStack.csproj +13 -0
- package/bundle/templates/csharp/Program.cs +17 -0
- package/bundle/templates/csharp/TestProgram.cs +42 -0
- package/bundle/templates/csharp/cdktf.json +11 -0
- package/bundle/templates/csharp/help +42 -0
- package/bundle/templates/csharp/{{}}.gitignore +345 -0
- package/bundle/templates/go/.hooks.sscaff.js +70 -0
- package/bundle/templates/go/cdktf.json +12 -0
- package/bundle/templates/go/go.mod +8 -0
- package/bundle/templates/go/help +32 -0
- package/bundle/templates/go/main.go +22 -0
- package/bundle/templates/go/main_test.go +42 -0
- package/bundle/templates/go/{{}}.gitignore +21 -0
- package/bundle/templates/java/.hooks.sscaff.js +64 -0
- package/bundle/templates/java/build.gradle +55 -0
- package/bundle/templates/java/cdktf.json +12 -0
- package/bundle/templates/java/gradle.properties +1 -0
- package/bundle/templates/java/gradlew +248 -0
- package/bundle/templates/java/gradlew.bat +92 -0
- package/bundle/templates/java/help +35 -0
- package/bundle/templates/java/settings.gradle +5 -0
- package/bundle/templates/java/src/main/java/com/mycompany/app/Main.java +16 -0
- package/bundle/templates/java/src/main/java/com/mycompany/app/MainStack.java +14 -0
- package/bundle/templates/java/src/test/java/com/company/app/MainTest.java +38 -0
- package/bundle/templates/java/{{}}.gitignore +14 -0
- package/bundle/templates/python/.hooks.sscaff.js +59 -0
- package/bundle/templates/python/Pipfile +7 -0
- package/bundle/templates/python/cdktf.json +12 -0
- package/bundle/templates/python/help +42 -0
- package/bundle/templates/python/main-test.py +26 -0
- package/bundle/templates/python/main.py +16 -0
- package/bundle/templates/python/{{}}.gitignore +7 -0
- package/bundle/templates/python-pip/.hooks.sscaff.js +63 -0
- package/bundle/templates/python-pip/cdktf.json +12 -0
- package/bundle/templates/python-pip/help +35 -0
- package/bundle/templates/python-pip/main-test.py +23 -0
- package/bundle/templates/python-pip/main.py +16 -0
- package/bundle/templates/python-pip/{{}}.gitignore +7 -0
- package/bundle/templates/typescript/.hooks.sscaff.js +78 -0
- package/bundle/templates/typescript/__tests__/main-test.ts +89 -0
- package/bundle/templates/typescript/cdktf.json +11 -0
- package/bundle/templates/typescript/help +51 -0
- package/bundle/templates/typescript/jest.config.js +187 -0
- package/bundle/templates/typescript/main.ts +14 -0
- package/bundle/templates/typescript/package.json +22 -0
- package/bundle/templates/typescript/setup.js +2 -0
- package/bundle/templates/typescript/tsconfig.json +35 -0
- package/bundle/templates/typescript/{{}}.gitignore +11 -0
- package/eslint.config.mjs +80 -0
- package/jest.config.js +19 -0
- package/package.json +133 -7
- package/src/bin/cdktn +2 -0
- package/src/bin/cmds/helper/__tests__/fixtures/foo.tfvars +4 -0
- package/src/bin/cmds/helper/__tests__/fixtures/hey-there.auto.tfvars +5 -0
- package/src/bin/cmds/helper/__tests__/fixtures/terraform.tfvars +4 -0
- package/src/bin/cmds/helper/render-ink.tsx +24 -0
- package/src/bin/cmds/ui/components/bottom-bars/approve.tsx +81 -0
- package/src/bin/cmds/ui/components/bottom-bars/outputs.tsx +30 -0
- package/src/bin/cmds/ui/components/bottom-bars/override.tsx +68 -0
- package/src/bin/cmds/ui/components/bottom-bars/status.tsx +183 -0
- package/src/bin/cmds/ui/components/outputs.tsx +103 -0
- package/src/bin/cmds/ui/components/stream-view.tsx +72 -0
- package/src/bin/cmds/ui/deploy.tsx +139 -0
- package/src/bin/cmds/ui/destroy.tsx +86 -0
- package/src/bin/cmds/ui/diff.tsx +59 -0
- package/src/bin/cmds/ui/get.tsx +134 -0
- package/src/bin/cmds/ui/list.tsx +59 -0
- package/src/bin/cmds/ui/output.tsx +52 -0
- package/src/bin/cmds/ui/provider-list.tsx +17 -0
- package/src/bin/cmds/ui/synth.tsx +51 -0
- package/src/bin/cmds/ui/watch.tsx +80 -0
- package/index.js +0 -2
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) HashiCorp, Inc.
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { execSync } = require('child_process');
|
|
7
|
+
const { chmodSync } = require('fs');
|
|
8
|
+
const { readFileSync, writeFileSync } = require('fs');
|
|
9
|
+
const os = require('os');
|
|
10
|
+
|
|
11
|
+
exports.pre = () => {
|
|
12
|
+
try {
|
|
13
|
+
if (os.platform() === 'win32') {
|
|
14
|
+
execSync('where pipenv')
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
execSync('which pipenv')
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
console.error(`Unable to find "pipenv". Follow the instructions from https://pipenv.pypa.io/`)
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.post = options => {
|
|
26
|
+
// Terraform Cloud configuration settings if the organization name and workspace is set.
|
|
27
|
+
if (options.OrganizationName != '') {
|
|
28
|
+
console.log(`\nGenerating Terraform Cloud configuration for '${options.OrganizationName}' organization and '${options.WorkspaceName}' workspace.....`)
|
|
29
|
+
terraformCloudConfig(options.$base, options.OrganizationName, options.WorkspaceName, options.TerraformRemoteHostname)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const pypi_cdktf = options.pypi_cdktf;
|
|
33
|
+
if (!pypi_cdktf) {
|
|
34
|
+
throw new Error(`missing context "pypi_cdktf"`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
execSync('pipenv install', { stdio: 'inherit' });
|
|
38
|
+
execSync(`pipenv install ${pypi_cdktf}`, { stdio: 'inherit' });
|
|
39
|
+
execSync(`pipenv install pytest`, { stdio: 'inherit' });
|
|
40
|
+
chmodSync('main.py', '700');
|
|
41
|
+
|
|
42
|
+
console.log(readFileSync('./help', 'utf-8'));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function terraformCloudConfig(baseName, organizationName, workspaceName, terraformRemoteHostname) {
|
|
46
|
+
template = readFileSync('./main.py', 'utf-8');
|
|
47
|
+
|
|
48
|
+
const templateWithImports = template.replace(`from cdktn import App, TerraformStack`,
|
|
49
|
+
`from cdktn import App, TerraformStack, CloudBackend, NamedCloudWorkspace`)
|
|
50
|
+
|
|
51
|
+
const result = templateWithImports.replace(`MyStack(app, "${baseName}")`, `stack = MyStack(app, "${baseName}")
|
|
52
|
+
CloudBackend(stack,
|
|
53
|
+
hostname='${terraformRemoteHostname}',
|
|
54
|
+
organization='${organizationName}',
|
|
55
|
+
workspaces=NamedCloudWorkspace('${workspaceName}')
|
|
56
|
+
)`);
|
|
57
|
+
|
|
58
|
+
writeFileSync('./main.py', result, 'utf-8');
|
|
59
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"language": "python",
|
|
3
|
+
"app": "pipenv run python main.py",
|
|
4
|
+
"projectId": "{{projectId}}",
|
|
5
|
+
"sendCrashReports": "{{sendCrashReports}}",
|
|
6
|
+
"terraformProviders": [],
|
|
7
|
+
"terraformModules": [],
|
|
8
|
+
"codeMakerOutput": "imports",
|
|
9
|
+
"context": {
|
|
10
|
+
{{futureFlags}}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
========================================================================================================
|
|
2
|
+
|
|
3
|
+
Your cdktn Python project is ready!
|
|
4
|
+
|
|
5
|
+
cat help Prints this message
|
|
6
|
+
|
|
7
|
+
Compile:
|
|
8
|
+
pipenv run ./main.py Compile and run the python code.
|
|
9
|
+
|
|
10
|
+
Synthesize:
|
|
11
|
+
cdktn synth [stack] Synthesize Terraform resources to cdktf.out/
|
|
12
|
+
|
|
13
|
+
Diff:
|
|
14
|
+
cdktn diff [stack] Perform a diff (terraform plan) for the given stack
|
|
15
|
+
|
|
16
|
+
Deploy:
|
|
17
|
+
cdktn deploy [stack] Deploy the given stack
|
|
18
|
+
|
|
19
|
+
Destroy:
|
|
20
|
+
cdktn destroy [stack] Destroy the given stack
|
|
21
|
+
|
|
22
|
+
Learn more about using modules and providers https://cdk.tf/modules-and-providers
|
|
23
|
+
|
|
24
|
+
Use Providers:
|
|
25
|
+
|
|
26
|
+
You can add prebuilt providers (if available) or locally generated ones using the add command:
|
|
27
|
+
|
|
28
|
+
cdktn provider add "aws@~>3.0" null kreuzwerker/docker
|
|
29
|
+
|
|
30
|
+
You can find all prebuilt providers on PyPI: https://pypi.org/user/cdktn-team/
|
|
31
|
+
You can also install these providers directly through pipenv:
|
|
32
|
+
|
|
33
|
+
pipenv install cdktn-provider-aws
|
|
34
|
+
pipenv install cdktn-provider-google
|
|
35
|
+
pipenv install cdktn-provider-azurerm
|
|
36
|
+
pipenv install cdktn-provider-docker
|
|
37
|
+
pipenv install cdktn-provider-github
|
|
38
|
+
pipenv install cdktn-provider-null
|
|
39
|
+
|
|
40
|
+
You can also build any module or provider locally. Learn more: https://cdk.tf/modules-and-providers
|
|
41
|
+
|
|
42
|
+
========================================================================================================
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from cdktn import Testing
|
|
3
|
+
|
|
4
|
+
# The tests below are example tests, you can find more information at
|
|
5
|
+
# https://cdk.tf/testing
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestMain:
|
|
9
|
+
|
|
10
|
+
def test_my_app(self):
|
|
11
|
+
assert True
|
|
12
|
+
|
|
13
|
+
#stack = TerraformStack(Testing.app(), "stack")
|
|
14
|
+
#app_abstraction = MyApplicationsAbstraction(stack, "app-abstraction")
|
|
15
|
+
#synthesized = Testing.synth(stack)
|
|
16
|
+
|
|
17
|
+
# def test_should_contain_container(self):
|
|
18
|
+
# assert Testing.to_have_resource(self.synthesized, Container.TF_RESOURCE_TYPE)
|
|
19
|
+
|
|
20
|
+
# def test_should_use_an_ubuntu_image(self):
|
|
21
|
+
# assert Testing.to_have_resource_with_properties(self.synthesized, Image.TF_RESOURCE_TYPE, {
|
|
22
|
+
# "name": "ubuntu:latest",
|
|
23
|
+
# })
|
|
24
|
+
|
|
25
|
+
# def test_check_validity(self):
|
|
26
|
+
# assert Testing.to_be_valid_terraform(Testing.full_synth(stack))
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
from constructs import Construct
|
|
3
|
+
from cdktn import App, TerraformStack
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MyStack(TerraformStack):
|
|
7
|
+
def __init__(self, scope: Construct, id: str):
|
|
8
|
+
super().__init__(scope, id)
|
|
9
|
+
|
|
10
|
+
# define resources here
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
app = App()
|
|
14
|
+
MyStack(app, "{{ $base }}")
|
|
15
|
+
|
|
16
|
+
app.synth()
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) HashiCorp, Inc.
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { execSync } = require('child_process');
|
|
7
|
+
const { chmodSync } = require('fs');
|
|
8
|
+
const { readFileSync, writeFileSync } = require('fs');
|
|
9
|
+
const os = require('os');
|
|
10
|
+
|
|
11
|
+
exports.pre = () => {
|
|
12
|
+
try {
|
|
13
|
+
if (os.platform() === 'win32') {
|
|
14
|
+
execSync('where pip3')
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
execSync('which pip3')
|
|
18
|
+
}
|
|
19
|
+
} catch {
|
|
20
|
+
console.error(`Unable to find "pip3".`)
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
exports.post = options => {
|
|
26
|
+
// Terraform Cloud configuration settings if the organization name and workspace is set.
|
|
27
|
+
if (options.OrganizationName != '') {
|
|
28
|
+
console.log(`\nGenerating Terraform Cloud configuration for '${options.OrganizationName}' organization and '${options.WorkspaceName}' workspace.....`)
|
|
29
|
+
terraformCloudConfig(options.$base, options.OrganizationName, options.WorkspaceName, options.TerraformRemoteHostname);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const pypi_cdktf = options.pypi_cdktf;
|
|
33
|
+
if (!pypi_cdktf) {
|
|
34
|
+
throw new Error(`missing context "pypi_cdktf"`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
writeFileSync('requirements.txt', pypi_cdktf + '\r\npytest\r\n', 'utf-8');
|
|
38
|
+
|
|
39
|
+
let installArgs = '';
|
|
40
|
+
if (!process.env.VIRTUAL_ENV) {
|
|
41
|
+
installArgs += '--user'
|
|
42
|
+
}
|
|
43
|
+
execSync(`pip3 install ${installArgs} -r requirements.txt`, { stdio: 'inherit' });
|
|
44
|
+
chmodSync('main.py', '700');
|
|
45
|
+
|
|
46
|
+
console.log(readFileSync('./help', 'utf-8'));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
function terraformCloudConfig(baseName, organizationName, workspaceName, terraformRemoteHostname) {
|
|
50
|
+
template = readFileSync('./main.py', 'utf-8');
|
|
51
|
+
|
|
52
|
+
const templateWithImports = template.replace(`from cdktn import App, TerraformStack`,
|
|
53
|
+
`from cdktn import App, TerraformStack, CloudBackend, NamedCloudWorkspace`)
|
|
54
|
+
|
|
55
|
+
const result = templateWithImports.replace(`MyStack(app, "${baseName}")`, `stack = MyStack(app, "${baseName}")
|
|
56
|
+
CloudBackend(stack,
|
|
57
|
+
hostname='${terraformRemoteHostname}',
|
|
58
|
+
organization='${organizationName}',
|
|
59
|
+
workspaces=NamedCloudWorkspace('${workspaceName}')
|
|
60
|
+
)`);
|
|
61
|
+
|
|
62
|
+
writeFileSync('./main.py', result, 'utf-8');
|
|
63
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"language": "python",
|
|
3
|
+
"app": "python3 ./main.py",
|
|
4
|
+
"projectId": "{{projectId}}",
|
|
5
|
+
"sendCrashReports": "{{sendCrashReports}}",
|
|
6
|
+
"terraformProviders": [],
|
|
7
|
+
"terraformModules": [],
|
|
8
|
+
"codeMakerOutput": "imports",
|
|
9
|
+
"context": {
|
|
10
|
+
{{futureFlags}}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
========================================================================================================
|
|
2
|
+
|
|
3
|
+
Your cdktn Python project is ready!
|
|
4
|
+
|
|
5
|
+
cat help Prints this message
|
|
6
|
+
|
|
7
|
+
Compile:
|
|
8
|
+
python3 ./main.py Compile and run the python code.
|
|
9
|
+
|
|
10
|
+
Synthesize:
|
|
11
|
+
cdktn synth [stack] Synthesize Terraform resources to cdktf.out/
|
|
12
|
+
|
|
13
|
+
Diff:
|
|
14
|
+
cdktn diff [stack] Perform a diff (terraform plan) for the given stack
|
|
15
|
+
|
|
16
|
+
Deploy:
|
|
17
|
+
cdktn deploy [stack] Deploy the given stack
|
|
18
|
+
|
|
19
|
+
Destroy:
|
|
20
|
+
cdktn destroy [stack] Destroy the given stack
|
|
21
|
+
|
|
22
|
+
Learn more about using modules and providers https://cdk.tf/modules-and-providers
|
|
23
|
+
|
|
24
|
+
Use Providers:
|
|
25
|
+
|
|
26
|
+
Use the add command to add both prebuilt providers (if available) or locally generated providers:
|
|
27
|
+
|
|
28
|
+
cdktn provider add "aws@~>3.0" null kreuzwerker/docker
|
|
29
|
+
|
|
30
|
+
You can find all prebuilt providers on PyPI: https://pypi.org/user/cdktn-team/
|
|
31
|
+
You can also add these providers directly to your requirements.txt file.
|
|
32
|
+
|
|
33
|
+
You can also build any module or provider locally. Learn more: https://cdk.tf/modules-and-providers
|
|
34
|
+
|
|
35
|
+
========================================================================================================
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from cdktn import Testing, TerraformStack
|
|
3
|
+
|
|
4
|
+
# The tests below are example tests, you can find more information at
|
|
5
|
+
# https://cdk.tf/testing
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestMain:
|
|
9
|
+
|
|
10
|
+
stack = TerraformStack(Testing.app(), "stack")
|
|
11
|
+
#app_abstraction = MyApplicationsAbstraction(stack, "app-abstraction")
|
|
12
|
+
#synthesized = Testing.synth(stack)
|
|
13
|
+
|
|
14
|
+
# def test_should_contain_container(self):
|
|
15
|
+
# assert Testing.to_have_resource(self.synthesized, Container.TF_RESOURCE_TYPE)
|
|
16
|
+
|
|
17
|
+
# def test_should_use_an_ubuntu_image(self):
|
|
18
|
+
# assert Testing.to_have_resource_with_properties(self.synthesized, Image.TF_RESOURCE_TYPE, {
|
|
19
|
+
# "name": "ubuntu:latest",
|
|
20
|
+
# })
|
|
21
|
+
|
|
22
|
+
# def test_check_validity(self):
|
|
23
|
+
# assert Testing.to_be_valid_terraform(Testing.full_synth(stack))
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
from constructs import Construct
|
|
3
|
+
from cdktn import App, TerraformStack
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MyStack(TerraformStack):
|
|
7
|
+
def __init__(self, scope: Construct, id: str):
|
|
8
|
+
super().__init__(scope, id)
|
|
9
|
+
|
|
10
|
+
# define resources here
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
app = App()
|
|
14
|
+
MyStack(app, "{{ $base }}")
|
|
15
|
+
|
|
16
|
+
app.synth()
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) HashiCorp, Inc.
|
|
3
|
+
* SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { execSync } = require("child_process");
|
|
7
|
+
const { readFileSync, writeFileSync } = require("fs");
|
|
8
|
+
|
|
9
|
+
exports.post = (ctx) => {
|
|
10
|
+
const silent = ctx.silent === "true" || ctx.silent === true;
|
|
11
|
+
// Terraform Cloud configuration settings if the organization name and workspace is set.
|
|
12
|
+
if (ctx.OrganizationName != "") {
|
|
13
|
+
if (!silent) {
|
|
14
|
+
console.log(
|
|
15
|
+
`\nGenerating Terraform Cloud configuration for '${ctx.OrganizationName}' organization and '${ctx.WorkspaceName}' workspace.....`
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
terraformCloudConfig(
|
|
19
|
+
ctx.$base,
|
|
20
|
+
ctx.OrganizationName,
|
|
21
|
+
ctx.WorkspaceName,
|
|
22
|
+
ctx.TerraformRemoteHostname
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const npm_cdktf = ctx.npm_cdktf;
|
|
27
|
+
if (!npm_cdktf) {
|
|
28
|
+
throw new Error(`missing context "npm_cdktf"`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
installDeps([npm_cdktf, `constructs@10`], false, silent);
|
|
32
|
+
installDeps(
|
|
33
|
+
["@types/node", "typescript", "jest", "@types/jest", "ts-jest", "ts-node"],
|
|
34
|
+
true,
|
|
35
|
+
silent
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
if (!silent) {
|
|
39
|
+
console.log(readFileSync("./help", "utf-8"));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function installDeps(deps, isDev, silent) {
|
|
44
|
+
const devDep = isDev ? "-D" : "";
|
|
45
|
+
// make sure we're installing dev dependencies as well
|
|
46
|
+
const env = Object.assign({}, process.env);
|
|
47
|
+
env["NODE_ENV"] = "development";
|
|
48
|
+
|
|
49
|
+
execSync(`npm install ${devDep} ${deps.join(" ")}`, {
|
|
50
|
+
stdio: silent ? "ignore" : "inherit",
|
|
51
|
+
env,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function terraformCloudConfig(
|
|
56
|
+
baseName,
|
|
57
|
+
organizationName,
|
|
58
|
+
workspaceName,
|
|
59
|
+
terraformRemoteHostname
|
|
60
|
+
) {
|
|
61
|
+
template = readFileSync("./main.ts", "utf-8");
|
|
62
|
+
|
|
63
|
+
result = template.replace(
|
|
64
|
+
`import { App, TerraformStack } from "cdktn";`,
|
|
65
|
+
`import { App, TerraformStack, CloudBackend, NamedCloudWorkspace } from "cdktn";`
|
|
66
|
+
);
|
|
67
|
+
result = result.replace(
|
|
68
|
+
`new MyStack(app, "${baseName}");`,
|
|
69
|
+
`const stack = new MyStack(app, "${baseName}");
|
|
70
|
+
new CloudBackend(stack, {
|
|
71
|
+
hostname: "${terraformRemoteHostname}",
|
|
72
|
+
organization: "${organizationName}",
|
|
73
|
+
workspaces: new NamedCloudWorkspace("${workspaceName}")
|
|
74
|
+
});`
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
writeFileSync("./main.ts", result, "utf-8");
|
|
78
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Copyright (c) HashiCorp, Inc
|
|
2
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
3
|
+
import "cdktn/lib/testing/adapters/jest"; // Load types for expect matchers
|
|
4
|
+
// import { Testing } from "cdktn";
|
|
5
|
+
|
|
6
|
+
describe("My CDKTN Application", () => {
|
|
7
|
+
// The tests below are example tests, you can find more information at
|
|
8
|
+
// https://cdk.tf/testing
|
|
9
|
+
it.todo("should be tested");
|
|
10
|
+
|
|
11
|
+
// // All Unit tests test the synthesised terraform code, it does not create real-world resources
|
|
12
|
+
// describe("Unit testing using assertions", () => {
|
|
13
|
+
// it("should contain a resource", () => {
|
|
14
|
+
// // import { Image,Container } from "./.gen/providers/docker"
|
|
15
|
+
// expect(
|
|
16
|
+
// Testing.synthScope((scope) => {
|
|
17
|
+
// new MyApplicationsAbstraction(scope, "my-app", {});
|
|
18
|
+
// })
|
|
19
|
+
// ).toHaveResource(Container);
|
|
20
|
+
|
|
21
|
+
// expect(
|
|
22
|
+
// Testing.synthScope((scope) => {
|
|
23
|
+
// new MyApplicationsAbstraction(scope, "my-app", {});
|
|
24
|
+
// })
|
|
25
|
+
// ).toHaveResourceWithProperties(Image, { name: "ubuntu:latest" });
|
|
26
|
+
// });
|
|
27
|
+
// });
|
|
28
|
+
|
|
29
|
+
// describe("Unit testing using snapshots", () => {
|
|
30
|
+
// it("Tests the snapshot", () => {
|
|
31
|
+
// const app = Testing.app();
|
|
32
|
+
// const stack = new TerraformStack(app, "test");
|
|
33
|
+
|
|
34
|
+
// new TestProvider(stack, "provider", {
|
|
35
|
+
// accessKey: "1",
|
|
36
|
+
// });
|
|
37
|
+
|
|
38
|
+
// new TestResource(stack, "test", {
|
|
39
|
+
// name: "my-resource",
|
|
40
|
+
// });
|
|
41
|
+
|
|
42
|
+
// expect(Testing.synth(stack)).toMatchSnapshot();
|
|
43
|
+
// });
|
|
44
|
+
|
|
45
|
+
// it("Tests a combination of resources", () => {
|
|
46
|
+
// expect(
|
|
47
|
+
// Testing.synthScope((stack) => {
|
|
48
|
+
// new TestDataSource(stack, "test-data-source", {
|
|
49
|
+
// name: "foo",
|
|
50
|
+
// });
|
|
51
|
+
|
|
52
|
+
// new TestResource(stack, "test-resource", {
|
|
53
|
+
// name: "bar",
|
|
54
|
+
// });
|
|
55
|
+
// })
|
|
56
|
+
// ).toMatchInlineSnapshot();
|
|
57
|
+
// });
|
|
58
|
+
// });
|
|
59
|
+
|
|
60
|
+
// describe("Checking validity", () => {
|
|
61
|
+
// it("check if the produced terraform configuration is valid", () => {
|
|
62
|
+
// const app = Testing.app();
|
|
63
|
+
// const stack = new TerraformStack(app, "test");
|
|
64
|
+
|
|
65
|
+
// new TestDataSource(stack, "test-data-source", {
|
|
66
|
+
// name: "foo",
|
|
67
|
+
// });
|
|
68
|
+
|
|
69
|
+
// new TestResource(stack, "test-resource", {
|
|
70
|
+
// name: "bar",
|
|
71
|
+
// });
|
|
72
|
+
// expect(Testing.fullSynth(app)).toBeValidTerraform();
|
|
73
|
+
// });
|
|
74
|
+
|
|
75
|
+
// it("check if this can be planned", () => {
|
|
76
|
+
// const app = Testing.app();
|
|
77
|
+
// const stack = new TerraformStack(app, "test");
|
|
78
|
+
|
|
79
|
+
// new TestDataSource(stack, "test-data-source", {
|
|
80
|
+
// name: "foo",
|
|
81
|
+
// });
|
|
82
|
+
|
|
83
|
+
// new TestResource(stack, "test-resource", {
|
|
84
|
+
// name: "bar",
|
|
85
|
+
// });
|
|
86
|
+
// expect(Testing.fullSynth(app)).toPlanSuccessfully();
|
|
87
|
+
// });
|
|
88
|
+
// });
|
|
89
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
========================================================================================================
|
|
2
|
+
|
|
3
|
+
Your CDKTN TypeScript project is ready!
|
|
4
|
+
|
|
5
|
+
cat help Print this message
|
|
6
|
+
|
|
7
|
+
Compile:
|
|
8
|
+
npm run get Import/update Terraform providers and modules (you should check-in this directory)
|
|
9
|
+
npm run compile Compile typescript code to javascript (or "npm run watch")
|
|
10
|
+
npm run watch Watch for changes and compile typescript in the background
|
|
11
|
+
npm run build Compile typescript
|
|
12
|
+
|
|
13
|
+
Synthesize:
|
|
14
|
+
cdktn synth [stack] Synthesize Terraform resources from stacks to cdktf.out/ (ready for 'terraform apply')
|
|
15
|
+
|
|
16
|
+
Diff:
|
|
17
|
+
cdktn diff [stack] Perform a diff (terraform plan) for the given stack
|
|
18
|
+
|
|
19
|
+
Deploy:
|
|
20
|
+
cdktn deploy [stack] Deploy the given stack
|
|
21
|
+
|
|
22
|
+
Destroy:
|
|
23
|
+
cdktn destroy [stack] Destroy the stack
|
|
24
|
+
|
|
25
|
+
Test:
|
|
26
|
+
npm run test Runs unit tests (edit __tests__/main-test.ts to add your own tests)
|
|
27
|
+
npm run test:watch Watches the tests and reruns them on change
|
|
28
|
+
|
|
29
|
+
Upgrades:
|
|
30
|
+
npm run upgrade Upgrade cdktn modules to latest version
|
|
31
|
+
npm run upgrade:next Upgrade cdktn modules to latest "@next" version (last commit)
|
|
32
|
+
|
|
33
|
+
Use Providers:
|
|
34
|
+
|
|
35
|
+
You can add prebuilt providers (if available) or locally generated ones using the add command:
|
|
36
|
+
|
|
37
|
+
cdktn provider add "aws@~>3.0" null kreuzwerker/docker
|
|
38
|
+
|
|
39
|
+
You can find all prebuilt providers on npm: https://www.npmjs.com/search?q=keywords:cdktf
|
|
40
|
+
You can also install these providers directly through npm:
|
|
41
|
+
|
|
42
|
+
npm install @cdktn/provider-aws
|
|
43
|
+
npm install @cdktn/provider-google
|
|
44
|
+
npm install @cdktn/provider-azurerm
|
|
45
|
+
npm install @cdktn/provider-docker
|
|
46
|
+
npm install @cdktn/provider-github
|
|
47
|
+
npm install @cdktn/provider-null
|
|
48
|
+
|
|
49
|
+
You can also build any module or provider locally. Learn more https://cdk.tf/modules-and-providers
|
|
50
|
+
|
|
51
|
+
========================================================================================================
|