Skip to content

Commit

Permalink
feat(lib): use objects instead of objects in arrays if possible
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This changes the API surface of every module / provider

Closes #258
  • Loading branch information
DanielMSchmidt committed Aug 27, 2021
1 parent 125f5e3 commit 3727cf6
Show file tree
Hide file tree
Showing 25 changed files with 1,700 additions and 8,724 deletions.
8 changes: 3 additions & 5 deletions examples/csharp/aws/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ public MyApp(Construct scope, string id) : base(scope, id)
DynamodbTable table = new DynamodbTable(this, "Hello", new DynamodbTableConfig {
Name = $"my-first-table-{region.Name}",
HashKey = "temp",
Attribute = new [] {
new DynamodbTableAttribute {
Name = "id",
Type = "S"
}
Attribute = new DynamodbTableAttribute {
Name = "id",
Type = "S"
},
BillingMode = "PAY_PER_REQUEST"
});
Expand Down
2 changes: 1 addition & 1 deletion examples/csharp/azure/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MyApp : TerraformStack
public MyApp(Construct scope, string id) : base(scope, id)
{
new AzurermProvider(this, "AzureRm", new AzurermProviderConfig {
Features = new []{new AzurermProviderFeatures()}
Features = new AzurermProviderFeatures()
});

new VirtualNetwork(this, "TfVnet", new VirtualNetworkConfig {
Expand Down
16 changes: 5 additions & 11 deletions examples/csharp/google/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,13 @@ public MyApp(Construct scope, string id) : base(scope, id)
new ComputeInstance(this, "ComputeInstance", new ComputeInstanceConfig {
Name = "cdktf-instance",
MachineType = "f1-micro",
BootDisk = new [] {
new ComputeInstanceBootDisk {
InitializeParams = new [] {
new ComputeInstanceBootDiskInitializeParams {
Image = "debian-cloud/debian-9"
}
}
BootDisk = new ComputeInstanceBootDisk {
InitializeParams = new ComputeInstanceBootDiskInitializeParams {
Image = "debian-cloud/debian-9"
}
},
NetworkInterface = new [] {
new ComputeInstanceNetworkInterface {
Network = network.Name
}
NetworkInterface = new ComputeInstanceNetworkInterface {
Network = network.Name
},
Tags = new [] {
"web",
Expand Down
28 changes: 11 additions & 17 deletions examples/go/google/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ func NewMyStack(scope constructs.Construct, id string) cdktf.TerraformStack {
google.NewContainerNodePool(stack, jsii.String("main-pool"), &google.ContainerNodePoolConfig{
Name: jsii.String("main"),
Cluster: cluster.Name(),
NodeConfig: &[]*google.ContainerNodePoolNodeConfig{
{
MachineType: jsii.String("e2-medium"),
Preemptible: jsii.Bool(true),
ServiceAccount: sa.Email(),
OauthScopes: &[]*string{jsii.String("https://www.googleapis.com/auth/cloud-platform")},
},
NodeConfig: &google.ContainerNodePoolNodeConfig{
MachineType: jsii.String("e2-medium"),
Preemptible: jsii.Bool(true),
ServiceAccount: sa.Email(),
OauthScopes: &[]*string{jsii.String("https://www.googleapis.com/auth/cloud-platform")},
},
})

Expand All @@ -63,20 +61,16 @@ func NewMyStack(scope constructs.Construct, id string) cdktf.TerraformStack {

namespaceName := "development"
kubernetes.NewNamespace(stack, jsii.String("namespace"), &kubernetes.NamespaceConfig{
Metadata: &[]*kubernetes.NamespaceMetadata{
{
Name: jsii.String(namespaceName),
},
Metadata: &kubernetes.NamespaceMetadata{
Name: jsii.String(namespaceName),
},
})

helm.NewHelmProvider(stack, jsii.String("helm"), &helm.HelmProviderConfig{
Kubernetes: &[]*helm.HelmProviderKubernetes{
{
ClusterCaCertificate: auth.ClusterCaCertificateOutput(),
Host: auth.HostOutput(),
Token: auth.TokenOutput(),
},
Kubernetes: &helm.HelmProviderKubernetes{
ClusterCaCertificate: auth.ClusterCaCertificateOutput(),
Host: auth.HostOutput(),
Token: auth.TokenOutput(),
},
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Main(final Construct scope, final String id) {
super(scope, id);

AzurermProvider.Builder.create(this, "AzureRm")
.features(Arrays.asList(AzurermProviderFeatures.builder().build()))
.features(AzurermProviderFeatures.builder().build())
.build();

VirtualNetwork.Builder.create(this, "TfVnet")
Expand Down
12 changes: 6 additions & 6 deletions examples/java/google/src/main/java/com/mycompany/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public Main(final Construct scope, final String id) throws IOException {
ComputeInstance.Builder.create(this, "ComputeInstance")
.name("cdktf-instance")
.machineType("f1-micro")
.bootDisk(Arrays.asList(ComputeInstanceBootDisk.builder()
.initializeParams(Arrays.asList(ComputeInstanceBootDiskInitializeParams.builder()
.bootDisk(ComputeInstanceBootDisk.builder()
.initializeParams(ComputeInstanceBootDiskInitializeParams.builder()
.image("debian-cloud/debian-9")
.build()
))
)
.build()
))
.networkInterface(Arrays.asList(ComputeInstanceNetworkInterface.builder()
)
.networkInterface(ComputeInstanceNetworkInterface.builder()
.network(network.getName())
.build()
))
)
.tags(Arrays.asList("web", "dev"))
.dependsOn(Arrays.asList(network))
.build();
Expand Down
46 changes: 23 additions & 23 deletions examples/java/kubernetes/src/main/java/com/mycompany/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ public Main(final Construct scope, final String id) {
String app = "nginx-example";

new Deployment(this, "nginx-deployment", DeploymentConfig.builder()
.metadata(Collections.singletonList(
.metadata(
DeploymentMetadata.builder()
.name(app)
.namespace(exampleNamespace.getId())
.labels(Collections.singletonMap("app", app))
.build()
))
.spec(Collections.singletonList(
)
.spec(
DeploymentSpec.builder()
.replicas(2)
.selector(Collections.singletonList(
.selector(
DeploymentSpecSelector.builder()
.matchLabels(Collections.singletonMap("app", app))
.build()
))
.template(Collections.singletonList(DeploymentSpecTemplate.builder()
.metadata(Collections.singletonList(
)
.template(DeploymentSpecTemplate.builder()
.metadata(
DeploymentSpecTemplateMetadata.builder()
.labels(Collections.singletonMap("app", app))
.build()
))
.spec(Collections.singletonList(
)
.spec(
DeploymentSpecTemplateSpec
.builder()
.container(Collections.singletonList(
.container(
DeploymentSpecTemplateSpecContainer.builder()
.image("nginx:1.7.8")
.name("example")
Expand All @@ -81,41 +81,41 @@ public Main(final Construct scope, final String id) {
.containerPort(80)
.build()
))
.resources(Collections.singletonList(
.resources(
DeploymentSpecTemplateSpecContainerResources.builder()
.limits(Collections.singletonList(
.limits(
DeploymentSpecTemplateSpecContainerResourcesLimits.builder()
.cpu("0.5")
.memory("512Mi")
.build()
))
.requests(Collections.singletonList(
)
.requests(
DeploymentSpecTemplateSpecContainerResourcesRequests.builder()
.cpu("250m")
.memory("50Mi")
.build()
)).build()
)).build()
)).build()
)).build())
).build()
).build()
).build()
).build()
).build()
)).build());
).build());

new Service(this, "nginx-service", ServiceConfig.builder()
.metadata(Collections.singletonList(
.metadata(
ServiceMetadata.builder()
.name(app)
.namespace(exampleNamespace.getId())
.build()))
.spec(Collections.singletonList(ServiceSpec.builder()
.build())
.spec(ServiceSpec.builder()
.selector(Collections.singletonMap("app", app))
.port(Collections.singletonList(
ServiceSpecPort.builder()
.nodePort(30201)
.port(80)
.targetPort("80")
.build()
))
)
.type("NodePort")
.build()))
.build());
Expand Down
36 changes: 18 additions & 18 deletions examples/python/kubernetes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,47 @@ def __init__(self, scope: Construct, ns: str):

KubernetesProvider(self, 'kind', config_path="~/.kube/config")
example_namespace = Namespace(self, "tf-cdk-example",
metadata=[{
metadata={
'name': 'tf-cdk-example'
}])
})
app_name = "nginx-example"
Deployment(self, 'nginx-deployment',
metadata=[{
metadata={
'name': app_name,
'namespace': example_namespace.metadata_input[0].name,
'labels': {
'app': app_name
}
}],
spec=[{
},
spec={
'replicas': 2,
'selector': [{
'selector': {
'matchLabels': {
'app': app_name
}
}],
'template': [{
'metadata': [{
},
'template': {
'metadata': {
'labels': {
'app': app_name
}
}],
'spec': [{
},
'spec': {
'container': [{
'image': 'nginx:1.7.9',
'name': 'example',
'ports': [{
'containerPort': 80
}]
}]
}]
}]
}])
}
}
})
Service(self, "tf-cdk-service",
metadata=[{
metadata={
'name': 'tf-cdk-service'
}],
spec=[{
},
spec={
'selector': {
'app': app_name
},
Expand All @@ -60,7 +60,7 @@ def __init__(self, scope: Construct, ns: str):
'target_port': 80
}],
'type': 'NodePort'
}])
})


app = App()
Expand Down
Loading

0 comments on commit 3727cf6

Please sign in to comment.