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

Add E2E EKS Terraform environment. #430

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 16 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
118 changes: 118 additions & 0 deletions terraform/e2e/eks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

module "common" {
source = "../../common"
}

module "basic_components" {
source = "../../basic_components"
}

locals {
aws_eks = "aws eks"
cluster_name = var.cluster_name != "" ? var.cluster_name : "cwagent-monitoring-config-e2e-eks"
musa-asad marked this conversation as resolved.
Show resolved Hide resolved
}

data "aws_eks_cluster_auth" "this" {
name = aws_eks_cluster.this.name
}

resource "aws_eks_cluster" "this" {
name = "${local.cluster_name}-${module.common.testing_id}"
role_arn = module.basic_components.role_arn
version = var.k8s_version
vpc_config {
subnet_ids = module.basic_components.public_subnet_ids
security_group_ids = [module.basic_components.security_group]
}
}

resource "aws_eks_node_group" "this" {
cluster_name = aws_eks_cluster.this.name
node_group_name = "${local.cluster_name}-node"
node_role_arn = aws_iam_role.node_role.arn
subnet_ids = module.basic_components.public_subnet_ids

scaling_config {
desired_size = 2
max_size = 2
min_size = 2
}

ami_type = "AL2_x86_64"
capacity_type = "ON_DEMAND"
disk_size = 20
instance_types = ["t3a.medium"]

depends_on = [
aws_iam_role_policy_attachment.node_CloudWatchAgentServerPolicy,
aws_iam_role_policy_attachment.node_AmazonEC2ContainerRegistryReadOnly,
aws_iam_role_policy_attachment.node_AmazonEKS_CNI_Policy,
aws_iam_role_policy_attachment.node_AmazonEKSWorkerNodePolicy
]
}

resource "aws_iam_role" "node_role" {
name = "${local.cluster_name}-Worker-Role-${module.common.testing_id}"

assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}

resource "aws_iam_role_policy_attachment" "node_AmazonEKSWorkerNodePolicy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy"
role = aws_iam_role.node_role.name
}

resource "aws_iam_role_policy_attachment" "node_AmazonEKS_CNI_Policy" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy"
role = aws_iam_role.node_role.name
}

resource "aws_iam_role_policy_attachment" "node_AmazonEC2ContainerRegistryReadOnly" {
policy_arn = "arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
role = aws_iam_role.node_role.name
}

resource "aws_iam_role_policy_attachment" "node_CloudWatchAgentServerPolicy" {
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
role = aws_iam_role.node_role.name
}

resource "null_resource" "test" {
depends_on = [aws_eks_cluster.this, aws_eks_node_group.this]

provisioner "local-exec" {
command = <<-EOT
go test -v ${var.validate_test} \
-region=${var.region} \
-k8s_version=${var.k8s_version} \
-cluster_name=${aws_eks_cluster.this.name} \
-helm_charts_branch=${var.helm_charts_branch} \
-cloudwatch_agent_repository=${var.cloudwatch_agent_repository} \
-cloudwatch_agent_tag=${var.cloudwatch_agent_tag} \
-cloudwatch_agent_repository_url=${var.cloudwatch_agent_repository_url} \
-cloudwatch_agent_operator_repository=${var.cloudwatch_agent_operator_repository} \
-cloudwatch_agent_operator_tag=${var.cloudwatch_agent_operator_tag} \
-cloudwatch_agent_operator_repository_url=${var.cloudwatch_agent_operator_repository_url} \
-agent_config=${var.agent_config} \
-otel_config=${var.otel_config} \
-prometheus_config=${var.prometheus_config} \
-sample_app=${var.sample_app} \
-sample_app_name=${var.sample_app_name}
EOT
}
}
15 changes: 15 additions & 0 deletions terraform/e2e/eks/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

terraform {
required_providers {
docker = {
source = "kreuzwerker/docker"
version = "3.0.2"
}
}
}

provider "aws" {
region = var.region
}
82 changes: 82 additions & 0 deletions terraform/e2e/eks/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

variable "region" {
type = string
default = "us-west-2"
}

variable "k8s_version" {
type = string
default = "1.31"
}

variable "cluster_name" {
type = string
default = "cwagent-otel-config-e2e-eks"
}

variable "helm_charts_branch" {
type = string
default = "main"
}

variable "cloudwatch_agent_repository" {
type = string
default = "cloudwatch-agent"
}

variable "cloudwatch_agent_tag" {
type = string
default = "latest"
}

variable "cloudwatch_agent_repository_url" {
type = string
default = "public.ecr.aws/cloudwatch-agent"
}

variable "cloudwatch_agent_operator_repository" {
type = string
default = "cloudwatch-agent-operator"
}

variable "cloudwatch_agent_operator_tag" {
type = string
default = "latest"
}

variable "cloudwatch_agent_operator_repository_url" {
type = string
default = "public.ecr.aws/cloudwatch-agent"
}

variable "validate_test" {
type = string
default = ""
}

variable "agent_config" {
type = string
default = ""
}

variable "otel_config" {
type = string
default = ""
}

variable "prometheus_config" {
type = string
default = ""
}

variable "sample_app" {
type = string
default = ""
}

variable "sample_app_name" {
type = string
default = ""
}
Loading