-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
119 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const { execSync } = require('child_process'); | ||
const { chmodSync } = require('fs'); | ||
const { readFileSync, writeFileSync } = require('fs'); | ||
|
||
const cli = require.resolve('../../bin/cdktf'); | ||
|
||
exports.pre = () => { | ||
try { | ||
execSync('which pip') | ||
} catch { | ||
console.error(`Unable to find "pip".`) | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
exports.post = options => { | ||
// Terraform Cloud configuration settings if the organization name and workspace is set. | ||
if (options.OrganizationName != '') { | ||
console.log(`\nGenerating Terraform Cloud configuration for '${options.OrganizationName}' organization and '${options.WorkspaceName}' workspace.....`) | ||
terraformCloudConfig(options.$base, options.OrganizationName, options.WorkspaceName) | ||
} | ||
|
||
const pypi_cdktf = options.pypi_cdktf; | ||
if (!pypi_cdktf) { | ||
throw new Error(`missing context "pypi_cdktf"`); | ||
} | ||
|
||
writeFileSync('requirements.txt', pypi_cdktf, 'utf-8'); | ||
execSync('pip install -r requirements.txt', { stdio: 'inherit' }); | ||
chmodSync('main.py', '700'); | ||
|
||
execSync(`${cli} get`, { stdio: 'inherit' }); | ||
execSync(`python3 ./main.py`); | ||
|
||
console.log(readFileSync('./help', 'utf-8')); | ||
}; | ||
|
||
function terraformCloudConfig(baseName, organizationName, workspaceName) { | ||
template = readFileSync('./main.py', 'utf-8'); | ||
|
||
const result = template.replace(`MyStack(app, "${baseName}")`, `stack = MyStack(app, "${baseName}") | ||
stack.add_override('terraform.backend', { | ||
'remote': { | ||
'hostname': 'app.terraform.io', | ||
'organization': '${organizationName}', | ||
'workspaces': { | ||
'name': '${workspaceName}' | ||
} | ||
} | ||
})`); | ||
|
||
writeFileSync('./main.py', result, 'utf-8'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"language": "python", | ||
"app": "python3 ./main.py", | ||
"terraformProviders": ["aws@~> 2.0"], | ||
"codeMakerOutput": "imports" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
======================================================================================================== | ||
|
||
Your cdktf Python project is ready! | ||
|
||
cat help Prints this message | ||
|
||
Compile: | ||
python3 ./main.py Compile and run the python code. | ||
|
||
Synthesize: | ||
cdktf synth Synthesize Terraform resources to cdktf.out/ | ||
|
||
Diff: | ||
cdktf diff Perform a diff (terraform plan) for the given stack | ||
|
||
Deploy: | ||
cdktf deploy Deploy the given stack | ||
|
||
Destroy: | ||
cdktf destroy Destroy the given stack | ||
|
||
======================================================================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env python | ||
from constructs import Construct | ||
from cdktf import App, TerraformStack | ||
|
||
|
||
class MyStack(TerraformStack): | ||
def __init__(self, scope: Construct, ns: str): | ||
super().__init__(scope, ns) | ||
|
||
# define resources here | ||
|
||
|
||
app = App() | ||
MyStack(app, "{{ $base }}") | ||
|
||
app.synth() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dist/ | ||
imports/* | ||
!imports/__init__.py | ||
.terraform | ||
cdktf.out | ||
terraform.tfstate* |