Skip to content

Commit

Permalink
wip - fix c# and python
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarm committed Aug 4, 2023
1 parent b4d222b commit 7647276
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/csharp/documentation/FunctionsOther.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public FunctionsOtherStack(Construct scope, string name) : base(scope, name)
});
new TerraformOutput(this, "first-user-name", new TerraformOutputConfig
{
Value = Fn.LookupNested(v.Value, new() { "users", "0", "name" })
Value = Fn.LookupNested(v.Value, new[] { "users", "0", "name" })
});
// DOCS_BLOCK_END:functions-lookup

Expand Down
6 changes: 2 additions & 4 deletions examples/python/documentation/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ def __init__(self, scope: Construct, id: str):
type = 'object({users: list(object({name: string}))})',
)
TerraformOutput(self, 'users',
# value=Fn.lookup(v.list_value, "users") # lookup2 has no optional default param specified
value=Fn.lookup(v.list_value, "users", None) # maybe the default works?
#value=Fn.element(v.list_value, 0) # doesn't make sense, but just for testing
value=Fn.lookup(v.value, "users")
)
TerraformOutput(self, 'first_user_name',
value=Fn.lookup_nested(v.list_value, ["users", 0, "name"])
value=Fn.lookup_nested(v.value, ["users", 0, "name"])
)
# DOCS_BLOCK_END:functions-lookup

Expand Down
9 changes: 3 additions & 6 deletions packages/cdktf/lib/terraform-functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) HashiCorp, Inc
// SPDX-License-Identifier: MPL-2.0
import { propertyAccess, rawString, Token } from ".";
import { asAny } from "./functions/helpers";
import { FnGenerated } from "./functions/terraform-functions.generated";

// eslint-disable-next-line jsdoc/require-jsdoc
Expand All @@ -26,11 +27,7 @@ export class Fn extends FnGenerated {
static lookup(inputMap: any, key: string, defaultValue?: any) {
// overwritten because lookup() uses a variadic argument for its optional defaultValue
if (defaultValue) return Fn._lookup(inputMap, key, [defaultValue]);
return propertyAccess(inputMap, [key]); // -> renders inputMap[key] (which is recommended if no default value is given)
}

static lookup2(inputMap: any, key: string) {
return propertyAccess(inputMap, [key]); // -> renders inputMap[key] (which is recommended if no default value is given)
return asAny(propertyAccess(inputMap, [key])); // -> renders inputMap[key] (which is recommended if no default value is given)
}

/**
Expand All @@ -40,7 +37,7 @@ export class Fn extends FnGenerated {
* @param {Array<any>} path
*/
static lookupNested(inputMap: any, path: any[]) {
return propertyAccess(inputMap, path);
return asAny(propertyAccess(inputMap, path));
}

/**
Expand Down

0 comments on commit 7647276

Please sign in to comment.