Skip to content

Commit 6513223

Browse files
Benbentwonitrocode
andauthored
upstream echo-server with alb group and logging (cloudposse/terraform-aws-components#492)
* upstream echo-server with alb group and logging * Apply suggestions from code review Co-authored-by: nitrocode <[email protected]> * upd Co-authored-by: nitrocode <[email protected]>
1 parent 71575b6 commit 6513223

File tree

6 files changed

+85
-5
lines changed

6 files changed

+85
-5
lines changed

src/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ components:
8484
8585
| Name | Source | Version |
8686
|------|--------|---------|
87+
| <a name="module_alb_controller_ingress_group"></a> [alb\_controller\_ingress\_group](#module\_alb\_controller\_ingress\_group) | cloudposse/stack-config/yaml//modules/remote-state | 0.22.4 |
8788
| <a name="module_echo_server"></a> [echo\_server](#module\_echo\_server) | cloudposse/helm-release/aws | 0.5.0 |
8889
| <a name="module_eks"></a> [eks](#module\_eks) | cloudposse/stack-config/yaml//modules/remote-state | 0.22.4 |
8990
| <a name="module_iam_roles"></a> [iam\_roles](#module\_iam\_roles) | ../../account-map/modules/iam-roles | n/a |
@@ -103,6 +104,11 @@ components:
103104
| Name | Description | Type | Default | Required |
104105
|------|-------------|------|---------|:--------:|
105106
| <a name="input_additional_tag_map"></a> [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.<br>This is for some rare cases where resources want additional configuration of tags<br>and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
107+
| <a name="input_alb_access_logs_enabled"></a> [alb\_access\_logs\_enabled](#input\_alb\_access\_logs\_enabled) | Whether or not to enable access logs for the ALB | `bool` | `false` | no |
108+
| <a name="input_alb_access_logs_s3_bucket_name"></a> [alb\_access\_logs\_s3\_bucket\_name](#input\_alb\_access\_logs\_s3\_bucket\_name) | The name of the S3 bucket to store the access logs in | `string` | `null` | no |
109+
| <a name="input_alb_access_logs_s3_bucket_prefix"></a> [alb\_access\_logs\_s3\_bucket\_prefix](#input\_alb\_access\_logs\_s3\_bucket\_prefix) | The prefix to use when storing the access logs | `string` | `"echo-server"` | no |
110+
| <a name="input_alb_controller_ingress_group_component_name"></a> [alb\_controller\_ingress\_group\_component\_name](#input\_alb\_controller\_ingress\_group\_component\_name) | The name of the alb-controller-ingress-group component | `string` | `"eks/alb-controller-ingress-group"` | no |
111+
| <a name="input_alb_controller_ingress_group_enabled"></a> [alb\_controller\_ingress\_group\_enabled](#input\_alb\_controller\_ingress\_group\_enabled) | Uses alb-controller-ingress-group component for alb ingress group | `bool` | `false` | no |
106112
| <a name="input_atomic"></a> [atomic](#input\_atomic) | If set, installation process purges chart on fail. The wait flag will be set automatically if atomic is used. | `bool` | `true` | no |
107113
| <a name="input_attributes"></a> [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,<br>in the order they appear in the list. New attributes are appended to the<br>end of the list. The elements of the list are joined by the `delimiter`<br>and treated as a single ID element. | `list(string)` | `[]` | no |
108114
| <a name="input_chart_version"></a> [chart\_version](#input\_chart\_version) | Specify the exact chart version to install. If this is not specified, the latest version is installed. | `string` | `null` | no |
@@ -112,7 +118,7 @@ components:
112118
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
113119
| <a name="input_description"></a> [description](#input\_description) | Set release description attribute (visible in the history). | `string` | `null` | no |
114120
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
115-
| <a name="input_eks_component_name"></a> [eks\_component\_name](#input\_eks\_component\_name) | The name of the eks component | `string` | `"eks/eks"` | no |
121+
| <a name="input_eks_component_name"></a> [eks\_component\_name](#input\_eks\_component\_name) | The name of the eks component | `string` | `"eks/cluster"` | no |
116122
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
117123
| <a name="input_environment"></a> [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
118124
| <a name="input_helm_manifest_experiment_enabled"></a> [helm\_manifest\_experiment\_enabled](#input\_helm\_manifest\_experiment\_enabled) | Enable storing of the rendered manifest for helm\_release so the full diff of what is changing can been seen in the plan | `bool` | `true` | no |
@@ -157,4 +163,3 @@ components:
157163

158164
## References
159165
* https://github.com/Ealenn/Echo-Server
160-
* [cloudposse/terraform-aws-components](https://github.com/cloudposse/terraform-aws-components/tree/master/modules/eks/echo-server) - Cloud Posse's upstream component

src/charts/echo-server/templates/ingress.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ metadata:
1515
{{- end }}
1616
{{- else if eq (printf "%v" .Values.ingress.alb.enabled) "true" }}
1717
kubernetes.io/ingress.class: {{ .Values.ingress.alb.class }}
18+
{{- if not .Values.ingress.alb.group_name }}
1819
alb.ingress.kubernetes.io/load-balancer-name: {{ index .Values.ingress.alb "load_balancer_name" | default "k8s-common" }}
20+
{{- end }}
1921
alb.ingress.kubernetes.io/group.name: {{ index .Values.ingress.alb "group_name" | default "common" }}
2022
alb.ingress.kubernetes.io/scheme: internet-facing
23+
{{- if .Values.ingress.alb.access_logs.enabled }}
24+
alb.ingress.kubernetes.io/load-balancer-attributes: access_logs.s3.enabled=true,access_logs.s3.bucket={{.Values.ingress.alb.access_logs.s3_bucket_name}},access_logs.s3.prefix={{.Values.ingress.alb.access_logs.s3_bucket_prefix}}
25+
{{- end }}
2126
alb.ingress.kubernetes.io/target-type: 'ip'
2227
{{- if eq (printf "%v" .Values.ingress.alb.ssl_redirect.enabled) "true" }}
2328
alb.ingress.kubernetes.io/ssl-redirect: '{{ .Values.ingress.alb.ssl_redirect.port }}'

src/charts/echo-server/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ ingress:
6565
enabled: true
6666
## alb.ingress.kubernetes.io/ssl-redirect:
6767
port: 443
68+
access_logs:
69+
enabled: false
70+
## s3_bucket_name: "acme-ue2-prod-eks-cluster-alb-access-logs"
71+
s3_bucket_prefix: "echo-server"
6872

6973
#resources: {}
7074
# # We usually recommend not to specify default resources and to leave this as a conscious

src/main.tf

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ locals {
22
enabled = module.this.enabled
33
ingress_nginx_enabled = var.ingress_type == "nginx" ? true : false
44
ingress_alb_enabled = var.ingress_type == "alb" ? true : false
5+
6+
alb_access_logs_enabled = var.alb_access_logs_enabled && var.alb_access_logs_s3_bucket_name != null && var.alb_access_logs_s3_bucket_name != ""
7+
ingress_controller_group_enabled = var.alb_controller_ingress_group_enabled ? [
8+
{
9+
name = "ingress.alb.group_name"
10+
value = module.alb_controller_ingress_group.outputs.group_name
11+
type = "auto"
12+
}
13+
] : []
514
}
615

716
resource "kubernetes_namespace" "default" {
@@ -35,7 +44,7 @@ module "echo_server" {
3544

3645
eks_cluster_oidc_issuer_url = replace(module.eks.outputs.eks_cluster_identity_oidc_issuer, "https://", "")
3746

38-
set = [
47+
set = concat([
3948
{
4049
name = "ingress.hostname"
4150
value = format(var.hostname_template, var.tenant, var.stage, var.environment)
@@ -50,8 +59,25 @@ module "echo_server" {
5059
name = "ingress.alb.enabled"
5160
value = local.ingress_alb_enabled
5261
type = "auto"
62+
},
63+
{
64+
name = "ingress.alb.access_logs.enabled"
65+
value = local.alb_access_logs_enabled
66+
type = "auto"
67+
},
68+
{
69+
name = "ingress.alb.access_logs.s3_bucket_name"
70+
value = var.alb_access_logs_s3_bucket_name == null ? "" : var.alb_access_logs_s3_bucket_name
71+
type = "auto"
72+
},
73+
{
74+
name = "ingress.alb.access_logs.s3_bucket_prefix"
75+
value = var.alb_access_logs_s3_bucket_prefix
76+
type = "auto"
5377
}
54-
]
78+
],
79+
local.ingress_controller_group_enabled
80+
)
5581

5682
values = compact([
5783
# hardcoded values

src/remote-state.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ module "eks" {
66

77
context = module.this.context
88
}
9+
10+
module "alb_controller_ingress_group" {
11+
source = "cloudposse/stack-config/yaml//modules/remote-state"
12+
version = "0.22.4"
13+
14+
component = var.alb_controller_ingress_group_component_name
15+
16+
context = module.this.context
17+
}
18+

src/variables.tf

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,35 @@ variable "region" {
66
variable "eks_component_name" {
77
type = string
88
description = "The name of the eks component"
9-
default = "eks/eks"
9+
default = "eks/cluster"
10+
}
11+
12+
variable "alb_controller_ingress_group_component_name" {
13+
type = string
14+
description = "The name of the alb-controller-ingress-group component"
15+
default = "eks/alb-controller-ingress-group"
16+
}
17+
18+
variable "alb_controller_ingress_group_enabled" {
19+
type = bool
20+
description = "Uses alb-controller-ingress-group component for alb ingress group"
21+
default = false
22+
}
23+
24+
variable "alb_access_logs_enabled" {
25+
type = bool
26+
description = "Whether or not to enable access logs for the ALB"
27+
default = false
28+
}
29+
30+
variable "alb_access_logs_s3_bucket_name" {
31+
type = string
32+
description = "The name of the S3 bucket to store the access logs in"
33+
default = null
34+
}
35+
36+
variable "alb_access_logs_s3_bucket_prefix" {
37+
type = string
38+
description = "The prefix to use when storing the access logs"
39+
default = "echo-server"
1040
}

0 commit comments

Comments
 (0)