Skip to content

Commit

Permalink
fix(DMVP-2544): Fixed bugs in vpc links for api gw module.
Browse files Browse the repository at this point in the history
  • Loading branch information
viktoryathegreat committed Sep 18, 2023
1 parent 9a7bb22 commit 39ecb9b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 4 deletions.
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,6 @@ module "api-gw-controller" {
deploy_region = var.api_gw_deploy_region

api_gateway_resources = var.api_gateway_resources
vpc_id = module.vpc[0].id
subnet_ids = var.vpc.create.private_subnets != {} ? module.vpc[0].private_subnets : var.vpc.link.private_subnet_ids
vpc_id = var.api_gateway_resources[0].vpc_links != null ? module.vpc[0].id : null
subnet_ids = var.api_gateway_resources[0].vpc_links != null ? (var.vpc.create.private_subnets != {} ? module.vpc[0].private_subnets : var.vpc.link.private_subnet_ids) : null
}
6 changes: 6 additions & 0 deletions modules/api-gw/tests/basic/0-setup.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# data
provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}
3 changes: 3 additions & 0 deletions modules/api-gw/tests/basic/1-example.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module "basic" {
source = "../.."
}
29 changes: 29 additions & 0 deletions modules/api-gw/tests/basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# basic

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

No providers.

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_basic"></a> [basic](#module\_basic) | ../.. | n/a |

## Resources

No resources.

## Inputs

No inputs.

## Outputs

No outputs.
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1 change: 1 addition & 0 deletions modules/api-gw/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ variable "deploy_region" {
variable "vpc_id" {
type = string
}

variable "subnet_ids" {
type = list(string)
}
Expand Down
5 changes: 3 additions & 2 deletions modules/api-gw/vpc-links.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
data "aws_region" "this" {}

data "aws_subnet" "selected" {
count = length(local.subnet_ids)
count = var.api_gateway_resources[0].vpc_links != null ? length(local.subnet_ids) : 0
id = local.subnet_ids[count.index]
}

Expand All @@ -17,13 +17,14 @@ resource "kubernetes_manifest" "vpc_link" {
}
spec = {
name = each.value.name
securityGroupIDs = [aws_security_group.api-gw-sg.id]
securityGroupIDs = [aws_security_group.api-gw-sg[0].id]
subnetIDs = var.subnet_ids
}
}
}

resource "aws_security_group" "api-gw-sg" {
count = var.api_gateway_resources[0].vpc_links != null ? 1 : 0
vpc_id = var.vpc_id
name = "aws-api-gw-${var.cluster_name}-${data.aws_region.this.name}-sg"
description = "Allow traffic from EKS to API gateway"
Expand Down

0 comments on commit 39ecb9b

Please sign in to comment.