-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Windows helm-chart tests. (#32)
Migrate Windows helm-chart tests.
- Loading branch information
1 parent
6d463b3
commit 05b76a5
Showing
8 changed files
with
442 additions
and
2 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
239 changes: 239 additions & 0 deletions
239
integration-tests/amazon-cloudwatch-observability/terraform/helm-windows/main.tf
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,239 @@ | ||
// 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}" | ||
cluster_name = var.cluster_name != "" ? var.cluster_name : "cwagent-helm-chart-integ" | ||
} | ||
|
||
data "aws_eks_cluster_auth" "this" { | ||
name = aws_eks_cluster.this.name | ||
} | ||
|
||
data "aws_caller_identity" "account_id" {} | ||
|
||
data "aws_eks_cluster" "eks_windows_cluster_ca" { | ||
name = aws_eks_cluster.this.name | ||
} | ||
|
||
output "account_id" { | ||
value = data.aws_caller_identity.account_id.account_id | ||
} | ||
|
||
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] | ||
} | ||
} | ||
|
||
## EKS Cluster Addon | ||
|
||
resource "aws_eks_addon" "eks_windows_addon" { | ||
cluster_name = aws_eks_cluster.this.name | ||
addon_name = "vpc-cni" | ||
} | ||
|
||
## Enable VPC CNI Windows Support | ||
|
||
resource "kubernetes_config_map_v1_data" "amazon_vpc_cni_windows" { | ||
depends_on = [ | ||
aws_eks_cluster.this, | ||
aws_eks_addon.eks_windows_addon | ||
] | ||
metadata { | ||
name = "amazon-vpc-cni" | ||
namespace = "kube-system" | ||
} | ||
|
||
force = true | ||
|
||
data = { | ||
enable-windows-ipam : "true" | ||
} | ||
} | ||
|
||
## AWS CONFIGMAP | ||
|
||
resource "kubernetes_config_map" "configmap" { | ||
data = { | ||
"mapRoles" = <<EOT | ||
- groups: | ||
- system:bootstrappers | ||
- system:nodes | ||
rolearn: arn:aws:iam::${data.aws_caller_identity.account_id.account_id}:role/${local.cluster_name}-Worker-Role-${module.common.testing_id} | ||
username: system:node:{{EC2PrivateDNSName}} | ||
- groups: | ||
- eks:kube-proxy-windows | ||
- system:bootstrappers | ||
- system:nodes | ||
rolearn: arn:aws:iam::${data.aws_caller_identity.account_id.account_id}:role/${local.cluster_name}-Worker-Role-${module.common.testing_id} | ||
username: system:node:{{EC2PrivateDNSName}} | ||
EOT | ||
} | ||
|
||
metadata { | ||
name = "aws-auth" | ||
namespace = "kube-system" | ||
} | ||
} | ||
|
||
# EKS Node Groups | ||
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 = 1 | ||
max_size = 1 | ||
min_size = 1 | ||
} | ||
|
||
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 | ||
] | ||
} | ||
|
||
# EKS Windows Node Groups | ||
resource "aws_eks_node_group" "node_group_windows" { | ||
cluster_name = aws_eks_cluster.this.name | ||
node_group_name = "${local.cluster_name}-windows-node" | ||
node_role_arn = aws_iam_role.node_role.arn | ||
subnet_ids = module.basic_components.public_subnet_ids | ||
|
||
scaling_config { | ||
desired_size = 1 | ||
max_size = 1 | ||
min_size = 1 | ||
} | ||
|
||
ami_type = var.windows_os_version | ||
capacity_type = "ON_DEMAND" | ||
disk_size = 50 | ||
instance_types = ["t3.large"] | ||
|
||
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 | ||
] | ||
} | ||
|
||
# EKS Node IAM Role | ||
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, | ||
aws_eks_node_group.node_group_windows | ||
] | ||
provisioner "local-exec" { | ||
command = <<-EOT | ||
${local.aws_eks} update-kubeconfig --name ${aws_eks_cluster.this.name} | ||
${local.aws_eks} list-clusters --output text | ||
${local.aws_eks} describe-cluster --name ${aws_eks_cluster.this.name} --output text | ||
EOT | ||
} | ||
} | ||
|
||
resource "helm_release" "this" { | ||
depends_on = [ | ||
null_resource.kubectl | ||
] | ||
name = "amazon-cloudwatch-observability" | ||
namespace = "amazon-cloudwatch" | ||
create_namespace = true | ||
chart = "${var.helm_dir}" | ||
set { | ||
name = "region" | ||
value = "${var.region}" | ||
} | ||
set { | ||
name = "clusterName" | ||
value = "${aws_eks_cluster.this.name}" | ||
} | ||
} | ||
|
||
resource "null_resource" "deployment_wait" { | ||
depends_on = [ | ||
helm_release.this, | ||
] | ||
provisioner "local-exec" { | ||
command = <<-EOT | ||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" | ||
chmod +x kubectl | ||
./kubectl rollout status daemonset fluent-bit-windows -n amazon-cloudwatch --timeout 1200s | ||
./kubectl rollout status daemonset cloudwatch-agent-windows -n amazon-cloudwatch --timeout 1200s | ||
EOT | ||
} | ||
} | ||
|
||
resource "null_resource" "validator" { | ||
depends_on = [ | ||
helm_release.this, | ||
null_resource.deployment_wait | ||
] | ||
provisioner "local-exec" { | ||
command = "go test ${var.test_dir} -v --tags=windowslinux" | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
integration-tests/amazon-cloudwatch-observability/terraform/helm-windows/providers.tf
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,18 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
provider "aws" { | ||
region = var.region | ||
} | ||
|
||
provider "helm" { | ||
kubernetes { | ||
config_path = "${var.kube_dir}/config" | ||
} | ||
} | ||
|
||
provider "kubernetes" { | ||
host = aws_eks_cluster.this.endpoint | ||
cluster_ca_certificate = base64decode(data.aws_eks_cluster.eks_windows_cluster_ca.certificate_authority[0].data) | ||
token = data.aws_eks_cluster_auth.this.token | ||
} |
Oops, something went wrong.