-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for a custom aws endpoint #1264
Open
sverch
wants to merge
20
commits into
gruntwork-io:main
Choose a base branch
from
sverch:feature/aws-custom-endpoint-494
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1b79e4b
Add support for a custom aws endpoint
5c2e8e4
Use `t.Setenv` so env vars are cleaned up
67df0cd
Fix formatter errors
6905e03
Add CI task to run tests
0606e8b
Add documentation for custom aws endpoints
5da3b5a
Fix section header
55fc462
Attempt to fix circleci configuration
4aa41b0
Update examples/terraform-aws-endpoint-example/README.md
sverch 0636877
Merge branch 'master' into feature/aws-custom-endpoint-494
ab57be4
Update .circleci/config.yml
sverch 471e5c3
Merge remote-tracking branch 'upstream/master' into feature/aws-custo…
212fbb4
Make log directory for mock aws server logs
dcf6e5c
Disable AWS_PAGER because of bad terminal warning
7aad127
Make sure to only run mock aws test
76bc05e
Use local IP in attempt to not cause dns lookup
62c801d
Use 127.0.0.1 in local endpoint example
cb1b7c5
Revert "Use 127.0.0.1 in local endpoint example"
7bf168c
Revert "Use local IP in attempt to not cause dns lookup"
4303600
Use s3 path style endpoints
7faf973
Merge branch 'master' into feature/aws-custom-endpoint-494
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,28 @@ | ||
# Terraform AWS Endpoint Example | ||
|
||
This folder contains a simple Terraform module to demonstrate using custom | ||
endpoints. It's deploying some AWS resources to `http://localhost:5000`, which | ||
is the default port for [moto running in server | ||
mode](http://docs.getmoto.org/en/latest/docs/server_mode.html). This allows for | ||
testing terraform modules locally with no connection to AWS. | ||
|
||
Check out | ||
[test/terraform_aws_endpoint_example_test.go](/test/terraform_aws_endpoint_example_test.go) | ||
to see how you can write automated tests for this module. | ||
|
||
## Running this module manually | ||
|
||
1. Run [Moto locally in server mode](http://docs.getmoto.org/en/latest/docs/server_mode.html) | ||
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. | ||
1. Run `terraform init`. | ||
1. Run `terraform apply`. | ||
1. When you're done, run `terraform destroy`. | ||
|
||
## Running automated tests against this module | ||
|
||
1. Run [Moto locally in server mode](http://docs.getmoto.org/en/latest/docs/server_mode.html) | ||
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. | ||
1. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`. | ||
1. `cd test` | ||
1. `dep ensure` | ||
1. `go test -v -run TestTerraformAwsEndpointExample` |
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,138 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# PIN TERRAFORM VERSION TO >= 0.12 | ||
# The examples have been upgraded to 0.12 syntax | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
provider "aws" { | ||
region = var.region | ||
access_key = "dummy" | ||
secret_key = "dummy" | ||
|
||
# By default, terraform will interact with s3 in a way that uses subdomains | ||
# to specify information about the bucket. If you have issues with subdomains | ||
# of "localhost" not resolving properly, set this to true to tell terraform | ||
# to use url paths rather than subdomains for this information. | ||
# See: https://registry.terraform.io/providers/hashicorp/aws/latest/docs#s3_use_path_style | ||
s3_use_path_style = "true" | ||
|
||
endpoints { | ||
sts = "http://localhost:5000" | ||
s3 = "http://localhost:5000" | ||
} | ||
} | ||
|
||
terraform { | ||
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting | ||
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it | ||
# forwards compatible with 0.13.x code. | ||
required_version = ">= 0.12.26" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# DEPLOY A S3 BUCKET WITH VERSIONING ENABLED INCLUDING TAGS TO A LOCAL ENDPOINT | ||
# See test/terraform_aws_endpoint_example_test.go for how to write automated tests for this code. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# Deploy and configure test S3 bucket with versioning and access log | ||
resource "aws_s3_bucket" "test_bucket" { | ||
bucket = "${local.aws_account_id}-${var.tag_bucket_name}" | ||
|
||
tags = { | ||
Name = var.tag_bucket_name | ||
Environment = var.tag_bucket_environment | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_logging" "test_bucket" { | ||
bucket = aws_s3_bucket.test_bucket.id | ||
target_bucket = aws_s3_bucket.test_bucket_logs.id | ||
target_prefix = "TFStateLogs/" | ||
} | ||
|
||
resource "aws_s3_bucket_versioning" "test_bucket" { | ||
bucket = aws_s3_bucket.test_bucket.id | ||
versioning_configuration { | ||
status = "Enabled" | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_acl" "test_bucket" { | ||
bucket = aws_s3_bucket.test_bucket.id | ||
acl = "private" | ||
} | ||
|
||
|
||
# Deploy S3 bucket to collect access logs for test bucket | ||
resource "aws_s3_bucket" "test_bucket_logs" { | ||
bucket = "${local.aws_account_id}-${var.tag_bucket_name}-logs" | ||
|
||
tags = { | ||
Name = "${local.aws_account_id}-${var.tag_bucket_name}-logs" | ||
Environment = var.tag_bucket_environment | ||
} | ||
|
||
force_destroy = true | ||
} | ||
|
||
resource "aws_s3_bucket_acl" "test_bucket_logs" { | ||
bucket = aws_s3_bucket.test_bucket_logs.id | ||
acl = "log-delivery-write" | ||
} | ||
|
||
# Configure bucket access policies | ||
|
||
resource "aws_s3_bucket_policy" "bucket_access_policy" { | ||
count = var.with_policy ? 1 : 0 | ||
bucket = aws_s3_bucket.test_bucket.id | ||
policy = data.aws_iam_policy_document.s3_bucket_policy.json | ||
} | ||
|
||
data "aws_iam_policy_document" "s3_bucket_policy" { | ||
statement { | ||
effect = "Allow" | ||
principals { | ||
# TF-UPGRADE-TODO: In Terraform v0.10 and earlier, it was sometimes necessary to | ||
# force an interpolation expression to be interpreted as a list by wrapping it | ||
# in an extra set of list brackets. That form was supported for compatibility in | ||
# v0.11, but is no longer supported in Terraform v0.12. | ||
# | ||
# If the expression in the following list itself returns a list, remove the | ||
# brackets to avoid interpretation as a list of lists. If the expression | ||
# returns a single list item then leave it as-is and remove this TODO comment. | ||
identifiers = [local.aws_account_id] | ||
type = "AWS" | ||
} | ||
actions = ["*"] | ||
resources = ["${aws_s3_bucket.test_bucket.arn}/*"] | ||
} | ||
|
||
statement { | ||
effect = "Deny" | ||
principals { | ||
identifiers = ["*"] | ||
type = "AWS" | ||
} | ||
actions = ["*"] | ||
resources = ["${aws_s3_bucket.test_bucket.arn}/*"] | ||
|
||
condition { | ||
test = "Bool" | ||
variable = "aws:SecureTransport" | ||
values = [ | ||
"false", | ||
] | ||
} | ||
} | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# LOCALS | ||
# Used to represent any data that requires complex expressions/interpolations | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
data "aws_caller_identity" "current" { | ||
} | ||
|
||
locals { | ||
aws_account_id = data.aws_caller_identity.current.account_id | ||
} | ||
|
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,15 @@ | ||
output "bucket_id" { | ||
value = aws_s3_bucket.test_bucket.id | ||
} | ||
|
||
output "bucket_arn" { | ||
value = aws_s3_bucket.test_bucket.arn | ||
} | ||
|
||
output "logging_target_bucket" { | ||
value = aws_s3_bucket_logging.test_bucket.target_bucket | ||
} | ||
|
||
output "logging_target_prefix" { | ||
value = aws_s3_bucket_logging.test_bucket.target_prefix | ||
} |
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,40 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# ENVIRONMENT VARIABLES | ||
# Define these secrets as environment variables | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# AWS_ACCESS_KEY_ID | ||
# AWS_SECRET_ACCESS_KEY | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# REQUIRED PARAMETERS | ||
# You must provide a value for each of these parameters. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
variable "region" { | ||
description = "The AWS region to deploy to" | ||
type = string | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# OPTIONAL PARAMETERS | ||
# These parameters have reasonable defaults. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
variable "with_policy" { | ||
description = "If set to `true`, the bucket will be created with a bucket policy." | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "tag_bucket_name" { | ||
description = "The Name tag to set for the S3 Bucket." | ||
type = string | ||
default = "Test Bucket" | ||
} | ||
|
||
variable "tag_bucket_environment" { | ||
description = "The Environment tag to set for the S3 Bucket." | ||
type = string | ||
default = "Test" | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.