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 Sep 21, 2021
1 parent 0c7464e commit c2169b0
Show file tree
Hide file tree
Showing 30 changed files with 440,457 additions and 331,618 deletions.
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
10 changes: 3 additions & 7 deletions examples/csharp/google/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@ 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 [] {
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
50 changes: 24 additions & 26 deletions examples/java/kubernetes/src/main/java/com/mycompany/app/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,37 @@ public Main(final Construct scope, final String id) {

Namespace exampleNamespace = new Namespace(this, "tf-cdk-example",
NamespaceConfig.builder()
.metadata(Collections.singletonList(
NamespaceMetadata.builder()
.metadata(NamespaceMetadata.builder()
.name("tf-cdk-example")
.build()
))
)
.build());

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(
Expand All @@ -81,41 +80,40 @@ 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
2 changes: 1 addition & 1 deletion examples/python/azure/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, scope: Construct, ns: str):


AzurermProvider(self, "Azurerm",\
features=[{}]
features={}
)

example_rg = ResourceGroup(self, 'example-rg',\
Expand Down
43 changes: 22 additions & 21 deletions examples/python/kubernetes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,48 @@ 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,
'namespace': example_namespace.metadata_input.name,
'labels': {
'app': app_name
}
}],
spec=[{
},
spec={
'replicas': 2,
'selector': [{
'matchLabels': {
'selector': {
'match_labels': {
'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=[{
'name': 'tf-cdk-service'
}],
spec=[{
metadata={
'name': 'tf-cdk-service',
'namespace': example_namespace.metadata_input.name,
},
spec={
'selector': {
'app': app_name
},
Expand All @@ -60,7 +61,7 @@ def __init__(self, scope: Construct, ns: str):
'target_port': 80
}],
'type': 'NodePort'
}])
})


app = App()
Expand Down
Loading

0 comments on commit c2169b0

Please sign in to comment.