Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make ecr user and token as variables #37

Merged
merged 6 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module "eks_ack_addons" {
source = "aws-ia/eks-ack-addons/aws"

cluster_id = "example-ack"
ecrpublic_username = local.ecrpublic_username
ecrpublic_token = local.ecrpublic_token

enable_api_gatewayv2 = true
enable_dynamodb = true
Expand Down Expand Up @@ -63,7 +65,6 @@ Examples codified under the [`examples`](https://github.com/aws-ia/terraform-aws
| [aws_iam_policy.emrcontainers](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
| [time_sleep.dataplane](https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep) | resource |
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_ecrpublic_authorization_token.token](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ecrpublic_authorization_token) | data source |
| [aws_eks_cluster.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/eks_cluster) | data source |
| [aws_iam_policy.amp](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy) | data source |
| [aws_iam_policy.api_gatewayv2_admin](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy) | data source |
Expand All @@ -84,6 +85,8 @@ Examples codified under the [`examples`](https://github.com/aws-ia/terraform-aws
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | EKS Cluster Id | `string` | n/a | yes |
| <a name="input_data_plane_wait_arn"></a> [data\_plane\_wait\_arn](#input\_data\_plane\_wait\_arn) | Addon deployment will not proceed until this value is known. Set to node group/Fargate profile ARN to wait for data plane to be ready before provisioning addons | `string` | `""` | no |
| <a name="input_dynamodb_helm_config"></a> [dynamodb\_helm\_config](#input\_dynamodb\_helm\_config) | ACK dynamodb Helm Chart config | `any` | `{}` | no |
| <a name="input_ecrpublic_token"></a> [ecrpublic\_token](#input\_ecrpublic\_token) | EKS Cluster Id | `string` | n/a | yes |
| <a name="input_ecrpublic_username"></a> [ecrpublic\_username](#input\_ecrpublic\_username) | EKS Cluster Id | `string` | n/a | yes |
| <a name="input_emrcontainers_helm_config"></a> [emrcontainers\_helm\_config](#input\_emrcontainers\_helm\_config) | ACK EMR container Helm Chart config | `any` | `{}` | no |
| <a name="input_enable_amp"></a> [enable\_amp](#input\_enable\_amp) | Enable ACK amp add-on | `bool` | `false` | no |
| <a name="input_enable_api_gatewayv2"></a> [enable\_api\_gatewayv2](#input\_enable\_api\_gatewayv2) | Enable ACK API gateway v2 add-on | `bool` | `false` | no |
Expand Down
21 changes: 19 additions & 2 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ provider "aws" {
region = var.aws_region
}

# This provider is required for ECR to autheticate with public repos. Please note ECR authetication requires us-east-1 as region hence its hardcoded below.
# If your region is same as us-east-1 then you can just use one aws provider
provider "aws" {
alias = "ecr"
region = "us-east-1"
}

data "aws_ecrpublic_authorization_token" "token" {
provider = aws.ecr
}

provider "kubernetes" {
host = module.eks_blueprints.eks_cluster_endpoint
cluster_ca_certificate = base64decode(module.eks_blueprints.eks_cluster_certificate_authority_data)
Expand All @@ -25,7 +36,10 @@ data "aws_caller_identity" "current" {}
data "aws_partition" "current" {}

locals {
name = "ack-eks-${basename(path.cwd)}"
name = "ack-eks-${basename(path.cwd)}"
ecrpublic_username = data.aws_ecrpublic_authorization_token.token.user_name
ecrpublic_token = data.aws_ecrpublic_authorization_token.token.password


vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)
Expand Down Expand Up @@ -91,7 +105,10 @@ module "eks_blueprints_kubernetes_addons" {
module "eks_ack_addons" {
source = "../../"

cluster_id = module.eks_blueprints.eks_cluster_id
cluster_id = module.eks_blueprints.eks_cluster_id
ecrpublic_username = local.ecrpublic_username
ecrpublic_token = local.ecrpublic_token


# Wait for data plane to be ready
data_plane_wait_arn = module.eks_blueprints.managed_node_group_arn[0]
Expand Down
30 changes: 15 additions & 15 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ data "aws_eks_cluster" "this" {
name = local.cluster_id
}

# Equivalent of aws ecr get-login
data "aws_ecrpublic_authorization_token" "token" {}

locals {
# this makes downstream resources wait for data plane to be ready
cluster_id = time_sleep.dataplane.triggers["cluster_id"]
region = data.aws_region.current.name

eks_oidc_issuer_url = replace(data.aws_eks_cluster.this.identity[0].oidc[0].issuer, "https://", "")

ecrpublic_username = var.ecrpublic_username
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We don't need to re-wrap these as locals. Just use them directly. You can delete these two lines here and just change the local.ecr* to var.ecr*

ecrpublic_token = var.ecrpublic_token

addon_context = {
aws_caller_identity_account_id = data.aws_caller_identity.current.account_id
aws_caller_identity_arn = data.aws_caller_identity.current.arn
Expand Down Expand Up @@ -60,8 +60,8 @@ module "api_gatewayv2" {
repository = "oci://public.ecr.aws/aws-controllers-k8s"
version = "v0.1.4"
namespace = local.api_gatewayv2_name
repository_username = data.aws_ecrpublic_authorization_token.token.user_name
repository_password = data.aws_ecrpublic_authorization_token.token.password
repository_username = local.ecrpublic_username
repository_password = local.ecrpublic_token
description = "ACK API Gateway Controller v2 Helm chart deployment configuration"
values = [
# shortens pod name from `ack-api-gatewayv2-apigatewayv2-chart-xxxxxxxxxxxxx` to `ack-api-gatewayv2-xxxxxxxxxxxxx`
Expand Down Expand Up @@ -136,8 +136,8 @@ module "dynamodb" {
repository = "oci://public.ecr.aws/aws-controllers-k8s"
version = "v0-stable"
namespace = local.dynamodb_name
repository_username = data.aws_ecrpublic_authorization_token.token.user_name
repository_password = data.aws_ecrpublic_authorization_token.token.password
repository_username = local.ecrpublic_username
repository_password = local.ecrpublic_token
description = "ACK DynamoDB Controller v2 Helm chart deployment configuration"
values = [
# shortens pod name from `ack-dynamodb-dynamodb-chart-xxxxxxxxxxxxx` to `ack-dynamodb-xxxxxxxxxxxxx`
Expand Down Expand Up @@ -203,8 +203,8 @@ module "s3" {
repository = "oci://public.ecr.aws/aws-controllers-k8s"
version = "v0.1.5"
namespace = local.s3_name
repository_username = data.aws_ecrpublic_authorization_token.token.user_name
repository_password = data.aws_ecrpublic_authorization_token.token.password
repository_username = local.ecrpublic_username
repository_password = local.ecrpublic_token
description = "ACK S3 Controller v2 Helm chart deployment configuration"
values = [
# shortens pod name from `ack-s3-s3-chart-xxxxxxxxxxxxx` to `ack-s3-xxxxxxxxxxxxx`
Expand Down Expand Up @@ -270,8 +270,8 @@ module "rds" {
repository = "oci://public.ecr.aws/aws-controllers-k8s"
version = "v0.1.1"
namespace = local.rds_name
repository_username = data.aws_ecrpublic_authorization_token.token.user_name
repository_password = data.aws_ecrpublic_authorization_token.token.password
repository_username = local.ecrpublic_username
repository_password = local.ecrpublic_token
create_namespace = true
description = "ACK RDS Controller v2 Helm chart deployment configuration"
values = [
Expand Down Expand Up @@ -338,8 +338,8 @@ module "amp" {
repository = "oci://public.ecr.aws/aws-controllers-k8s"
version = "v0.1.1"
namespace = local.amp_name
repository_username = data.aws_ecrpublic_authorization_token.token.user_name
repository_password = data.aws_ecrpublic_authorization_token.token.password
repository_username = local.ecrpublic_username
repository_password = local.ecrpublic_token
create_namespace = true
description = "ACK amp Controller v2 Helm chart deployment configuration"
values = [
Expand Down Expand Up @@ -406,8 +406,8 @@ module "emrcontainers" {
repository = "oci://public.ecr.aws/aws-controllers-k8s"
version = "v0-stable"
namespace = local.emr_name
repository_username = data.aws_ecrpublic_authorization_token.token.user_name
repository_password = data.aws_ecrpublic_authorization_token.token.password
repository_username = local.ecrpublic_username
repository_password = local.ecrpublic_token
description = "Helm Charts for the emrcontainers controller for AWS Controllers for Kubernetes (ACK)"
values = [
# shortens pod name from `ack-emrcontainers-emrcontainers-chart-xxxxxxxxxxxxx` to `ack-emrcontainers-xxxxxxxxxxxxx`
Expand Down
10 changes: 10 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ variable "cluster_id" {
type = string
}

variable "ecrpublic_username" {
description = "EKS Cluster Id"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type = string
}

variable "ecrpublic_token" {
description = "EKS Cluster Id"
victorgu-github marked this conversation as resolved.
Show resolved Hide resolved
type = string
}

variable "data_plane_wait_arn" {
description = "Addon deployment will not proceed until this value is known. Set to node group/Fargate profile ARN to wait for data plane to be ready before provisioning addons"
type = string
Expand Down