Skip to content

Commit 89a6b4f

Browse files
authored
Added tests (#19)
1 parent ba00f3d commit 89a6b4f

File tree

16 files changed

+1061
-6
lines changed

16 files changed

+1061
-6
lines changed

src/provider-helm.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,8 @@ locals {
133133
"--profile", var.kube_exec_auth_aws_profile
134134
] : []
135135

136-
kube_exec_auth_role_arn = coalesce(var.kube_exec_auth_role_arn, module.iam_roles.terraform_role_arn)
137136
exec_role = local.kube_exec_auth_enabled && var.kube_exec_auth_role_arn_enabled ? [
138-
"--role-arn", local.kube_exec_auth_role_arn
137+
"--role-arn", coalesce(var.kube_exec_auth_role_arn, module.iam_roles.terraform_role_arn)
139138
] : []
140139

141140
# Provide dummy configuration for the case where the EKS cluster is not available.

src/remote-state.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module "eks" {
22
source = "cloudposse/stack-config/yaml//modules/remote-state"
3-
version = "1.5.0"
3+
version = "1.8.0"
44

55
component = var.eks_component_name
66

test/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
state/
2+
.cache
3+
test/test-suite.json
4+
.atmos
5+
test_suite.yaml

test/component_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package test
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
"strings"
7+
helper "github.com/cloudposse/test-helpers/pkg/atmos/component-helper"
8+
"github.com/cloudposse/test-helpers/pkg/atmos"
9+
"github.com/cloudposse/test-helpers/pkg/helm"
10+
"github.com/stretchr/testify/assert"
11+
"github.com/gruntwork-io/terratest/modules/random"
12+
)
13+
14+
type ComponentSuite struct {
15+
helper.TestSuite
16+
}
17+
18+
func (s *ComponentSuite) TestBasic() {
19+
const component = "eks/reloader/basic"
20+
const stack = "default-test"
21+
const awsRegion = "us-east-2"
22+
23+
randomID := strings.ToLower(random.UniqueId())
24+
25+
namespace := fmt.Sprintf("reloader-%s", randomID)
26+
27+
inputs := map[string]interface{}{
28+
"kubernetes_namespace": namespace,
29+
}
30+
31+
defer s.DestroyAtmosComponent(s.T(), component, stack, &inputs)
32+
options, _ := s.DeployAtmosComponent(s.T(), component, stack, &inputs)
33+
assert.NotNil(s.T(), options)
34+
35+
metadataArray := []helm.Metadata{}
36+
37+
atmos.OutputStruct(s.T(), options, "metadata", &metadataArray)
38+
39+
assert.Equal(s.T(), len(metadataArray), 1)
40+
metadata := metadataArray[0]
41+
42+
assert.Equal(s.T(), metadata.AppVersion, "v0.0.124")
43+
assert.Equal(s.T(), metadata.Chart, "reloader")
44+
assert.NotNil(s.T(), metadata.FirstDeployed)
45+
assert.NotNil(s.T(), metadata.LastDeployed)
46+
assert.Equal(s.T(), metadata.Name, "reloader")
47+
assert.Equal(s.T(), metadata.Namespace, namespace)
48+
assert.NotNil(s.T(), metadata.Values)
49+
assert.Equal(s.T(), metadata.Version, "v0.0.124")
50+
51+
s.DriftTest(component, stack, &inputs)
52+
}
53+
54+
func (s *ComponentSuite) TestEnabledFlag() {
55+
const component = "eks/reloader/disabled"
56+
const stack = "default-test"
57+
s.VerifyEnabledFlag(component, stack, nil)
58+
}
59+
60+
func (s *ComponentSuite) SetupSuite() {
61+
s.TestSuite.InitConfig()
62+
s.TestSuite.Config.ComponentDestDir = "components/terraform/eks/reloader"
63+
s.TestSuite.SetupSuite()
64+
}
65+
66+
func TestRunSuite(t *testing.T) {
67+
suite := new(ComponentSuite)
68+
suite.AddDependency(t, "vpc", "default-test", nil)
69+
suite.AddDependency(t, "eks/cluster", "default-test", nil)
70+
helper.Run(t, suite)
71+
}

test/fixtures/atmos.yaml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# CLI config is loaded from the following locations (from lowest to highest priority):
2+
# system dir (`/usr/local/etc/atmos` on Linux, `%LOCALAPPDATA%/atmos` on Windows)
3+
# home dir (~/.atmos)
4+
# current directory
5+
# ENV vars
6+
# Command-line arguments
7+
#
8+
# It supports POSIX-style Globs for file names/paths (double-star `**` is supported)
9+
# https://en.wikipedia.org/wiki/Glob_(programming)
10+
11+
# Base path for components, stacks and workflows configurations.
12+
# Can also be set using `ATMOS_BASE_PATH` ENV var, or `--base-path` command-line argument.
13+
# Supports both absolute and relative paths.
14+
# If not provided or is an empty string, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path`
15+
# are independent settings (supporting both absolute and relative paths).
16+
# If `base_path` is provided, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path`
17+
# are considered paths relative to `base_path`.
18+
base_path: ""
19+
20+
components:
21+
terraform:
22+
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_BASE_PATH` ENV var, or `--terraform-dir` command-line argument
23+
# Supports both absolute and relative paths
24+
base_path: "components/terraform"
25+
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE` ENV var
26+
apply_auto_approve: true
27+
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_DEPLOY_RUN_INIT` ENV var, or `--deploy-run-init` command-line argument
28+
deploy_run_init: true
29+
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE` ENV var, or `--init-run-reconfigure` command-line argument
30+
init_run_reconfigure: true
31+
# Can also be set using `ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE` ENV var, or `--auto-generate-backend-file` command-line argument
32+
auto_generate_backend_file: true
33+
34+
stacks:
35+
# Can also be set using `ATMOS_STACKS_BASE_PATH` ENV var, or `--config-dir` and `--stacks-dir` command-line arguments
36+
# Supports both absolute and relative paths
37+
base_path: "stacks"
38+
# Can also be set using `ATMOS_STACKS_INCLUDED_PATHS` ENV var (comma-separated values string)
39+
# Since we are distinguishing stacks based on namespace, and namespace is not part
40+
# of the stack name, we have to set `included_paths` via the ENV var in the Dockerfile
41+
included_paths:
42+
- "orgs/**/*"
43+
44+
# Can also be set using `ATMOS_STACKS_EXCLUDED_PATHS` ENV var (comma-separated values string)
45+
excluded_paths:
46+
- "**/_defaults.yaml"
47+
48+
# Can also be set using `ATMOS_STACKS_NAME_PATTERN` ENV var
49+
name_pattern: "{tenant}-{stage}"
50+
51+
workflows:
52+
# Can also be set using `ATMOS_WORKFLOWS_BASE_PATH` ENV var, or `--workflows-dir` command-line arguments
53+
# Supports both absolute and relative paths
54+
base_path: "stacks/workflows"
55+
56+
# https://github.com/cloudposse/atmos/releases/tag/v1.33.0
57+
logs:
58+
file: "/dev/stdout"
59+
# Supported log levels: Trace, Debug, Info, Warning, Off
60+
level: Info
61+
62+
settings:
63+
# Can also be set using 'ATMOS_SETTINGS_LIST_MERGE_STRATEGY' environment variable, or '--settings-list-merge-strategy' command-line argument
64+
list_merge_strategy: replace
65+
66+
# `Go` templates in Atmos manifests
67+
# https://atmos.tools/core-concepts/stacks/templating
68+
# https://pkg.go.dev/text/template
69+
templates:
70+
settings:
71+
enabled: true
72+
# https://masterminds.github.io/sprig
73+
sprig:
74+
enabled: true
75+
# https://docs.gomplate.ca
76+
gomplate:
77+
enabled: true
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
components:
2+
terraform:
3+
account-map:
4+
metadata:
5+
terraform_workspace: core-gbl-root
6+
vars:
7+
tenant: core
8+
environment: gbl
9+
stage: root
10+
11+
# This remote state is only for Cloud Posse internal use.
12+
# It references the Cloud Posse test organizations actual infrastructure.
13+
# remote_state_backend:
14+
# s3:
15+
# bucket: cptest-core-ue2-root-tfstate-core
16+
# dynamodb_table: cptest-core-ue2-root-tfstate-core-lock
17+
# role_arn: arn:aws:iam::822777368227:role/cptest-core-gbl-root-tfstate-core-ro
18+
# encrypt: true
19+
# key: terraform.tfstate
20+
# acl: bucket-owner-full-control
21+
# region: us-east-2
22+
23+
remote_state_backend_type: static
24+
remote_state_backend:
25+
# This static backend is used for tests that only need to use the account map iam-roles module
26+
# to find the role to assume for Terraform operations. It is configured to use whatever
27+
# the current user's role is, but the environment variable `TEST_ACCOUNT_ID` must be set to
28+
# the account ID of the account that the user is currently assuming a role in.
29+
#
30+
# For some components, this backend is missing important data, and those components
31+
# will need that data added to the backend configuration in order to work properly.
32+
static:
33+
account_info_map: {}
34+
all_accounts: []
35+
aws_partition: aws
36+
full_account_map: {}
37+
iam_role_arn_templates: {}
38+
non_eks_accounts: []
39+
profiles_enabled: false
40+
root_account_aws_name: root
41+
terraform_access_map: {}
42+
terraform_dynamic_role_enabled: false
43+
terraform_role_name_map:
44+
apply: terraform
45+
plan: planner
46+
terraform_roles: {}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
components:
2+
terraform:
3+
eks/cluster:
4+
metadata:
5+
component: eks/cluster
6+
vars:
7+
enabled: true
8+
9+
# Cluster node configuration
10+
aws_ssm_agent_enabled: true
11+
managed_node_groups_enabled: true
12+
node_groups: # will create node group for each item in map
13+
main: # Karpenter is responsible for scaling nodes, but this default node group is required for deploying EKS Addons
14+
# EKS AMI version to use, e.g. "1.16.13-20200821" (no "v").
15+
ami_release_version: null
16+
# Type of Amazon Machine Image (AMI) associated with the EKS Node Group
17+
ami_type: AL2_x86_64
18+
# Additional name attributes (e.g. `1`) for the node group
19+
attributes: []
20+
# will create 1 auto scaling group in each specified availability zone
21+
# or all AZs with subnets if none are specified anywhere
22+
availability_zones: null
23+
# Whether to enable Node Group to scale its AutoScaling Group
24+
cluster_autoscaler_enabled: false
25+
# True (recommended) to create new node_groups before deleting old ones, avoiding a temporary outage
26+
create_before_destroy: true
27+
# Desired number of worker nodes when initially provisioned
28+
desired_group_size: 2
29+
# Enable disk encryption for the created launch template (if we aren't provided with an existing launch template)
30+
disk_encryption_enabled: true
31+
# Disk size in GiB for worker nodes. Terraform will only perform drift detection if a configuration value is provided.
32+
disk_size: 20
33+
# Set of instance types associated with the EKS Node Group. Terraform will only perform drift detection if a configuration value is provided.
34+
instance_types:
35+
- t3.small
36+
kubernetes_labels: {}
37+
kubernetes_taints: []
38+
node_role_policy_arns: null
39+
kubernetes_version: null
40+
max_group_size: 3
41+
min_group_size: 2
42+
resources_to_tag:
43+
- instance
44+
- volume
45+
tags: null
46+
47+
access_config:
48+
authentication_mode: "API"
49+
bootstrap_cluster_creator_admin_permissions: true
50+
51+
# Fargate profiles, required for Karpenter
52+
# fargate_profiles:
53+
# karpenter:
54+
# kubernetes_namespace: karpenter
55+
# kubernetes_labels: null
56+
# fargate_profile_iam_role_kubernetes_namespace_delimiter: "@"
57+
# karpenter_iam_role_enabled: true
58+
59+
# Legacy settings
60+
# The upstream component sets these to true by default to avoid breaking existing deployments,
61+
# but new deployments should have these settings all disabled.
62+
legacy_fargate_1_role_per_profile_enabled: false
63+
64+
addons_depends_on: true
65+
deploy_addons_to_fargate: false
66+
67+
allow_ingress_from_vpc_accounts: []
68+
public_access_cidrs: ["0.0.0.0/0"]
69+
allowed_cidr_blocks: []
70+
allowed_security_groups: []
71+
72+
enabled_cluster_log_types: []
73+
apply_config_map_aws_auth: true
74+
availability_zone_abbreviation_type: fixed
75+
cluster_private_subnets_only: true
76+
cluster_encryption_config_enabled: true
77+
cluster_endpoint_private_access: true
78+
cluster_endpoint_public_access: true
79+
cluster_log_retention_period: 90
80+
oidc_provider_enabled: true
81+
cluster_kubernetes_version: "1.31"
82+
addons:
83+
vpc-cni:
84+
addon_version: "v1.18.3-eksbuild.3"
85+
kube-proxy:
86+
addon_version: "v1.30.3-eksbuild.5"
87+
coredns:
88+
addon_version: "v1.11.3-eksbuild.1"
89+
configuration_values: '{"autoScaling":{"enabled":true,"minReplicas":3}}'
90+
aws-ebs-csi-driver:
91+
addon_version: "v1.34.0-eksbuild.1"
92+
configuration_values: '{"sidecars":{"snapshotter":{"forceEnable":false}}}'
93+
aws-efs-csi-driver:
94+
addon_version: "v2.0.8-eksbuild.1"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
components:
2+
terraform:
3+
eks/reloader/basic:
4+
metadata:
5+
component: eks/reloader
6+
vars:
7+
enabled: true
8+
kube_exec_auth_role_arn_enabled: false
9+
name: "reloader"
10+
kubernetes_namespace: "reloader"
11+
create_namespace: true
12+
repository: "https://stakater.github.io/stakater-charts"
13+
chart: "reloader"
14+
chart_version: "v0.0.124"
15+
timeout: 180
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
components:
2+
terraform:
3+
eks/reloader/disabled:
4+
metadata:
5+
component: eks/reloader
6+
vars:
7+
enabled: false
8+
kube_exec_auth_role_arn_enabled: false
9+
name: "reloader"
10+
kubernetes_namespace: "reloader"
11+
create_namespace: true
12+
repository: "https://stakater.github.io/stakater-charts"
13+
chart: "reloader"
14+
chart_version: "v0.0.124"
15+
timeout: 180
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
components:
2+
terraform:
3+
vpc:
4+
metadata:
5+
component: vpc
6+
vars:
7+
name: "vpc"
8+
availability_zones:
9+
- "b"
10+
- "c"
11+
public_subnets_enabled: true
12+
max_nats: 1
13+
# Private subnets do not need internet access
14+
nat_gateway_enabled: true
15+
nat_instance_enabled: false
16+
subnet_type_tag_key: "eg.cptest.co/subnet/type"
17+
max_subnet_count: 3
18+
vpc_flow_logs_enabled: false
19+
ipv4_primary_cidr_block: "172.16.0.0/16"

0 commit comments

Comments
 (0)