Skip to content

Commit

Permalink
Merge pull request #1248 from hashicorp/rework-namespaces
Browse files Browse the repository at this point in the history
fix(lib): Rework AWS Provider Namespacing
  • Loading branch information
ansgarm authored Nov 9, 2021
2 parents 3dad320 + a3c60f0 commit 7c82308
Show file tree
Hide file tree
Showing 27 changed files with 405,975 additions and 173,594 deletions.
44 changes: 44 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
## Unreleased

**Breaking Changes**

### Namespaced AWS Provider Resources [#1248](https://github.com/hashicorp/terraform-cdk/pull/1248)

We iterated on the namespacing for the AWS provider which got introduced in [#1101](https://github.com/hashicorp/terraform-cdk/issues/1101). Our goal was, to enable custom L2 / L3 abstractions being built with jsii, improve the general jsii support for the namespacing and last but not least to allow both namespace and barrel imports in Typescript. A welcome side effect is a 5x performance gain when building packages via jsii for Python (from ~ 16 minutes to ~ 3 minutes) and likely other targets such as Java or C#

As a result, there are a few minor breaking changes:

- Namespaces are all lowercased now, without a separating character
- Namespaces are all a single word now (e.g. `DynamoDb` used to be `dynamo_db` in Python - it's now just `dynamodb`)
- `CloudwatchEventBridge` namespace got renamed to `eventbridge`

#### Typescript Example

##### Before

This was pretty much the only way to use the namespaced provider classes.

```ts
import { CloudFront } from "@cdktf/provider-aws";

new CloudFront.CloudfrontDistribution(this, "cloudfront", {});
```

##### After

Now it's possible to either import the entire namespace, or a resource class directly.

```ts
// Similar to before, but namespace is lowercased
import { cloudfront } from "@cdktf/provider-aws";

new cloudfront.CloudfrontDistribution(this, "cloudfront", {});

// new option
import { CloudfrontDistribution } from "@cdktf/provider-aws/lib/cloudfront";

new CloudfrontDistribution(this, "cloudfront", {});
```

See this [Pull Request](https://github.com/hashicorp/terraform-cdk/pull/1248) for more details.

## 0.7.0 (October 19, 2021)

**Breaking Changes**
Expand Down
4 changes: 2 additions & 2 deletions examples/csharp/aws/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using aws;
using aws.DataSources;
using aws.DynamoDb;
using aws.Datasources;
using aws.Dynamodb;
using aws.Sns;
using Constructs;
using HashiCorp.Cdktf;
Expand Down
6 changes: 3 additions & 3 deletions examples/java/aws/src/main/java/com/mycompany/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import com.hashicorp.cdktf.TerraformStack;

import imports.aws.AwsProvider;
import imports.aws.data_sources.DataAwsRegion;
import imports.aws.dynamo_db.DynamodbTable;
import imports.aws.dynamo_db.DynamodbTableAttribute;
import imports.aws.datasources.DataAwsRegion;
import imports.aws.dynamodb.DynamodbTable;
import imports.aws.dynamodb.DynamodbTableAttribute;
import imports.aws.sns.SnsTopic;
import software.constructs.Construct;

Expand Down
2 changes: 1 addition & 1 deletion examples/python/aws-eks/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# for terraform provider
from imports.aws import AwsProvider
from imports.aws.data_sources import DataAwsCallerIdentity
from imports.aws.datasources import DataAwsCallerIdentity

# for terraform module
from imports.vpc import Vpc
Expand Down
2 changes: 1 addition & 1 deletion examples/python/aws/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from imports.aws import AwsProvider
from imports.aws.sns import SnsTopic
from imports.terraform_aws_modules.aws import Vpc
from imports.aws.lambda_function import LambdaFunction
from imports.aws.lambdafunction import LambdaFunction
from imports.aws.iam import IamRole


Expand Down
62 changes: 56 additions & 6 deletions examples/typescript/aws-cloudfront-proxy/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { Construct } from "constructs";
import { App, TerraformStack, TerraformOutput } from "cdktf";
import { CloudFront, AwsProvider, Route53, ACM } from "./.gen/providers/aws";
import {
cloudfront,
AwsProvider,
route53,
acm,
wafv2,
} from "./.gen/providers/aws";

class MyStack extends TerraformStack {
constructor(scope: Construct, ns: string) {
Expand All @@ -19,7 +25,51 @@ class MyStack extends TerraformStack {
alias: "route53",
});

const cert = new ACM.AcmCertificate(this, "cert", {
new wafv2.Wafv2WebAcl(this, "wafv2", {
defaultAction: {
allow: {},
},
name: "managed-rule-example",
scope: "REGIONAL",
visibilityConfig: {
cloudwatchMetricsEnabled: true,
metricName: "managed-rule-example",
sampledRequestsEnabled: true,
},
rule: [
{
name: "managed-rule-example",
priority: 1,
overrideAction: {
count: {},
},
visibilityConfig: {
cloudwatchMetricsEnabled: true,
metricName: "managed-rule-example",
sampledRequestsEnabled: true,
},
statement: {
managedRuleGroupStatement: {
name: "managed-rule-example",
vendorName: "AWS",
excludedRule: [
{
name: "SizeRestrictions_QUERYSTRING",
},
{ name: "SQLInjection_QUERYSTRING" },
],
scopeDownStatement: {
geoMatchStatement: {
countryCodes: ["US"],
},
},
},
},
},
],
});

const cert = new acm.AcmCertificate(this, "cert", {
domainName,
validationMethod: "DNS",
provider,
Expand All @@ -30,7 +80,7 @@ class MyStack extends TerraformStack {
// privateZone: false
// })

const record = new Route53.Route53Record(this, "CertValidationRecord", {
const record = new route53.Route53Record(this, "CertValidationRecord", {
name: cert.domainValidationOptions("0").resourceRecordName,
type: cert.domainValidationOptions("0").resourceRecordType,
records: [cert.domainValidationOptions("0").resourceRecordValue],
Expand All @@ -40,13 +90,13 @@ class MyStack extends TerraformStack {
allowOverwrite: true,
});

new ACM.AcmCertificateValidation(this, "certvalidation", {
new acm.AcmCertificateValidation(this, "certvalidation", {
certificateArn: cert.arn,
validationRecordFqdns: [record.fqdn],
provider,
});

const distribution = new CloudFront.CloudfrontDistribution(
const distribution = new cloudfront.CloudfrontDistribution(
this,
"cloudfront",
{
Expand Down Expand Up @@ -115,7 +165,7 @@ class MyStack extends TerraformStack {
}
);

new Route53.Route53Record(this, "distribution_domain", {
new route53.Route53Record(this, "distribution_domain", {
name: domainName,
type: "A",
// zoneId: zone.zoneId,
Expand Down
4 changes: 2 additions & 2 deletions examples/typescript/aws-multiple-stacks/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Construct } from "constructs";
import { App, TerraformStack } from "cdktf";
import { AwsProvider, EC2 } from "./.gen/providers/aws";
import { AwsProvider, ec2 } from "./.gen/providers/aws";

interface MyStackConfig {
environment: string;
Expand All @@ -17,7 +17,7 @@ class MyStack extends TerraformStack {
region,
});

new EC2.Instance(this, "Hello", {
new ec2.Instance(this, "Hello", {
ami: "ami-2757f631",
instanceType: "t2.micro",
tags: {
Expand Down
4 changes: 2 additions & 2 deletions examples/typescript/backends/s3/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
S3Backend,
DataTerraformRemoteStateS3,
} from "cdktf";
import { AwsProvider, S3 } from "./.gen/providers/aws";
import { AwsProvider, s3 } from "./.gen/providers/aws";

class MyStack extends TerraformStack {
constructor(scope: Construct, name: string) {
Expand All @@ -31,7 +31,7 @@ class MyStack extends TerraformStack {
});

// Reference Remote State
new S3.DataAwsS3BucketObject(this, "object", {
new s3.DataAwsS3BucketObject(this, "object", {
bucket: "objectbucket",
key: otherState.get("bucket_key"),
});
Expand Down
Loading

0 comments on commit 7c82308

Please sign in to comment.