Skip to content

Commit

Permalink
refactor: simplify tf for one distro
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-newrelic committed Feb 14, 2025
1 parent 0017bd9 commit 2d5f63c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
22 changes: 8 additions & 14 deletions test/terraform/nightly/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
locals {
test_specs = {
for distro in var.distros :
distro => yamldecode(file("${path.module}/../../../distributions/${distro}/test-spec.yaml"))
}
test_spec = yamldecode(file("${path.module}/../../../distributions/${var.distro}/test-spec.yaml"))
releases_bucket_name = "nr-releases"
required_permissions_boundary_arn_for_new_roles = "arn:aws:iam::${var.aws_account_id}:policy/resource-provisioner-boundary"
}
Expand All @@ -14,22 +11,19 @@ resource "random_string" "deploy_id" {


data "aws_ecr_repository" "ecr_repo" {
for_each = var.distros
name = each.value
name = var.distro
}

resource "helm_release" "ci_e2e_nightly" {
for_each = var.distros

name = "ci-e2etest-nightly"
name = "ci-e2etest-nightly-${var.distro}"
chart = "../../charts/nr_backend"

create_namespace = true
namespace = "nightly-${each.key}"
namespace = "nightly-${var.distro}"

set {
name = "image.repository"
value = data.aws_ecr_repository.ecr_repo[each.key].repository_url
value = data.aws_ecr_repository.ecr_repo[var.distro].repository_url
}

set {
Expand All @@ -54,15 +48,15 @@ resource "helm_release" "ci_e2e_nightly" {

set {
name = "collector.hostname"
value = "${var.test_environment}-${random_string.deploy_id.result}-${each.key}-k8s_node"
value = "${var.test_environment}-${random_string.deploy_id.result}-${var.distro}-k8s_node"
}
}

module "ci_e2e_ec2" {
for_each = toset([for distro in var.distros : distro if local.test_specs[distro].nightly.ec2.enabled])
count = local.test_spec.nightly.ec2.enabled ? 1 : 0
source = "../modules/ec2"
releases_bucket_name = local.releases_bucket_name
collector_distro = each.key
collector_distro = var.distro
nr_ingest_key = var.nr_ingest_key
# reuse vpc to avoid having to pay for second NAT gateway for this simple use case
vpc_id = data.aws_eks_cluster.eks_cluster.vpc_config[0].vpc_id
Expand Down
2 changes: 1 addition & 1 deletion test/terraform/nightly/providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ data "aws_eks_cluster" "eks_cluster" {
}

data "aws_eks_cluster_auth" "eks_cluster_auth" {
name = "aws-ci-e2etest"
name = "aws-ci-e2etest"
}

provider "helm" {
Expand Down
8 changes: 4 additions & 4 deletions test/terraform/nightly/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ variable "aws_region" {
}

variable "distro" {
description = "Distro to test during nightly"
type = string
description = "Distro to test during nightly"
type = string
}

variable "nightly_docker_manifest_sha" {
description = "SHA of the nightly docker manifest"
type = string
description = "SHA of the nightly docker manifest"
type = string
}

variable "nr_backend_url" {
Expand Down

0 comments on commit 2d5f63c

Please sign in to comment.