-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial Implementation * Update `README` * Update `README` * Update `README` * Update `README`
- Loading branch information
Showing
9 changed files
with
317 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# Compiled files | ||
*.tfstate | ||
*.tfstate.backup | ||
.terraform.tfstate.lock.info | ||
|
||
# Module directory | ||
.terraform/ | ||
.idea | ||
terraform-aws-vpc-peering.iml |
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,16 @@ | ||
addons: | ||
apt: | ||
packages: | ||
- git | ||
- make | ||
- curl | ||
|
||
install: | ||
- make init | ||
|
||
script: | ||
- make terraform/install | ||
- make terraform/get-plugins | ||
- make terraform/get-modules | ||
- make terraform/lint | ||
- make terraform/validate |
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,6 @@ | ||
SHELL := /bin/bash | ||
|
||
-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness) | ||
|
||
lint: | ||
$(SELF) terraform/install terraform/get-modules terraform/get-plugins terraform/lint terraform/validate |
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 |
---|---|---|
@@ -1 +1,143 @@ | ||
# terraform-aws-vpc-peering | ||
# terraform-aws-vpc-peering [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-vpc-peering.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-vpc-peering) | ||
|
||
Terraform module to create a peering connection between two VPCs | ||
|
||
![vpc-peering](images/vpc-peering.png) | ||
|
||
|
||
## Usage | ||
|
||
```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_id = "vpc-XXXXXXXX" | ||
acceptor_vpc_id = "vpc-YYYYYYYY" | ||
} | ||
``` | ||
|
||
|
||
## Variables | ||
|
||
| Name | Default | Description | Required | | ||
|:---------------------------------------------|:---------------|:---------------------------------------------------------------------------------|:--------:| | ||
| `namespace` | `` | Namespace (_e.g._ `cp` or `cloudposse`) | Yes | | ||
| `stage` | `` | Stage (_e.g._ `prod`, `dev`, `staging`) | Yes | | ||
| `name` | `` | Name (_e.g._ `app` or `cluster`) | Yes | | ||
| `requestor_vpc_id` | `` | Requestor VPC ID | Yes | | ||
| `acceptor_vpc_id` | `` | Acceptor VPC ID | Yes | | ||
| `attributes` | `[]` | Additional attributes (_e.g._ `policy` or `role`) | No | | ||
| `tags` | `{}` | Additional tags (_e.g._ `map("BusinessUnit","XYZ")` | No | | ||
| `delimiter` | `-` | Delimiter to be used between `namespace`, `stage`, `name`, and `attributes` | No | | ||
| `enabled` | `true` | Set to `false` to prevent the module from creating or accessing any resources | No | | ||
| `auto_accept` | `true` | Automatically accept the peering (both VPCs need to be in the same AWS account) | No | | ||
| `acceptor_allow_remote_vpc_dns_resolution` | `true` | Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC | No | | ||
| `requestor_allow_remote_vpc_dns_resolution` | `true` | Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC | No | | ||
|
||
|
||
__NOTE:__ Both the acceptor and requestor VPCs must have subnets associated with route tables | ||
|
||
__NOTE:__ When enabled, the DNS resolution features (`acceptor_allow_remote_vpc_dns_resolution` and `requestor_allow_remote_vpc_dns_resolution`) | ||
require that VPCs participating in the peering must have support for the DNS hostnames enabled. | ||
This can be done using the [`enable_dns_hostnames`](https://www.terraform.io/docs/providers/aws/r/vpc.html#enable_dns_hostnames) attribute in the `aws_vpc` resource. | ||
|
||
https://www.terraform.io/docs/providers/aws/r/vpc_peering.html#allow_remote_vpc_dns_resolution | ||
|
||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|:--------------------------------|:--------------------------------------------------| | ||
| `connection_id` | VPC peering connection ID | | ||
| `accept_status` | The status of the VPC peering connection request | | ||
|
||
|
||
## Credits | ||
|
||
Thanks to [Gladly.com](https://www.gladly.com/) for the inspiration with this wonderful module: | ||
|
||
https://github.com/sagansystems/terraform-aws-vpc-kops-peering | ||
|
||
|
||
## Help | ||
|
||
**Got a question?** | ||
|
||
File a GitHub [issue](https://github.com/cloudposse/terraform-aws-vpc-peering/issues), send us an [email](mailto:hello@cloudposse.com) or reach out to us on [Gitter](https://gitter.im/cloudposse/). | ||
|
||
|
||
## Contributing | ||
|
||
### Bug Reports & Feature Requests | ||
|
||
Please use the [issue tracker](https://github.com/cloudposse/terraform-aws-vpc-peering/issues) to report any bugs or file feature requests. | ||
|
||
### Developing | ||
|
||
If you are interested in being a contributor and want to get involved in developing `terraform-aws-vpc-peering`, we would love to hear from you! Shoot us an [email](mailto:hello@cloudposse.com). | ||
|
||
In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow. | ||
|
||
1. **Fork** the repo on GitHub | ||
2. **Clone** the project to your own machine | ||
3. **Commit** changes to your own branch | ||
4. **Push** your work back up to your fork | ||
5. Submit a **Pull request** so that we can review your changes | ||
|
||
**NOTE:** Be sure to merge the latest from "upstream" before making a pull request! | ||
|
||
|
||
## License | ||
|
||
[APACHE 2.0](LICENSE) © 2018 [Cloud Posse, LLC](https://cloudposse.com) | ||
|
||
See [LICENSE](LICENSE) for full details. | ||
|
||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
|
||
|
||
## About | ||
|
||
`terraform-aws-vpc-peering` is maintained and funded by [Cloud Posse, LLC][website]. | ||
|
||
![Cloud Posse](https://cloudposse.com/logo-300x69.png) | ||
|
||
|
||
Like it? Please let us know at <hello@cloudposse.com> | ||
|
||
We love [Open Source Software](https://github.com/cloudposse/)! | ||
|
||
See [our other projects][community] | ||
or [hire us][hire] to help build your next cloud platform. | ||
|
||
[website]: https://cloudposse.com/ | ||
[community]: https://github.com/cloudposse/ | ||
[hire]: https://cloudposse.com/contact/ | ||
|
||
|
||
## Contributors | ||
|
||
| [![Erik Osterman][erik_img]][erik_web]<br/>[Erik Osterman][erik_web] | [![Andriy Knysh][andriy_img]][andriy_web]<br/>[Andriy Knysh][andriy_web] | | ||
|-------------------------------------------------------|------------------------------------------------------------------| | ||
|
||
[erik_img]: http://s.gravatar.com/avatar/88c480d4f73b813904e00a5695a454cb?s=144 | ||
[erik_web]: https://github.com/osterman/ | ||
[andriy_img]: https://avatars0.githubusercontent.com/u/7356997?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144 | ||
[andriy_web]: https://github.com/aknysh/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,78 @@ | ||
module "label" { | ||
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.3" | ||
enabled = "${var.enabled}" | ||
namespace = "${var.namespace}" | ||
name = "${var.name}" | ||
stage = "${var.stage}" | ||
delimiter = "${var.delimiter}" | ||
attributes = "${var.attributes}" | ||
tags = "${var.tags}" | ||
} | ||
|
||
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}" | ||
|
||
auto_accept = "${var.auto_accept}" | ||
|
||
accepter { | ||
allow_remote_vpc_dns_resolution = "${var.acceptor_allow_remote_vpc_dns_resolution}" | ||
} | ||
|
||
requester { | ||
allow_remote_vpc_dns_resolution = "${var.requestor_allow_remote_vpc_dns_resolution}" | ||
} | ||
|
||
tags = "${module.label.tags}" | ||
} | ||
|
||
# Lookup requestor VPC so that we can reference the CIDR | ||
data "aws_vpc" "requestor" { | ||
count = "${var.enabled == "true" ? 1 : 0}" | ||
id = "${var.requestor_vpc_id}" | ||
} | ||
|
||
# Lookup requestor subnets | ||
data "aws_subnet_ids" "requestor" { | ||
vpc_id = "${var.requestor_vpc_id}" | ||
} | ||
|
||
# Lookup requestor route tables | ||
data "aws_route_table" "requestor" { | ||
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_subnet_ids.requestor.ids))) : 0}" | ||
subnet_id = "${element(distinct(sort(data.aws_subnet_ids.requestor.ids)), count.index)}" | ||
} | ||
|
||
# Lookup acceptor VPC so that we can reference the CIDR | ||
data "aws_vpc" "acceptor" { | ||
count = "${var.enabled == "true" ? 1 : 0}" | ||
id = "${var.acceptor_vpc_id}" | ||
} | ||
|
||
# Lookup acceptor subnets | ||
data "aws_subnet_ids" "acceptor" { | ||
vpc_id = "${var.acceptor_vpc_id}" | ||
} | ||
|
||
# Lookup acceptor route tables | ||
data "aws_route_table" "acceptor" { | ||
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_subnet_ids.acceptor.ids))) : 0}" | ||
subnet_id = "${element(distinct(sort(data.aws_subnet_ids.acceptor.ids)), count.index)}" | ||
} | ||
|
||
# Create a route from requestor to acceptor | ||
resource "aws_route" "requestor" { | ||
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_route_table.requestor.*.route_table_id))) : 0}" | ||
route_table_id = "${element(distinct(sort(data.aws_route_table.requestor.*.route_table_id)), count.index)}" | ||
destination_cidr_block = "${data.aws_vpc.acceptor.cidr_block}" | ||
vpc_peering_connection_id = "${aws_vpc_peering_connection.default.id}" | ||
} | ||
|
||
# Create a route from acceptor to requestor | ||
resource "aws_route" "acceptor" { | ||
count = "${var.enabled == "true" ? length(distinct(sort(data.aws_route_table.acceptor.*.route_table_id))) : 0}" | ||
route_table_id = "${element(distinct(sort(data.aws_route_table.acceptor.*.route_table_id)), count.index)}" | ||
destination_cidr_block = "${data.aws_vpc.requestor.cidr_block}" | ||
vpc_peering_connection_id = "${aws_vpc_peering_connection.default.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,7 @@ | ||
output "connection_id" { | ||
value = "${join("", aws_vpc_peering_connection.default.*.id)}" | ||
} | ||
|
||
output "accept_status" { | ||
value = "${join("", aws_vpc_peering_connection.default.*.accept_status)}" | ||
} |
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,62 @@ | ||
variable "enabled" { | ||
default = "true" | ||
description = "Set to false to prevent the module from creating or accessing any resources" | ||
} | ||
|
||
variable "requestor_vpc_id" { | ||
type = "string" | ||
description = "Requestor VPC ID" | ||
} | ||
|
||
variable "acceptor_vpc_id" { | ||
type = "string" | ||
description = "Acceptor VPC ID" | ||
} | ||
|
||
variable "auto_accept" { | ||
default = "true" | ||
description = "Automatically accept the peering (both VPCs need to be in the same AWS account)" | ||
} | ||
|
||
variable "acceptor_allow_remote_vpc_dns_resolution" { | ||
default = "true" | ||
description = "Allow acceptor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the requestor VPC" | ||
} | ||
|
||
variable "requestor_allow_remote_vpc_dns_resolution" { | ||
default = "true" | ||
description = "Allow requestor VPC to resolve public DNS hostnames to private IP addresses when queried from instances in the acceptor VPC" | ||
} | ||
|
||
variable "namespace" { | ||
description = "Namespace (e.g. `cp` or `cloudposse`)" | ||
type = "string" | ||
} | ||
|
||
variable "stage" { | ||
description = "Stage (e.g. `prod`, `dev`, `staging`)" | ||
type = "string" | ||
} | ||
|
||
variable "name" { | ||
description = "Name (e.g. `app` or `cluster`)" | ||
type = "string" | ||
} | ||
|
||
variable "delimiter" { | ||
type = "string" | ||
default = "-" | ||
description = "Delimiter to be used between `namespace`, `stage`, `name`, and `attributes`" | ||
} | ||
|
||
variable "attributes" { | ||
type = "list" | ||
default = [] | ||
description = "Additional attributes (e.g. `policy` or `role`)" | ||
} | ||
|
||
variable "tags" { | ||
type = "map" | ||
default = {} | ||
description = "Additional tags (e.g. map('BusinessUnit`,`XYZ`)" | ||
} |