hashicorp / terraform-cdk

Define infrastructure resources using programming constructs and provision them using HashiCorp Terraform
https://www.terraform.io/cdktf
Mozilla Public License 2.0
4.8k stars 443 forks source link

More examples using inheritance in Python for CDKTF #432

Open cesarpball opened 3 years ago

cesarpball commented 3 years ago

Community Note

Description

Would be nice if more examples are added to show the real potential of using CDK with Terraform like Python Inheritance

References

No references

skorfmann commented 3 years ago

Do you have a specific case in mind?

cmclaughlin commented 3 years ago

I have a base class that extends TerraformStack where I setup Terraform state on S3 with DynamoDB locking - that way I don't have to do it in every stack. The bucket/table name is company-specific, but I suppose that's the sort of thing that you'd like in an example?

cesarpball commented 3 years ago

Do you have a specific case in mind?

For example, have the following structure:

Jenkinsfile Pipfile.lock cdktf.out imports templates eks.py iam.py Pipfile cdktf.json help main.py

Then in main.py

class MyStack (TerraformStack, EKSClass, IAMClass):

And use those class in the main one

cesarpball commented 3 years ago

I have a base class that extends TerraformStack where I setup Terraform state on S3 with DynamoDB locking - that way I don't have to do it in every stack. The bucket/table name is company-specific, but I suppose that's the sort of thing that you'd like in an example?

That would be a great way to point on the Documentation!

bafonso commented 3 years ago

I have a base class that extends TerraformStack where I setup Terraform state on S3 with DynamoDB locking - that way I don't have to do it in every stack. The bucket/table name is company-specific, but I suppose that's the sort of thing that you'd like in an example?

@cmclaughlin I'd love to use this.. as of now I am still struggling with doing this the normal way :-D

teamdts commented 3 years ago

expected below two example

  1. create Iam User , role , policy ,group, download iam user access key , credential
  2. create Ec2 instance , assign role,policy ,upload ssh key/generate ssh key , download key
1oglop1 commented 2 years ago

I've been also looking for examples with IAM because the AWS CDK IAM API is the main selling point for me. Especially when compared to what terraform/cloudformation offers right now. I was wondering if I could use libs from CDK that implement https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.IGrantable.html instead of terraform specific libraries.

jsteinich commented 2 years ago

I've been also looking for examples with IAM because the AWS CDK IAM API is the main selling point for me. Especially when compared to what terraform/cloudformation offers right now. I was wondering if I could use libs from CDK that implement https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.IGrantable.html instead of terraform specific libraries.

Not at this time. It is possible to use iam floyd by adding a small wrapper to your code.

1oglop1 commented 2 years ago

I've been also looking for examples with IAM because the AWS CDK IAM API is the main selling point for me. Especially when compared to what terraform/cloudformation offers right now. I was wondering if I could use libs from CDK that implement https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-iam.IGrantable.html instead of terraform specific libraries.

Not at this time. It is possible to use iam floyd by adding a small wrapper to your code.

Wow thank you, this is what I needed! I was hacking my own version with Pydantic but having someone who can dedicate the time developing this is great!