Skip to content

Commit

Permalink
Migrate tests to Localstack
Browse files Browse the repository at this point in the history
  • Loading branch information
grem11n committed Feb 13, 2024
1 parent 6da054b commit 1eeca19
Show file tree
Hide file tree
Showing 35 changed files with 312 additions and 287 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/terratest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
terraform: ['1.3.7']
terraform: ['1.5.7']
steps:
- uses: actions/checkout@master
- uses: hashicorp/setup-terraform@v1
Expand All @@ -38,13 +38,12 @@ jobs:
strategy:
max-parallel: 1
matrix:
terraform: ['1.3.7']
terraform: ['1.5.7']
steps:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.19'

go-version: '1.21'
- name: Checkout
uses: actions/checkout@v1
with:
Expand All @@ -58,13 +57,12 @@ jobs:
sudo unzip -d /tmp/ /tmp/terraform.zip &&
sudo mv /tmp/terraform /usr/local/bin/
- name: Start Localstack
run: docker-compose up -d

- name: Terratest
env:
GOPATH: /home/runner/work/terraform-aws-vpc-peering/go
TF_VAR_aws_peer_access_key: ${{ secrets.TF_VAR_aws_peer_access_key }}
TF_VAR_aws_peer_secret_key: ${{ secrets.TF_VAR_aws_peer_secret_key }}
TF_VAR_aws_this_access_key: ${{ secrets.TF_VAR_aws_this_access_key }}
TF_VAR_aws_this_secret_key: ${{ secrets.TF_VAR_aws_this_secret_key }}
run: >
go mod init github.com/grem11n/terraform-aws-vpc-peering &&
go mod tidy &&
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ go.sum

# Environment variables
.env

# Localstack
volume/
14 changes: 14 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
version: "3.8"
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
image: localstack/localstack
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
- DEBUG=${DEBUG:-0}
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
16 changes: 13 additions & 3 deletions examples/associated-cidrs/provider.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// This provider example is designed to work with Localstack.
// You need to have a real AWS provider configuration for the production usage.
provider "aws" {
region = "eu-west-1"
access_key = var.aws_this_access_key
secret_key = var.aws_this_secret_key
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "eu-west-1"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}
9 changes: 0 additions & 9 deletions examples/associated-cidrs/variables.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
// Variables are required to pass them via Terratest
// on fixtures creation
variable "this_vpc_id" {}

variable "peer_vpc_id" {}

variable "aws_this_access_key" {
description = "AWS Access Key for requester account"
}

variable "aws_this_secret_key" {
description = "AWS Secret Key for requester account"
}
4 changes: 3 additions & 1 deletion examples/module-depends-on/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Using depends_on With This Module
# Using `depends_on` With This Module

**Warning**: There's a bug which prevents the creation of peering with the `depends_on` directove. Thus, Terraform should be executed twice to address that.

If you're using Terraform `>=0.13`, you [can use `depedns_on` meta-argument with modules as well](https://www.terraform.io/docs/language/meta-arguments/depends_on.html)

Expand Down
16 changes: 13 additions & 3 deletions examples/module-depends-on/provider.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// This provider example is designed to work with Localstack.
// You need to have a real AWS provider configuration for the production usage.
provider "aws" {
region = "eu-west-1"
access_key = var.aws_this_access_key
secret_key = var.aws_this_secret_key
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "eu-west-1"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}
8 changes: 0 additions & 8 deletions examples/module-depends-on/variables.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
variable "aws_this_access_key" {
description = "AWS Access Key for requester account"
}

variable "aws_this_secret_key" {
description = "AWS Secret Key for requester account"
}

variable "this_subnets" {
description = "Subnet list for _this_ VPC"
type = list(string)
Expand Down
34 changes: 26 additions & 8 deletions examples/multi-account-multi-region/provider.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
// This provider example is designed to work with Localstack.
// You need to have a real AWS provider configuration for the production usage.
provider "aws" {
alias = "this"
region = "eu-west-1"
access_key = var.aws_this_access_key
secret_key = var.aws_this_secret_key
alias = "this"
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "eu-west-1"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}

provider "aws" {
alias = "peer"
region = "eu-central-1"
access_key = var.aws_peer_access_key
secret_key = var.aws_peer_secret_key
alias = "peer"
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "eu-central-1"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}
17 changes: 0 additions & 17 deletions examples/multi-account-multi-region/variables.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
// Variables are required to pass them via Terratest
// on fixtures creation
variable "this_vpc_id" {}

variable "peer_vpc_id" {}

variable "aws_this_access_key" {
description = "AWS Access Key for requester account"
}

variable "aws_this_secret_key" {
description = "AWS Secret Key for requester account"
}

variable "aws_peer_access_key" {
description = "AWS Access Key for accepter account"
}

variable "aws_peer_secret_key" {
description = "AWS Secret Key for accepter account"
}
34 changes: 26 additions & 8 deletions examples/multi-account-single-region/provider.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
// This provider example is designed to work with Localstack.
// You need to have a real AWS provider configuration for the production usage.
provider "aws" {
alias = "this"
region = "ap-southeast-2"
access_key = var.aws_this_access_key
secret_key = var.aws_this_secret_key
alias = "this"
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "ap-southeast-2"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}

provider "aws" {
alias = "peer"
region = "ap-southeast-2"
access_key = var.aws_peer_access_key
secret_key = var.aws_peer_secret_key
alias = "peer"
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "ap-southeast-2"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}
17 changes: 0 additions & 17 deletions examples/multi-account-single-region/variables.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
// Variables are required to pass them via Terratest
// on fixtures creation
variable "this_vpc_id" {}

variable "peer_vpc_id" {}

variable "aws_this_access_key" {
description = "AWS Access Key for requester account"
}

variable "aws_this_secret_key" {
description = "AWS Secret Key for requester account"
}

variable "aws_peer_access_key" {
description = "AWS Access Key for accepter account"
}

variable "aws_peer_secret_key" {
description = "AWS Secret Key for accepter account"
}
32 changes: 22 additions & 10 deletions examples/partial-subnets/provider.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
// This provider example is designed to work with Localstack.
// You need to have a real AWS provider configuration for the production usage.
provider "aws" {
alias = "this"
region = var.this_region != "" ? var.this_region : "eu-west-2"
assume_role {
role_arn = var.this_assume_role_arn != "" ? var.this_assume_role_arn : null
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
access_key = var.aws_this_access_key != "" ? var.aws_this_access_key : null
secret_key = var.aws_this_secret_key != "" ? var.aws_this_secret_key : null
region = "eu-west-2"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}

provider "aws" {
alias = "peer"
region = var.peer_region != "" ? var.peer_region : "eu-central-1"
assume_role {
role_arn = var.peer_assume_role_arn != "" ? var.peer_assume_role_arn : null
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
access_key = var.aws_peer_access_key != "" ? var.aws_peer_access_key : null
secret_key = var.aws_peer_secret_key != "" ? var.aws_peer_secret_key : null
region = "eu-central-1"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}

34 changes: 26 additions & 8 deletions examples/single-account-multi-region/provider.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
// This provider example is designed to work with Localstack.
// You need to have a real AWS provider configuration for the production usage.
provider "aws" {
alias = "this"
region = "eu-west-1"
access_key = var.aws_this_access_key
secret_key = var.aws_this_secret_key
alias = "this"
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "eu-west-1"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}

provider "aws" {
alias = "peer"
region = "eu-central-1"
access_key = var.aws_this_access_key
secret_key = var.aws_this_secret_key
alias = "peer"
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "eu-central-1"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}
9 changes: 0 additions & 9 deletions examples/single-account-multi-region/variables.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
// Variables are required to pass them via Terratest
// on fixtures creation
variable "this_vpc_id" {}

variable "peer_vpc_id" {}

variable "aws_this_access_key" {
description = "AWS Access Key for requester account"
}

variable "aws_this_secret_key" {
description = "AWS Secret Key for requester account"
}
16 changes: 13 additions & 3 deletions examples/single-account-single-region-with-options/provider.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
// This provider example is designed to work with Localstack.
// You need to have a real AWS provider configuration for the production usage.
provider "aws" {
region = "eu-west-1"
access_key = var.aws_this_access_key
secret_key = var.aws_this_secret_key
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "eu-west-1"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}
17 changes: 0 additions & 17 deletions examples/single-account-single-region-with-options/variables.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
// Variables are required to pass them via Terratest
// on fixtures creation
variable "this_vpc_id" {}

variable "peer_vpc_id" {}

variable "aws_this_access_key" {
description = "AWS Access Key for requester account"
}

variable "aws_this_secret_key" {
description = "AWS Secret Key for requester account"
}

variable "aws_peer_access_key" {
description = "AWS Access Key for accepter account"
}

variable "aws_peer_secret_key" {
description = "AWS Secret Key for accepter account"
}
Loading

0 comments on commit 1eeca19

Please sign in to comment.