Skip to content

Commit

Permalink
check vpc exists just if required to create a vgw. Fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Cobles committed Jul 26, 2022
1 parent 7775d73 commit c9adc91
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ See <https://registry.terraform.io/modules/equinix-labs/fabric-connection-aws/eq

- [Fabric Port connection](https://registry.terraform.io/modules/equinix-labs/fabric-connection-aws/equinix/latest/examples/fabric-port-connection/)
- [Network Edge device connection](https://registry.terraform.io/modules/equinix-labs/fabric-connection-aws/equinix/latest/examples/network-edge-device-connection/)
- [Service Token (a-side) Equinix Metal to AWS connection](https://registry.terraform.io/modules/equinix-labs/fabric-connection-aws/equinix/latest/examples/service-token-metal-to-aws-connection/)
- [Service Token (a-side) Equinix Metal to AWS redundant connection End-to-End Solution](https://registry.terraform.io/modules/equinix-labs/fabric-connection-aws/equinix/latest/examples/service-token-metal-to-aws-connection/)
1 change: 1 addition & 0 deletions examples/service-token-metal-to-aws-connection/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ resource "equinix_metal_connection" "this" {
vlans = [equinix_metal_vlan.this.vxlan]
}

## Create an AWS VPC
resource "aws_vpc" "this" {
cidr_block = "10.0.0.0/16"
}
Expand Down
8 changes: 4 additions & 4 deletions examples/service-token-metal-to-aws-connection/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ variable "aws_account_id" {
}

variable "aws_region" {
type = string
type = string
description = <<EOF
The region for the AWS Direct connect, e.g. 'eu-west-1'. NOTE that 'aws_region' and 'fabric_destination_metro_code' must correspond to same location,
i.e Frankfurt will be: region = "eu-central-1" and fabric_destination_metro_code "FR"
EOF
default = "us-west-1"
default = "us-west-1"
}

variable "metal_project_id" {
type = string
description = "ID of the project where the connection is scoped to, used to look up the project."
description = "(Required) ID of the project where the connection is scoped to, used to look up the project."
}

variable "fabric_notification_users" {
type = list(string)
description = "A list of email addresses used for sending connection update notifications."
default = ["[email protected]"]
default = ["[email protected]"]
}

variable "fabric_destination_metro_code" {
Expand Down
7 changes: 5 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ locals {
if action_data["key"] == "awsConnectionId"
])
aws_vgw_id = var.aws_dx_create_vgw ? aws_vpn_gateway.this[0].id : var.aws_dx_vgw_id
aws_vpc_id = coalesce(var.aws_vpc_id, data.aws_vpc.this.id)
aws_vpc_id = var.aws_dx_create_vgw ? data.aws_vpc.this[0].id : ""
aws_region = data.aws_region.this.name
}

data "aws_region" "this" {}

data "aws_vpc" "this" {
default = true
count = var.aws_dx_create_vgw ? 1 : 0

id = var.aws_vpc_id == "" ? null : var.aws_vpc_id
default = var.aws_vpc_id == "" ? true : null
}

resource "random_string" "this" {
Expand Down
5 changes: 5 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ output "aws_vgw_id" {
value = try(local.aws_vgw_id, null)
}

output "aws_vpc_id" {
description = "AWS VPC ID."
value = try(local.aws_vpc_id, null)
}

output "aws_vif_id" {
description = "AWS Private Virtual Interface ID."
value = try(aws_dx_private_virtual_interface.this[0].id, null)
Expand Down
7 changes: 5 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ variable "aws_dx_vgw_id" {

variable "aws_vpc_id" {
type = string
description = "The ID of the VPC to connect with the AWS VGW. Applicable if 'aws_dx_create_vgw' is true. If not specified 'Default' VPC will be used."
description = <<EOF
The ID of the VPC to connect with the AWS VGW. Applicable if 'aws_dx_create_vgw' is true. If not specified 'Default'
VPC will be used (If applicable it will fail if there is no 'Default' VPC for the account in the selected region).
EOF
default = ""
}

variable "aws_vpn_gateway_name" {
type = string
description = "The name for the VPC VPN Gateway. It will be auto-generated if not specified."
description = "The name for the Virtual Private Gateway. It will be auto-generated if not specified."
default = ""
}

Expand Down

0 comments on commit c9adc91

Please sign in to comment.