Skip to content

Commit

Permalink
documented md5/sha1/sha256/sha512 custom jinja functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ribejara-te committed Jan 20, 2025
1 parent 6915662 commit ac39b57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The ["I am starting from scratch" quick-start guide](<2.2. I am starting from sc
2. [Reusable root modules](<docs/3.1.2. Reusable root modules.md>)
3. [Jinja templating for Terraform](<docs/3.1.3. Jinja templating for Terraform.md>)
4. [Jinja templating for variables](<docs/3.1.4. Jinja templating for variables.md>)
5. [Remote lookup functions](<docs/3.1.5. Remote lookup functions.md>)
5. [Custom Jinja functions](<docs/3.1.5. Custom Jinja functions.md>)
6. [Inline secret encryption](<docs/3.1.6. Inline secret encryption.md>)
7. [Automatic variable initialization](<docs/3.1.7. Automatic variable initialization.md>)
2. Features you can build with Stacks
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Remote lookup functions
# Custom Jinja functions

With Jinja you get to inject your own custom functions to be used in templating, so of course we do.

## The `variable` lookup function
With the `variable` lookup function you can fetch any variable value off any other layer in your repository.
## The `variable` function
With the `variable` function you can fetch any variable value off any other layer in your repository.
### Example 1: fetching a `vpc_id` variable from the same layer in a different stack
```hcl
# stacks/ec2/stack.tfvars.jinja:
Expand All @@ -20,18 +20,26 @@ vpc_id = "{{ variable("vpc_id", stack="vpc", environment="production") }}"
vpc_id = "{{ variable("vpc_id", stack="vpc", environment="development", subenvironment="us-east-1", instance="foo") }}" # stack/environment/subenvironment/instance all default to the caller's
```

## The `output` lookup function
With the `output` lookup function you can fetch any output value off the state of any other layer in your repository.
## The `output` function
With the `output` function you can fetch any output value off the state of any other layer in your repository.
### Example 1: fetching a `vpc_id` output from the same layer in a different stack
```hcl
# stacks/ec2/stack.tfvars.jinja:
vpc_id = "{{ output("vpc_id", stack="vpc") }}"
```

## The `resource` lookup function
With the `resource` lookup function you can fetch any resource attributes off the state of any other layer in your repository.
## The `resource` function
With the `resource` function you can fetch any resource attributes off the state of any other layer in your repository.
### Example 1: fetching a `aws_vpc.main` resource from the same layer in a different stack
```hcl
# stacks/ec2/stack.tfvars.jinja:
vpc_id = "{{ resource("aws_vpc.main", stack="vpc")["id"] }}"
```

## The `md5`, `sha1`, `sha256` and `sha512` functions
With these functions you can generate the MD5, SHA-1, SHA-256 and SHA-512 checksums respectively of a given string.
### Example
```hcl
# stacks/ec2/stacks.tfvars.jinja
foo_md5 = "{{ md5("foo") }}"
```

0 comments on commit ac39b57

Please sign in to comment.