-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from dasmeta/DMVP-2544-api-gw-controller
DMVP-2544: Add API-Gateway submodule
- Loading branch information
Showing
11 changed files
with
226 additions
and
0 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
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,63 @@ | ||
# API Gateway controller | ||
|
||
To enable API-Gateway controller in EKS cluster you need to set | ||
```terraform | ||
module "eks" { | ||
... | ||
enable_api_gw_controller = true | ||
... | ||
} | ||
``` | ||
|
||
## How to deploy API from EKS using controller | ||
API, and its dependent parts (integrations, routes, ...) are deployed with CRDs | ||
which you can find [here](https://aws-controllers-k8s.github.io/community/docs/tutorials/apigatewayv2-reference-example/) | ||
|
||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.3 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.31 | | ||
| <a name="requirement_helm"></a> [helm](#requirement\_helm) | >= 2.4.1 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.31 | | ||
| <a name="provider_helm"></a> [helm](#provider\_helm) | >= 2.4.1 | | ||
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | n/a | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_iam_policy.policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | | ||
| [aws_iam_role.role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | | ||
| [helm_release.api-gw-release](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | | ||
| [kubernetes_service_account.servciceaccount](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/service_account) | resource | | ||
| [aws_caller_identity.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | ||
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_chart_version"></a> [chart\_version](#input\_chart\_version) | Chart version of api-gw | `string` | `"0.0.17"` | no | | ||
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Cluster name to pass to role | `string` | n/a | yes | | ||
| <a name="input_cluster_oidc_arn"></a> [cluster\_oidc\_arn](#input\_cluster\_oidc\_arn) | Cluster OIDC arn to pass to policy | `string` | n/a | yes | | ||
| <a name="input_deploy_region"></a> [deploy\_region](#input\_deploy\_region) | Region in which API gatewat will be configured | `string` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
No outputs. | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
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,26 @@ | ||
locals { | ||
oidc_id = split("/", var.cluster_oidc_arn)[3] | ||
} | ||
|
||
data "aws_region" "current" {} | ||
|
||
data "aws_caller_identity" "this" {} | ||
|
||
resource "aws_iam_policy" "policy" { | ||
name = "AmazonEKSClusterApiGateway-${var.cluster_name}-${data.aws_region.current.name}" | ||
path = "/" | ||
description = "Amazon EKS API gateway Policy" | ||
|
||
policy = templatefile("${path.module}/policies/api-gw-policy.json", { | ||
cluster_name = var.cluster_name | ||
}) | ||
} | ||
|
||
resource "aws_iam_role" "role" { | ||
name = "api-gw-${var.cluster_name}-${data.aws_region.current.name}" | ||
assume_role_policy = templatefile("${path.module}/policies/trusted-policy.json", { | ||
oidc = var.cluster_oidc_arn, | ||
current_region = data.aws_region.current.name, | ||
oidc_id = local.oidc_id }) | ||
managed_policy_arns = [aws_iam_policy.policy.arn] | ||
} |
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,19 @@ | ||
resource "helm_release" "api-gw-release" { | ||
depends_on = [kubernetes_service_account.servciceaccount] | ||
|
||
name = "api-gateway-controller" | ||
repository = "oci://public.ecr.aws/aws-controllers-k8s" | ||
chart = "apigatewayv2-chart" | ||
version = var.chart_version | ||
namespace = "kube-system" | ||
|
||
set { | ||
name = "serviceAccount.create" | ||
value = "false" | ||
} | ||
|
||
set { | ||
name = "aws.region" | ||
value = var.deploy_region == "" ? data.aws_region.current.name : var.deploy_region | ||
} | ||
} |
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,32 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Sid": "VisualEditor0", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"autoscaling:SetDesiredCapacity", | ||
"autoscaling:TerminateInstanceInAutoScalingGroup" | ||
], | ||
"Resource": "*", | ||
"Condition": { | ||
"StringEquals": { | ||
"aws:ResourceTag/k8s.io/cluster-autoscaler/${cluster_name}": "owned" | ||
} | ||
} | ||
}, | ||
{ | ||
"Sid": "VisualEditor1", | ||
"Effect": "Allow", | ||
"Action": [ | ||
"autoscaling:DescribeAutoScalingInstances", | ||
"autoscaling:DescribeAutoScalingGroups", | ||
"ec2:DescribeLaunchTemplateVersions", | ||
"autoscaling:DescribeTags", | ||
"autoscaling:DescribeLaunchConfigurations", | ||
"ec2:DescribeInstanceTypes" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} |
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,17 @@ | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Federated": "${oidc}" | ||
}, | ||
"Action": "sts:AssumeRoleWithWebIdentity", | ||
"Condition": { | ||
"StringEquals": { | ||
"oidc.eks.${current_region}.amazonaws.com/id/${oidc_id}:sub": "system:serviceaccount:kube-system:ack-apigatewayv2-controller" | ||
} | ||
} | ||
} | ||
] | ||
} |
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,9 @@ | ||
resource "kubernetes_service_account" "servciceaccount" { | ||
metadata { | ||
name = "api-gateway-controller" | ||
namespace = "kube-system" | ||
annotations = { | ||
"eks.amazonaws.com/role-arn" = aws_iam_role.role.arn | ||
} | ||
} | ||
} |
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,20 @@ | ||
variable "cluster_oidc_arn" { | ||
type = string | ||
description = "Cluster OIDC arn to pass to policy" | ||
} | ||
|
||
variable "cluster_name" { | ||
type = string | ||
description = "Cluster name to pass to role" | ||
} | ||
|
||
variable "chart_version" { | ||
description = "Chart version of api-gw" | ||
type = string | ||
default = "0.0.17" | ||
} | ||
|
||
variable "deploy_region" { | ||
description = "Region in which API gatewat will be configured" | ||
type = string | ||
} |
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,15 @@ | ||
terraform { | ||
required_version = "~> 1.3" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 3.31" | ||
} | ||
|
||
helm = { | ||
source = "hashicorp/helm" | ||
version = ">= 2.4.1" | ||
} | ||
} | ||
} |
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