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 8 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
128 changes: 128 additions & 0 deletions terraform/e2e/eks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// 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 --region ${var.region}"
musa-asad marked this conversation as resolved.
Show resolved Hide resolved
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" "kubectl" {
depends_on = [
aws_eks_cluster.this,
aws_eks_node_group.this
]
provisioner "local-exec" {
command = <<-EOT
${local.aws_eks} update-kubeconfig --name ${aws_eks_cluster.this.name}
musa-asad marked this conversation as resolved.
Show resolved Hide resolved
${local.aws_eks} list-clusters --output text
musa-asad marked this conversation as resolved.
Show resolved Hide resolved
${local.aws_eks} describe-cluster --name ${aws_eks_cluster.this.name} --output text
EOT
}
}

resource "null_resource" "helm_charts" {
provisioner "local-exec" {
command = <<-EOT
git clone https://github.com/aws-observability/helm-charts.git helm-charts
cd helm-charts
git checkout ${var.helm_charts_branch}
EOT
}

provisioner "local-exec" {
when = destroy
musa-asad marked this conversation as resolved.
Show resolved Hide resolved
command = "rm -rf ${path.module}/helm-charts"
}
}
musa-asad marked this conversation as resolved.
Show resolved Hide resolved
musa-asad marked this conversation as resolved.
Show resolved Hide resolved

resource "null_resource" "test" {
provisioner "local-exec" {
command = "go test -v ${var.validate_test}"
}
}
25 changes: 25 additions & 0 deletions terraform/e2e/eks/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 "docker" {
musa-asad marked this conversation as resolved.
Show resolved Hide resolved
host = "unix:///var/run/docker.sock"
}

provider "aws" {
region = var.region
}

provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}
92 changes: 92 additions & 0 deletions terraform/e2e/eks/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// 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 "agent_branch" {
type = string
default = "main"
}

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

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

variable "otel-config" {
type = string
default = ""
}

variable "agent-config" {
type = string
default = "../../../test/e2e/jmx/files/cwagent_configs/jvm_tomcat.json"
}

variable "prometheus-config" {
type = string
default = ""
}

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 = "../../../test/e2e/jmx/validate_test.go"
}

variable "sample-app" {
musa-asad marked this conversation as resolved.
Show resolved Hide resolved
musa-asad marked this conversation as resolved.
Show resolved Hide resolved
type = string
default = "../../../test/e2e/jmx/files/sample_applications/tomcat-deployment.yaml"
}

variable "sample-app-name" {
type = string
default = "tomcat-deployment"
}
Loading