Skip to content

Commit

Permalink
chore: document for each expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Nov 23, 2023
1 parent ed42caa commit 02159fe
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 34 deletions.
28 changes: 28 additions & 0 deletions examples/csharp/documentation/IteratorStack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,34 @@ public IteratorStack(Construct scope, string name) : base(scope, name)
Source = helpFile.Path
});
// DOCS_BLOCK_END:iterators-chain

// DOCS_BLOCK_START:iterators-for-expression
TerraformLocal values = new TerraformLocal(this, "values", new Dictionary<string, object> {
{
"website ",
new Dictionary<string, object> {
{ "name", "website-static-files" },
{ "tags", new Dictionary<string, string> {
{ "app", "website" }
}}
}
},
{
"images",
new Dictionary<string, object> {
{ "name", "images" },
{ "tags", new Dictionary<string, string> {
{ "app", "image-converter" }
}}
}
}
});
MapTerraformIterator mapIterator = MapTerraformIterator.FromMap(values.AsAnyMap);
new TerraformLocal(this, "list-of-keys", mapIterator.MapToKey());
new TerraformLocal(this, "list-of-names", mapIterator.MapToValueProperty("name"));
new TerraformLocal(this, "list-of-names-of-included", mapIterator.ForExpressionForList("val.name if val.included"));
new TerraformLocal(this, "map-with-names-as-key-and-tags-as-value-of-included", mapIterator.ForExpressionForMap("val.name", "val.tags if val.included"));
// DOCS_BLOCK_END:iterators-for-expression
}
}
}
19 changes: 19 additions & 0 deletions examples/go/documentation/iterators.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,24 @@ func NewIteratorsStack(scope constructs.Construct, name string) cdktf.TerraformS
})
// DOCS_BLOCK_END:iterators-chain

// DOCS_BLOCK_START:iterators-for-expression
values := cdktf.NewTerraformLocal(stack, jsii.String("values"), []map[string]interface{}{
{
"name": "website-static-files",
"tags": map[string]string{"app": "website"},
},
{
"name": "images",
"tags": map[string]string{"app": "image-converter"},
},
})

mapIterator := cdktf.TerraformIterator_FromList(values.Expression())
cdktf.NewTerraformLocal(stack, jsii.String("list-of-keys"), mapIterator.MapToKey())
cdktf.NewTerraformLocal(stack, jsii.String("list-of-names"), mapIterator.MapToValueProperty(jsii.String("name")))
cdktf.NewTerraformLocal(stack, jsii.String("list-of-names-of-included"), mapIterator.ForExpressionForList(jsii.String("val.name if val.included")))
cdktf.NewTerraformLocal(stack, jsii.String("map-with-names-as-key-and-tags-as-value-of-included"), mapIterator.ForExpressionForMap(jsii.String("val.name"), jsii.String("val.tags if val.included")))
// DOCS_BLOCK_END:iterators-for-expression

return stack
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,39 @@ public MainIterator2(Construct scope, String id) {
.source(asset.getPath())
.build()
);
// DOCS_BLOCK_END:iterators-chain
// DOCS_BLOCK_END:iterators-chain

// DOCS_BLOCK_START:iterators-for-expression
TerraformLocal values = new TerraformLocal(this, "values", new HashMap() {
{
put("website", new HashMap() {
{
put("name", "website-static-files");
put("tags", new HashMap<String, String>() {
{
put("app", "website");
}
});
}
});
put("images", new HashMap() {
{
put("name", "images");
put("tags", new HashMap<String, String>() {
{
put("app", "image-converter");
}
});
}
});
}
});

TerraformIterator mapIterator = TerraformIterator.fromMap(values.getAsAnyMap());
new TerraformLocal(this, "list-of-keys", mapIterator.mapToKey());
new TerraformLocal(this, "list-of-names", mapIterator.mapToValueProperty("name"));
new TerraformLocal(this, "list-of-names-of-included", mapIterator.forExpressionForList("val.name if val.included"));
new TerraformLocal(this, "map-with-names-as-key-and-tags-as-value-of-included", mapIterator.forExpressionForMap("val.name", "val.tags if val.included"));
// DOCS_BLOCK_END:iterators-for-expression
}
}
21 changes: 21 additions & 0 deletions examples/python/documentation/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,24 @@ def __init__(self, scope: Construct, id: str):
source=help_file.path
)
# DOCS_BLOCK_END:iterators-chain


# DOCS_BLOCK_START:iterators-for-expression
values = TerraformLocal(self, "map-local", {
"website": {
"name": "website-static-files",
"tags": {"app": "website"}
},
"images": {
"name": "images",
"tags": {"app": "image-converter"}
}
})
mapIterator = TerraformIterator.from_map(
map=values.as_any_map
)
TerraformLocal(self, "list-of-keys", mapIterator.map_to_key())
TerraformLocal(self, "list-of-names", mapIterator.map_to_value_property("name"))
TerraformLocal(self, "list-of-names-of-included", mapIterator.for_expression_for_list("val.name if val.included"))
TerraformLocal(self, "map-with-names-as-key-and-tags-as-value-of-included", mapIterator.for_expression_for_map("val.name", "val.tags if val.included"))
# DOCS_BLOCK_END:iterators-for-expression
42 changes: 39 additions & 3 deletions examples/typescript/documentation/iterators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { Team } from "@cdktf/provider-github/lib/team";
import { DataGithubOrganization } from "@cdktf/provider-github/lib/data-github-organization";
import { TeamMembers } from "@cdktf/provider-github/lib/team-members";
// DOCS_BLOCK_START:iterators,iterators-complex-types
import { TerraformIterator, TerraformStack, TerraformVariable } from "cdktf";
import {
TerraformIterator,
TerraformLocal,
TerraformOutput,
TerraformStack,
TerraformVariable,
} from "cdktf";
import { Construct } from "constructs";
import { AwsProvider } from "@cdktf/provider-aws/lib/aws-provider";
import { S3Bucket } from "@cdktf/provider-aws/lib/s3-bucket";
Expand Down Expand Up @@ -113,7 +119,37 @@ export class IteratorsStack extends TerraformStack {
});
// DOCS_BLOCK_END:iterators-chain

// DOCS_BLOCK_START:iterators,iterators-complex-types,iterators-chain
// DOCS_BLOCK_START:iterators-for-expression
const mapIterator = TerraformIterator.fromMap({
website: {
name: "website-static-files",
tags: { app: "website" },
included: true,
},
images: {
name: "images",
tags: { app: "image-converter" },
},
});
new TerraformLocal(this, "list-of-keys", mapIterator.mapToKey());
new TerraformLocal(
this,
"list-of-names",
mapIterator.mapToValueProperty("name")
);
new TerraformLocal(
this,
"list-of-names-of-included",
mapIterator.forExpressionForList("val.name if val.included")
);
new TerraformLocal(
this,
"map-with-names-as-key-and-tags-as-value-of-included",
mapIterator.forExpressionForMap("val.name", "val.tags if val.included")
);
// DOCS_BLOCK_END:iterators-for-expression

// DOCS_BLOCK_START:iterators,iterators-complex-types
}
}
// DOCS_BLOCK_END:iterators,iterators-complex-types,iterators-chain
// DOCS_BLOCK_END:iterators,iterators-complex-types
Loading

0 comments on commit 02159fe

Please sign in to comment.