-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API to interact with terraform cli #237
Comments
The general idea of this is quite appealing to me. However, At the moment, the In the I think a similar concept could work for #219 |
Maybe we can use terraform-exec to interact with synthesized outputs from the stack? |
Since terraform-exec is a go module, it's not the best fit for this project since it's mostly written in Typescript. We sort of built something similar in Typescript. |
Mind sharing the link or is it not publicly avaiable? |
Was playing around with this a bit. While it requires the usage of JS / Typescript, it's sort of possible to drive synth and deploy / destroy bypassing the full deployimport { SynthStack } from 'cdktf-cli/bin/cmds/helper/synth-stack';
import { TerraformCli } from 'cdktf-cli/bin/cmds/ui/models/terraform-cli';
const setup = async () => {
const stacks = await SynthStack.synth('node stack.js', 'cdktf.test.out');
const cli = new TerraformCli(stacks[0]);
await cli.init();
await cli.deploy('', (chunk: Buffer) => (console.log(chunk.toString('utf-8'))));
}
(async function() { await setup() } ()); destroyimport { SynthStack } from 'cdktf-cli/bin/cmds/helper/synth-stack';
import { TerraformCli } from 'cdktf-cli/bin/cmds/ui/models/terraform-cli';
const teardown = async () => {
const stacks = await SynthStack.synth('node stack.js', 'cdktf.test.out');
const cli = new TerraformCli(stacks[0]);
await cli.init();
await cli.destroy((chunk: Buffer) => (console.log(chunk.toString('utf-8'))));
}
(async function() { await teardown() } ()); I'm using this right now for driving automated test setups / teardowns. Since this skips generating the plan and is running headless, it's also a bit faster compared to using the |
@skorfmann I think this would be a great feature, it would mirror some of the functionality available in pulumi with its API. Is there a potential python approach to your sample? |
Since the CLI is written in Typescript only, I don't think there's a similar way to do this right now - except for shelling out und using the cli directly. However, cross language support for programmatic interaction is something we'd like to address - but I can't give you an ETA on that. |
Took a bit of time, but I managed to play around with JSII and add the necessary files into a local cdktf package, its not clear and I've probably brutalised it somewhat but I've got the following working in python; def main():
app = App()
tfStack = MyStack(app, "python-cdk", GCP_PROJECT_NAME)
app.synth()
stack = SynthesizedStack(**tfStack.get_stack_args())
cli = TerraformCli(stack=stack)
print(cli.version())
# print(cli.init())
# plan = cli.plan()
# print(plan)
# print(cli.deploy())
# print(cli.destroy()) |
Thanks for these examples @skorfmann! This is my new favorite way to use CDKTF. I'd love to see a more formal API... A few things from my experience that would help this...
Looking forward to seeing this evolve. This is the most excited I've been about IaC in a while. |
Just to add to this issue, though it's not anything other than more justification: Pulumi works with the automation API but hesitant to commit to using it when both AWS CDK, and Terraform CDK are maturing and both offer advantages (already a Terraform Cloud customer at work and cloudformation state in AWS appeals in some scenarios). AWS CDK still doesn't have a programmatic interface, and the demo example from @drandell looks promising - though as cited, you'd want a formalised API before taking this into production. Ideally the interface would allow you to run a stack synth, stack deploy and then take the outputs from the resolved deployed stack to do something with (insertion into dynamo/webhooks for notification of deployment and triggering an email etc). |
This comment was marked as off-topic.
This comment was marked as off-topic.
@JayDoubleu Sounds good, using Pulumi cloud for state or S3 etc? |
This comment was marked as off-topic.
This comment was marked as off-topic.
As a follow up, Pulumi is agonisingly slow to resolve changes compared to CDKTF so guess I'll be hoping this "automation API" can be formalised soonish. |
Hi All, please suggest |
Hi all, |
@anamitra-saikia : No workaround yet and havent implemented . |
Community Note
Description
It would be very useful to have an API to interact with terraform cli (not cloud) from cdk.
Example below:
References
#225
The text was updated successfully, but these errors were encountered: