-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docs for Fn.lookup and Fn.lookupNested
- Loading branch information
Showing
9 changed files
with
300 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
|
||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Constructs; | ||
using HashiCorp.Cdktf; | ||
using aws.Provider; | ||
using aws.DataAwsAvailabilityZones; | ||
|
||
namespace Examples | ||
{ | ||
class FunctionsOtherStack : TerraformStack | ||
{ | ||
public FunctionsOtherStack(Construct scope, string name) : base(scope, name) | ||
{ | ||
new AwsProvider(this, "aws", new AwsProviderConfig | ||
{ | ||
Region = "eu-central-1" | ||
}); | ||
|
||
|
||
// DOCS_BLOCK_START:functions-raw | ||
DataAwsAvailabilityZones zones = new DataAwsAvailabilityZones(this, "zones", new DataAwsAvailabilityZonesConfig | ||
{ | ||
State = "available" | ||
}); | ||
|
||
new TerraformOutput(this, "half-of-the-zone", new TerraformOutputConfig | ||
{ | ||
Value = $"${{length({zones.Fqn}.names) / 2}}" | ||
}); | ||
// DOCS_BLOCK_END:functions-raw | ||
|
||
// DOCS_BLOCK_START:functions-lookup | ||
TerraformVariable v = new TerraformVariable(this, "complex_object", TerraformVariableConfig.builder() | ||
.type("object({users: list(object({name: string}))})") | ||
.build()); | ||
new TerraformOutput(this, "users", new TerraformOutputConfig | ||
{ | ||
Value = Fn.Lookup(v.Value, "users") | ||
}); | ||
new TerraformOutput(this, "first-user-name", new TerraformOutputConfig | ||
{ | ||
Value = Fn.LookupNested(v.Value, new() { "users", "0", "name" }) | ||
}); | ||
// DOCS_BLOCK_END:functions-lookup | ||
|
||
// DOCS_BLOCK_START:functions-raw-string | ||
new TerraformOutput(this, "quotes", new TerraformOutputConfig | ||
{ | ||
Value = Fn.RawString("\"b\"") | ||
}); | ||
new TerraformOutput(this, "template", new TerraformOutputConfig | ||
{ | ||
Value = Fn.RawString("${TEMPLATE}") | ||
}); | ||
// DOCS_BLOCK_END:functions-raw-string | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/aws/constructs-go/constructs/v10" | ||
"github.com/aws/jsii-runtime-go" | ||
"github.com/hashicorp/terraform-cdk-go/cdktf" | ||
) | ||
|
||
func NewFunctionsOtherStack(scope constructs.Construct, name string) cdktf.TerraformStack { | ||
stack := cdktf.NewTerraformStack(scope, &name) | ||
|
||
// DOCS_BLOCK_START:functions-lookup | ||
v := cdktf.NewTerraformVariable(stack, jsii.String("complex-object"), &cdktf.TerraformVariableConfig{ | ||
Type: jsii.String("object({users: list(object({name: string}))})"), | ||
}) | ||
cdktf.NewTerraformOutput(stack, jsii.String("users"), &cdktf.TerraformOutputConfig{ | ||
Value: cdktf.Fn_Lookup(v.Value(), jsii.String("users"), nil), | ||
}) | ||
cdktf.NewTerraformOutput(stack, jsii.String("first-user-name"), &cdktf.TerraformOutputConfig{ | ||
Value: cdktf.Fn_LookupNested(v.Value(), &[]interface{}{"users", 0, "name"}), | ||
}) | ||
// DOCS_BLOCK_END:functions-lookup | ||
|
||
// DOCS_BLOCK_START:functions-raw-string | ||
cdktf.NewTerraformOutput(stack, jsii.String("quotes"), &cdktf.TerraformOutputConfig{ | ||
Value: cdktf.Fn_RawString(jsii.String("\"b\"")), | ||
}) | ||
cdktf.NewTerraformOutput(stack, jsii.String("template"), &cdktf.TerraformOutputConfig{ | ||
Value: cdktf.Fn_RawString(jsii.String("${TEMPLATE}")), | ||
}) | ||
// DOCS_BLOCK_END:functions-raw-string | ||
|
||
return stack | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.