Skip to content

Commit

Permalink
Added tags to find vpc (#10)
Browse files Browse the repository at this point in the history
* Added tags to find vpc

* Added tags to find vpc

* Apply suggestions from code review

Co-Authored-By: goruha <goruha@gmail.com>

* Address comments

* Address comments

* Address comments
  • Loading branch information
goruha authored Apr 12, 2019
1 parent d0a4315 commit b76e9be
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 10 deletions.
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are

## Usage

**IMPORTANT:** Using the `master` branch is just an example.
Do not pin to `master` in your code because there may be breaking changes between releases.
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-vpc-peering/releases).


### Using VPC IDs

```hcl
module "vpc_peering" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc-peering.git?ref=master"
Expand All @@ -59,6 +66,23 @@ module "vpc_peering" {
}
```

### Using VPC tags

```hcl
module "vpc_peering" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc-peering.git?ref=master"
namespace = "cp"
stage = "dev"
name = "cluster"
requestor_vpc_tags = {
"kubernetes.io/cluster/my-k8s" = "owned"
}
acceptor_vpc_tags = {
Name = "legacy-vpc"
}
}
```




Expand All @@ -74,21 +98,22 @@ Available targets:
lint Lint terraform code
```

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| acceptor_allow_remote_vpc_dns_resolution | Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC | string | `true` | no |
| acceptor_vpc_id | Acceptor VPC ID | string | - | yes |
| acceptor_vpc_id | Acceptor VPC ID | string | `` | no |
| acceptor_vpc_tags | Acceptor VPC tags | map | `<map>` | no |
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
| auto_accept | Automatically accept the peering (both VPCs need to be in the same AWS account) | string | `true` | no |
| delimiter | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | string | `-` | no |
| enabled | Set to false to prevent the module from creating or accessing any resources | string | `true` | no |
| name | Name (e.g. `app` or `cluster`) | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
| requestor_allow_remote_vpc_dns_resolution | Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC | string | `true` | no |
| requestor_vpc_id | Requestor VPC ID | string | - | yes |
| requestor_vpc_id | Requestor VPC ID | string | `` | no |
| requestor_vpc_tags | Requestor VPC tags | map | `<map>` | no |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| tags | Additional tags (e.g. map('BusinessUnit`,`XYZ`) | map | `<map>` | no |

Expand Down Expand Up @@ -188,7 +213,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

## Copyright

Copyright © 2017-2018 [Cloud Posse, LLC](https://cpco.io/copyright)
Copyright © 2017-2019 [Cloud Posse, LLC](https://cpco.io/copyright)



Expand Down
27 changes: 26 additions & 1 deletion README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ description: |-
# How to use this project
usage: |-
**IMPORTANT:** Using the `master` branch is just an example.
Do not pin to `master` in your code because there may be breaking changes between releases.
Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases](https://github.com/cloudposse/terraform-aws-vpc-peering/releases).
### Using VPC IDs
```hcl
module "vpc_peering" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc-peering.git?ref=master"
Expand All @@ -69,6 +76,24 @@ usage: |-
}
```
### Using VPC tags
```hcl
module "vpc_peering" {
source = "git::https://github.com/cloudposse/terraform-aws-vpc-peering.git?ref=master"
namespace = "cp"
stage = "dev"
name = "cluster"
requestor_vpc_tags = {
"kubernetes.io/cluster/my-k8s" = "owned"
}
acceptor_vpc_tags = {
Name = "legacy-vpc"
}
}
```
references:
- name: "terraform-aws-vpc-kops-peering"
description: "Thanks to [Gladly.com](https://www.gladly.com/) for the inspiration with this wonderful module"
Expand All @@ -88,4 +113,4 @@ contributors:
- name: "Andriy Knysh"
github: "aknysh"
- name: "Vladimir"
github: "SweetOps"
github: "SweetOps"
7 changes: 4 additions & 3 deletions docs/terraform.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| acceptor_allow_remote_vpc_dns_resolution | Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC | string | `true` | no |
| acceptor_vpc_id | Acceptor VPC ID | string | - | yes |
| acceptor_vpc_id | Acceptor VPC ID | string | `` | no |
| acceptor_vpc_tags | Acceptor VPC tags | map | `<map>` | no |
| attributes | Additional attributes (e.g. `policy` or `role`) | list | `<list>` | no |
| auto_accept | Automatically accept the peering (both VPCs need to be in the same AWS account) | string | `true` | no |
| delimiter | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | string | `-` | no |
| enabled | Set to false to prevent the module from creating or accessing any resources | string | `true` | no |
| name | Name (e.g. `app` or `cluster`) | string | - | yes |
| namespace | Namespace (e.g. `cp` or `cloudposse`) | string | - | yes |
| requestor_allow_remote_vpc_dns_resolution | Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC | string | `true` | no |
| requestor_vpc_id | Requestor VPC ID | string | - | yes |
| requestor_vpc_id | Requestor VPC ID | string | `` | no |
| requestor_vpc_tags | Requestor VPC tags | map | `<map>` | no |
| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes |
| tags | Additional tags (e.g. map('BusinessUnit`,`XYZ`) | map | `<map>` | no |

Expand Down
6 changes: 4 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module "label" {

resource "aws_vpc_peering_connection" "default" {
count = "${var.enabled == "true" ? 1 : 0}"
vpc_id = "${var.requestor_vpc_id}"
peer_vpc_id = "${var.acceptor_vpc_id}"
vpc_id = "${join("", data.aws_vpc.requestor.*.id)}"
peer_vpc_id = "${join("", data.aws_vpc.acceptor.*.id)}"

auto_accept = "${var.auto_accept}"

Expand All @@ -31,6 +31,7 @@ resource "aws_vpc_peering_connection" "default" {
data "aws_vpc" "requestor" {
count = "${var.enabled == "true" ? 1 : 0}"
id = "${var.requestor_vpc_id}"
tags = "${var.requestor_vpc_tags}"
}

# Lookup requestor route tables
Expand All @@ -49,6 +50,7 @@ data "aws_subnet_ids" "requestor" {
data "aws_vpc" "acceptor" {
count = "${var.enabled == "true" ? 1 : 0}"
id = "${var.acceptor_vpc_id}"
tags = "${var.acceptor_vpc_tags}"
}

# Lookup acceptor subnets
Expand Down
14 changes: 14 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,25 @@ variable "enabled" {
variable "requestor_vpc_id" {
type = "string"
description = "Requestor VPC ID"
default = ""
}

variable "requestor_vpc_tags" {
type = "map"
description = "Requestor VPC tags"
default = {}
}

variable "acceptor_vpc_id" {
type = "string"
description = "Acceptor VPC ID"
default = ""
}

variable "acceptor_vpc_tags" {
type = "map"
description = "Acceptor VPC tags"
default = {}
}

variable "auto_accept" {
Expand Down

0 comments on commit b76e9be

Please sign in to comment.