Skip to content
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

Generate More Python Examples #207

Closed
skorfmann opened this issue Jul 18, 2020 · 2 comments
Closed

Generate More Python Examples #207

skorfmann opened this issue Jul 18, 2020 · 2 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request language/python language/typescript priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. size/medium estimated < 1 week

Comments

@skorfmann
Copy link
Contributor

skorfmann commented Jul 18, 2020

jsii-rosetta could be used to generate Python examples from the Typescript examples.

While the typescript-aws example doesn't compile cleanly ("arrow functions are not supported"), it would be easy to fix that. The cloudfront example compiles cleanly.

Expand for generated Python code

from constructs import Construct
from cdktf import App, TerraformStack, TerraformOutput
from ...gen.providers.aws import CloudfrontDistribution, AcmCertificate, Route53Record, AcmCertificateValidation, AwsProvider

class MyStack(TerraformStack):
    def __init__(self, scope, ns):
        super().__init__(scope, ns)

        origin_id = "myS3Origin"
        domain_name = "www.example.com"
        proxy_target = "example.com"

        AwsProvider(self, "aws",
            region="eu-central-1"
        )

        provider = AwsProvider(self, "aws.route53",
            region="us-east-1",
            alias="route53"
        )

        cert = AcmCertificate(self, "cert",
            domain_name=domain_name,
            validation_method="DNS",
            provider=provider
        )

        # const zone = new DataAwsRoute53Zone(this, 'zone', {
        #   name: 'example.com.',
        #   privateZone: false
        # })

        record = Route53Record(self, "CertValidationRecord",
            name=cert.domain_validation_options("0").domain_name,
            type=cert.domain_validation_options("0").resource_record_type,
            records=[
                cert.domain_validation_options("0").resource_record_value
            ],
            # zoneId: zone.zoneId,
            zone_id="123",
            ttl=60,
            allow_overwrite=True
        )

        AcmCertificateValidation(self, "certvalidation",
            certificate_arn=cert.arn,
            validation_record_fqdns=[record.fqdn],
            provider=provider
        )

        distribution = CloudfrontDistribution(self, "cloudfront",
            enabled=True,
            is_ipv6_enabled=True,

            viewer_certificate=[CloudfrontDistributionViewerCertificate(
                acm_certificate_arn=cert.arn,
                ssl_support_method="sni-only"
            )],

            restrictions=[CloudfrontDistributionRestrictions(
                geo_restriction=[CloudfrontDistributionRestrictionsGeoRestriction(
                    restriction_type="none"
                )]
            )],

            origin=[CloudfrontDistributionOrigin(
                origin_id=origin_id,
                domain_name=proxy_target,
                custom_origin_config=[CloudfrontDistributionOriginCustomOriginConfig(
                    http_port=80,
                    https_port=443,
                    origin_protocol_policy="http-only",
                    origin_ssl_protocols=["TLSv1.2", "TLSv1.1"]
                )]
            )],

            aliases=[domain_name
            ],

            default_cache_behavior=[CloudfrontDistributionDefaultCacheBehavior(
                min_ttl=0,
                default_ttl=60,
                max_ttl=86400,
                allowed_methods=["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"],
                cached_methods=["GET", "HEAD"],
                target_origin_id=origin_id,
                viewer_protocol_policy="redirect-to-https",
                forwarded_values=[CloudfrontDistributionDefaultCacheBehaviorForwardedValues(
                    cookies=[CloudfrontDistributionDefaultCacheBehaviorForwardedValuesCookies(
                        forward="all"
                    )],
                    headers=["Host", "Accept-Datetime", "Accept-Encoding", "Accept-Language", "User-Agent", "Referer", "Origin", "X-Forwarded-Host"],
                    query_string=True
                )]
            )]
        )

        Route53Record(self, "distribution_domain",
            name=domain_name,
            type="A",
            # zoneId: zone.zoneId,
            zone_id="123",
            alias=[Route53RecordAlias(
                name=distribution.domain_name,
                zone_id=distribution.hosted_zone_id,
                evaluate_target_health=True
            )]
        )

        TerraformOutput(self, "distribution_domain_name",
            value=distribution.domain_name
        )

app = App()
MyStack(app, "typescript-aws-cloudfront-proxy")
app.synth()

The examples could be restructured a bit so that only Typescript examples are maintained. In an additional build step, Python and later on C# / Java / ... could be automatically generated.

@DanielMSchmidt DanielMSchmidt added documentation Improvements or additions to documentation priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. size/medium estimated < 1 week labels Dec 7, 2021
@ansgarm
Copy link
Member

ansgarm commented Nov 23, 2022

Closing this, as we have quite a few Python examples now in our repo. We also have a HashiCorp Developer Tutorial in Python and an end-to-end serverless example in Python.

@ansgarm ansgarm closed this as completed Nov 23, 2022
@github-actions
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation enhancement New feature or request language/python language/typescript priority/important-longterm Medium priority, to be worked on within the following 1-2 business quarters. size/medium estimated < 1 week
Projects
None yet
Development

No branches or pull requests

3 participants