Install Pipenv using Homebrew by running:
$ brew install pipenv
You can install Pipenv by visiting the website.
Install project dependencies
pipenv install
Generate CDK for Terraform constructs for Terraform provides and modules used in the project.
cdktf get
You can now edit the main.py
file if you want to modify any code.
#!/usr/bin/env python
from constructs import Construct
from cdktf import App, TerraformStack
from imports.docker import Image, Container
class MyStack(TerraformStack):
def __init__(self, scope: Construct, ns: str):
super().__init__(scope, ns)
docker_image = Image(self, 'nginx-latest', name='nginx:latest', keep_locally=False)
Container(self, 'nginx-cdktf', name='nginx-python-cdktf',
image=docker_image.name, ports=[
{
'internal': 80,
'external': 8000
}], privileged=False)
app = App()
MyStack(app, "python-docker")
app.synth()
Compile and generate Terraform configuration
cdktf synth
The above command will create a folder called cdktf.out
that contains all Terraform JSON configuration that was generated.
Run Terraform commands
cd cdktf.out
terraform init
terraform plan
terraform apply
OR
cdktf deploy