> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Sourcing a Module From a Git Repository

> This tutorial teaches how to source a Terraform module from GitHub using Terragrunt for consistent deployments.

In this tutorial, you’ll learn how to source the official [Terraform AWS S3 Bucket Module](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket) directly from GitHub using Terragrunt. By pinning to a specific release tag, you can guarantee consistent deployments across environments.

## Prerequisites

* Terragrunt installed (v0.XX+).
* [AWS CLI](https://aws.amazon.com/cli/) configured with valid credentials.
* Git installed and reachable from your environment.

## terragrunt.hcl

Create or update your `terragrunt.hcl` file:

```hcl theme={null}
terraform {
  source = "git::https://github.com/terraform-aws-modules/terraform-aws-s3-bucket.git?ref=v4.1.2"
}

inputs = {
  # This module expects "bucket" (not "bucket_name")
  bucket = "terragrunt-demo-bucket"
}
```

<Callout icon="lightbulb" color="#1CB2FE">
  Appending `?ref=v4.1.2` to the Git URL locks the module to version 4.1.2. This prevents unexpected changes due to upstream updates.
</Callout>

## Module Inputs

| Input  | Description            | Required | Default |
| ------ | ---------------------- | -------- | ------- |
| bucket | Name of the S3 bucket. | yes      | —       |

## Apply the Configuration

Run the following command in the directory containing your `terragrunt.hcl`:

```bash theme={null}
terragrunt apply
```

You should see a plan similar to:

```HCL theme={null}
  # module.s3_bucket.aws_s3_bucket.this will be created
  + resource "aws_s3_bucket" "this" {
      + bucket = "terragrunt-demo-bucket"
      …
    }

  # module.s3_bucket.aws_s3_bucket_public_access_block.this will be created
  + resource "aws_s3_bucket_public_access_block" "this" {
      …
    }
```

Confirm by typing `yes` and wait for provisioning to complete.

## Verify the Bucket

After Terragrunt finishes, list your S3 buckets:

```bash theme={null}
aws s3 ls
```

Expected output:

```text theme={null}
2023-06-01 12:34:56 terragrunt-demo-bucket
```

You should see `terragrunt-demo-bucket` in the list.

## Sourcing from Private Repositories

If your module resides in a private Git repo, update the `source` URL to point to your private repository (HTTPS or SSH) and ensure authentication is set up:

* **SSH**: Configure SSH keys and add them to your Git provider.
* **HTTPS**: Use `git-credential-helper` or environment variables for credentials.

<Callout icon="triangle-alert" color="#FF6B6B">
  Do not store credentials in version control. Use secure credential helpers or environment variables to manage access.
</Callout>

## Links and References

| Resource                 | URL                                                                                                                                  |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| Terraform AWS S3 Module  | [https://github.com/terraform-aws-modules/terraform-aws-s3-bucket](https://github.com/terraform-aws-modules/terraform-aws-s3-bucket) |
| Terragrunt Documentation | [https://terragrunt.gruntwork.io/docs/](https://terragrunt.gruntwork.io/docs/)                                                       |
| Terraform Documentation  | [https://www.terraform.io/docs/](https://www.terraform.io/docs/)                                                                     |
| AWS CLI                  | [https://aws.amazon.com/cli/](https://aws.amazon.com/cli/)                                                                           |

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/terragrunt-for-beginners/module/4d4cda50-7d42-4622-b0d4-fa6e6ce0a16d/lesson/8a3a7434-c751-49b0-8ff8-4d5e3f342d3c" />
</CardGroup>
