Skip to content
Merged
6 changes: 3 additions & 3 deletions _docs-sources/iac/getting-started/accessing-the-code.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Accessing the code

Gruntwork provides all code included in your subscription to the Infrastructure as Code (IaC) library through GitHub. To gain access to the IaC Library, you must first [create an account in the Developer Portal](../../developer-portal/create-account.md). Once you have an account, you must [link your Github ID](../../developer-portal/link-github-id) to your Developer Portal account to gain access to the IaC Library.
Gruntwork provides all code included in your subscription to the Infrastructure as Code (IaC) library through GitHub. To gain access to the IaC Library, you must first [create an account in the Developer Portal](../../developer-portal/create-account.md). Once you have an account, you must [link your GitHub ID](../../developer-portal/link-github-id) to your Developer Portal account to gain access to the IaC Library.

## Accessing Modules and Services in the IaC library

Once you have gained access to the Gruntwork IaC library, you can view the source code for our modules and services in [Github](https://github.com/orgs/gruntwork-io/repositories). For a full list of modules and services, check the [Library Reference](../../iac/reference/index.md).
Once you have gained access to the Gruntwork IaC library, you can view the source code for our modules and services in [GitHub](https://github.com/orgs/gruntwork-io/repositories). For a full list of modules and services, check the [Library Reference](../../iac/reference/index.md).

In Github, each IaC repository is prefixed with `terraform-aws-` then a high level description of the modules it contains. For example, Amazon SNS, SQS, MSK, and Kinesis are located in the `terraform-aws-messaging` repository. In each repository, the modules are located in the `modules` directory. Example usage and tests are provided for each module in the `examples` and `tests` directories, respectively.
In GitHub, each IaC repository is prefixed with `terraform-aws-` then a high level description of the modules it contains. For example, Amazon SNS, SQS, MSK, and Kinesis are located in the `terraform-aws-messaging` repository. In each repository, the modules are located in the `modules` directory. Example usage and tests are provided for each module in the `examples` and `tests` directories, respectively.
31 changes: 15 additions & 16 deletions _docs-sources/iac/getting-started/deploying-a-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

[Modules](../overview/modules.md) allow you to define an interface to create one or many resources in the cloud or on-premise, similar to how in object oriented programming you can define a class that may have different attribute values across many instances.

Modules help keep your Terraform code DRY (Don’t Repeat Yourself), and speed up development time when creating new resources.

This tutorial will teach you how to develop a Terraform module that deploys an AWS Lambda function. We will create the required file structure, define an AWS Lambda function and AWS IAM role as code, then plan and apply the resource in an AWS account. Then, we’ll verify the deployment by invoking the Lambda using the AWS CLI. Finally, we'll clean up the resources we create to avoid unexpected costs.

## Prerequisites
Expand All @@ -22,7 +20,7 @@ This module could be referenced many times to create any number of AWS Lambda fu
### Create a basic file structure
First, create the directories and files that will contain the Terraform configuration.

```sh
```bash
mkdir -p terraform-aws-gw-lambda-tutorial/modules/lambda
touch terraform-aws-gw-lambda-tutorial/modules/lambda/main.tf
touch terraform-aws-gw-lambda-tutorial/modules/lambda/variables.tf
Expand All @@ -34,7 +32,7 @@ touch terraform-aws-gw-lambda-tutorial/modules/lambda/outputs.tf
First, define the resources that should be created by the module. This is where you define resource level blocks provided by Terraform. For this module, we need an AWS Lambda function and an IAM role that will be used by the Lambda function.

Paste the following snippet in `terraform-aws-gw-lambda/modules/lambda/main.tf`.
```hcl
```hcl title="terraform-aws-gw-lambda/modules/lambda/main.tf"
resource "aws_iam_role" "lambda_role" {
name = "${var.lambda_name}-role"

Expand Down Expand Up @@ -80,7 +78,7 @@ Now that you’ve defined the resources you want to create, you need to list out

Copy the following snippet into `terraform-aws-gw-lambda-tutorial/modules/lambda/variables.tf`.

```tf
```hcl title="terraform-aws-gw-lambda-tutorial/modules/lambda/variables.tf"
variable "lambda_name" {
type = string
description = "Name that will be used for the AWS Lambda function"
Expand Down Expand Up @@ -119,7 +117,7 @@ variable "timeout" {
Terraform allows you to specify values that the module will output. Outputs are convenient ways to pass values between modules when composing a service comprised of many modules.

Copy the following snippet into `terraform-aws-gw-lambda-tutorial/modules/lambda/outputs.tf`.
```tf
```hcl title="terraform-aws-gw-lambda-tutorial/modules/lambda/outputs.tf"
output "function_name" {
value = aws_lambda_function.lambda.function_name
}
Expand All @@ -134,7 +132,7 @@ Now that you have defined a module that creates an AWS Lambda function and IAM r
Now that you have the module defined, you need to create files which will reference the module. Typically, you would create a module in one repository, then reference it in a different repository. For this tutorial, we’ll just create the reference in the top level directory for the sake of simplicity.

Create a file called `main.tf`, which will contain a reference to the module, and a file called `main.py`, which will contain the Lambda function code.
```sh
```bash
touch terraform-aws-gw-lambda-tutorial/main.tf
touch terraform-aws-gw-lambda-tutorial/main.py
```
Expand All @@ -144,7 +142,8 @@ touch terraform-aws-gw-lambda-tutorial/main.py
Next, we’ll write a simple Python function that returns a string that will be used as the entrypoint of the AWS Lambda function. Terraform will create a zip file containing this file that will be uploaded to the Lambda function.

Copy the following to `terraform-aws-gw-lambda-tutorial/main.py`.
```

```py title="terraform-aws-gw-lambda-tutorial/main.py"
def lambda_handler(event, context):
return "Hello from Gruntwork!"
```
Expand All @@ -153,7 +152,7 @@ def lambda_handler(event, context):

Next, create a reference to the module you just created in `/modules/lambda/main.tf`. This code uses the `module` block from Terraform, which references the `/modules/lambda` directory using the `source` attribute. You can then specify values for the required variables specified in `/modules/lambdas/variables.tf`. Finally, we specify an output using the value of the `module.lambda.function_name` output created in `/modules/lambdas/outputs.tf`

```
```hcl title="terraform-aws-gw-lambda-tutorial/main.tf"
terraform {
required_providers {
aws = {
Expand Down Expand Up @@ -188,11 +187,11 @@ Running `terraform plan` is helpful when developing modules, to confirm that the


From the `terraform-aws-gw-lambda-tutorial` directory, run a plan to see what resources will be created.
```sh
```bash
terraform plan
```

Review the output of `terraform plan`, it should contain two resources - an AWS Lambda function and an AWS IAM role.
Review the output of `terraform plan`, it should contain two resources an AWS Lambda function and an AWS IAM role.


### Run Terraform apply
Expand All @@ -201,7 +200,7 @@ Terraform creates resources when using the `apply` action in a directory contain

From the `terraform-aws-gw-lambda-tutorial` directory, run `terraform apply`. Terraform will pause to show you the resources it will create and prompt you to confirm resource creation.

```sh
```bash
terraform apply
```

Expand All @@ -212,14 +211,14 @@ Review the output to confirm it will only create an AWS Lambda function and IAM
Next, invoke the AWS Lambda function to verify it was created and is successfully executing the application code.

Use `terraform output` to retrieve the name of the AWS Lambda function you provisioned. This uses the outputs we added to the module in [create a module](./deploying-a-module.md#create-a-module) to retrieve the name of the Lambda function. Then, invoke the Lambda function directly using the AWS CLI, writing the response of the Lambda to a file called `lambda_output`.
```sh
```bash
#!/bin/bash
export FUNCTION_NAME=$(terraform output -raw function_name)
aws lambda invoke --function-name $FUNCTION_NAME --output json lambda_output
```

The lambda `invoke` command should return a JSON blob in response with the StatusCode of 200 and the ExecutedVersion of `$LATEST`.
```sh
```json
{
"StatusCode": 200,
"ExecutedVersion": "$LATEST"
Expand All @@ -233,15 +232,15 @@ Inspect the contents of the `lambda_output` file, you should see a string statin
When you’ve completed the tutorial, clean up the resources you created to avoid incurring unexpected costs.

First, execute the `terraform plan -destroy` command to show the AWS resources that will be destroyed.
```sh
```bash
terraform plan -destroy
```

Review the output, it should show two resources to be destroyed — an AWS Lambda function and IAM role.

Next, execute the `destroy` command.

```sh
```bash
terraform destroy
```

Expand Down
4 changes: 3 additions & 1 deletion _docs-sources/iac/getting-started/setting-up.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ If you want to skip immediately to learning, you can learn how to [deploy your f

## Terragrunt

Terragrunt is a tool developed by Gruntwork that provides extra tools for keeping your Terraform configurations DRY, working with multiple Terraform modules, and managing remote state. Terragrunt allows you to execute multiple Terraform commands at once, centrally manage your Terraform state configuration, and set repeatable CLI arguments. Since Terraform is a dependency of Terragrunt, you can continue to write modules for Terraform in the Terraform configuration language, then reference and re-use the modules in different environments or applications.
[Terragrunt](https://terragrunt.gruntwork.io) is a tool developed by Gruntwork that provides extra tools for keeping your Terraform configurations DRY, working with multiple Terraform modules, and managing remote state. Terragrunt allows you to execute multiple Terraform commands at once, centrally manage your Terraform state configuration, and set repeatable CLI arguments. Since Terraform is a dependency of Terragrunt, you can continue to write modules for Terraform in the Terraform configuration language, then reference and re-use the modules in different environments or applications.

:::info
Terragrunt is not a required tool to use the IaC library, but it does provide many convenience features on top of Terraform. If you are using the Gruntwork [Reference Architecture](../../refarch/whats-this/what-is-a-reference-architecture), Terragrunt is a requirement.
:::

### Installation
Terragrunt is supported on Mac (x86 and Apple Silicon), Windows, and Linux. To install Terragrunt, follow the guide on how to [install Terragrunt](https://terragrunt.gruntwork.io/docs/getting-started/install/) on the Terragrunt website.
Expand Down
2 changes: 1 addition & 1 deletion _docs-sources/iac/stay-up-to-date/updating.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Below is a module block referencing version `0.15.3` of the `single-server` subm

To update to version `0.15.4`, you update the value to the right of `ref=` in the source attribute. Since the version number denotes that this update is backwards compatible, it should not require any other changes.

```tf
```hcl
module "my_instance" {
# Old
# source = "git::git@github.com:gruntwork-io/terraform-aws-server.git//modules/single-server?ref=v0.15.3"
Expand Down
10 changes: 6 additions & 4 deletions _docs-sources/iac/stay-up-to-date/versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Gruntwork versions the IaC library using [Semantic Versioning](https://semver.or
- MINOR version when we make backward incompatible API changes, and
- PATCH version when we add backward compatible functionality or bug fixes

For modules that have submodules (e.g., terraform-aws-server/modules/single-server), not every release contains changes to every module. While using the latest available version is recommended, the version that most recently contains changes for a module can be found in each submodule's reference in the [Library Reference](../reference/index.md).
For modules that have submodules (e.g., terraform-aws-server/modules/single-server), not every release contains changes to every module. While using the latest available version is recommended, the version that most recently contains changes for a module can be found in each submodule’s reference in the [Library Reference](../reference/index.md).

![Submodules show the last version in which they were modified](/img/iac/stay-up-to-date/versioning/module_release_tag_versions.png)

We release new module versions using GitHub releases, refer to the release notes in the GitHub repository release page for a list of changes and migration guides (when necessary).

Expand All @@ -14,7 +16,7 @@ We release new module versions using GitHub releases, refer to the release notes
The git tag created by the release can then be referenced in the source argument for a module block sourcing from a git URL.

For example, below is a module block referencing version `0.15.4` of the `single-server` submodule from the `terraform-aws-server` module.
```tf
```hcl
module "my_instance" {
source = "git::git@github.com:gruntwork-io/terraform-aws-server.git//modules/single-server?ref=v0.15.4"

Expand All @@ -29,6 +31,6 @@ module "my_instance" {
}
```

## What's next
## Whats next

Once you start using versioned modules, it's important to keep the modules up to date. Refer to the [Updating](./updating.md) guide to learn more.
Once you start using versioned modules, its important to keep the modules up to date. Refer to the [Updating](./updating.md) guide to learn more.
8 changes: 4 additions & 4 deletions docs/iac/getting-started/accessing-the-code.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Accessing the code

Gruntwork provides all code included in your subscription to the Infrastructure as Code (IaC) library through GitHub. To gain access to the IaC Library, you must first [create an account in the Developer Portal](../../developer-portal/create-account.md). Once you have an account, you must [link your Github ID](../../developer-portal/link-github-id) to your Developer Portal account to gain access to the IaC Library.
Gruntwork provides all code included in your subscription to the Infrastructure as Code (IaC) library through GitHub. To gain access to the IaC Library, you must first [create an account in the Developer Portal](../../developer-portal/create-account.md). Once you have an account, you must [link your GitHub ID](../../developer-portal/link-github-id) to your Developer Portal account to gain access to the IaC Library.

## Accessing Modules and Services in the IaC library

Once you have gained access to the Gruntwork IaC library, you can view the source code for our modules and services in [Github](https://github.com/orgs/gruntwork-io/repositories). For a full list of modules and services, check the [Library Reference](../../iac/reference/index.md).
Once you have gained access to the Gruntwork IaC library, you can view the source code for our modules and services in [GitHub](https://github.com/orgs/gruntwork-io/repositories). For a full list of modules and services, check the [Library Reference](../../iac/reference/index.md).

In Github, each IaC repository is prefixed with `terraform-aws-` then a high level description of the modules it contains. For example, Amazon SNS, SQS, MSK, and Kinesis are located in the `terraform-aws-messaging` repository. In each repository, the modules are located in the `modules` directory. Example usage and tests are provided for each module in the `examples` and `tests` directories, respectively.
In GitHub, each IaC repository is prefixed with `terraform-aws-` then a high level description of the modules it contains. For example, Amazon SNS, SQS, MSK, and Kinesis are located in the `terraform-aws-messaging` repository. In each repository, the modules are located in the `modules` directory. Example usage and tests are provided for each module in the `examples` and `tests` directories, respectively.


<!-- ##DOCS-SOURCER-START
{
"sourcePlugin": "local-copier",
"hash": "88f91722ace689986e5db3d4b5723cfc"
"hash": "bcd57ad0a4f3270656d998deb53df2b0"
}
##DOCS-SOURCER-END -->
Loading