Skip to content

Commit 6010dcf

Browse files
committed
tests/int: Update terraform config to use tags
Update the terraform configurations for all the cloud providers to use tags. The tags are provided with input variables "tags" which is common across the cloud providers. Signed-off-by: Sunny <[email protected]>
1 parent 94cc0f7 commit 6010dcf

File tree

7 files changed

+53
-1
lines changed

7 files changed

+53
-1
lines changed

tests/integration/.env.sample

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,40 @@
22
# export AWS_ACCESS_KEY_ID=
33
# export AWS_SECRET_ACCESS_KEY=
44
# export AWS_REGION=us-east-2
5+
## This random value is needed for AWS only to prevent
6+
## https://github.com/hashicorp/terraform-provider-aws/issues/19583 which
7+
## happens when using dynamic "name" value in presence of more than one tag.
8+
# export TF_VAR_rand=${RANDOM}
59

610
## Azure
711
# export TF_VAR_azure_location=eastus
12+
## Set the following only when authenticating using Service Principal (suited
13+
## for CI environment).
14+
# export ARM_CLIENT_ID=
15+
# export ARM_CLIENT_SECRET=
16+
# export ARM_SUBSCRIPTION_ID=
17+
# export ARM_TENANT_ID=
818

919
## GCP
1020
# export TF_VAR_gcp_project_id=
1121
# export TF_VAR_gcp_region=us-central1
1222
# export TF_VAR_gcp_zone=us-central1-c
1323
## Leave GCR region empty to use gcr.io. Else set it to `us`, `eu` or `asia`.
1424
# export TF_VAR_gcr_region=
25+
## Set the following only when using service account.
26+
## Provide absolute path to the service account JSON key file.
27+
# export GOOGLE_APPLICATION_CREDENTIALS=
28+
29+
## Common variables
30+
# export TF_VAR_tags='{"environment"="dev"}'
31+
#
32+
## WARNING: For AWS, also set the "createdat" tag to overwrite the default
33+
## timestamp and use a static value. Dynamic tag value causes the issue
34+
## https://github.com/hashicorp/terraform-provider-aws/issues/19583.
35+
## The date format is based on the format defined in
36+
## fluxcd/test-infra/tf-modules/utils/tags tf-module that's compatible with the
37+
## tags/labels value in all the cloud providers.
38+
## Also, since "createdat" is a dynamic value, its value changes on subsequent
39+
## apply. Overriding it with a static value helps avoid modifying the resource
40+
## tags during development when the configurations are applied frequently.
41+
# export TF_VAR_tags='{"environment"="dev", "createdat"='"\"$(date -u +x%Y-%m-%d_%Hh%Mm%Ss)\""'}'

tests/integration/terraform/aws/main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@ provider "aws" {}
33
resource "random_pet" "suffix" {}
44

55
locals {
6-
name = "flux-test-${random_pet.suffix.id}"
6+
name = "flux-test-${var.rand}"
77
}
88

99
module "eks" {
1010
source = "git::https://github.com/fluxcd/test-infra.git//tf-modules/aws/eks"
1111

1212
name = local.name
13+
tags = var.tags
1314
}
1415

1516
module "test_ecr" {
1617
source = "git::https://github.com/fluxcd/test-infra.git//tf-modules/aws/ecr"
1718

1819
name = "test-repo-${local.name}"
20+
tags = var.tags
1921
}
2022

2123
module "image_reflector_ecr" {
2224
source = "git::https://github.com/fluxcd/test-infra.git//tf-modules/aws/ecr"
2325

2426
name = "test-image-reflector-${local.name}"
27+
tags = var.tags
2528
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
variable "rand" {
2+
type = string
3+
}
4+
5+
variable "tags" {
6+
type = map(string)
7+
default = {}
8+
}

tests/integration/terraform/azure/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module "aks" {
1717

1818
name = local.name
1919
location = var.azure_location
20+
tags = var.tags
2021
}
2122

2223
module "acr" {
@@ -26,6 +27,7 @@ module "acr" {
2627
location = var.azure_location
2728
aks_principal_id = module.aks.principal_id
2829
resource_group = module.aks.resource_group
30+
tags = var.tags
2931

3032
depends_on = [module.aks]
3133
}

tests/integration/terraform/azure/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ variable "azure_location" {
22
type = string
33
default = "eastus"
44
}
5+
6+
variable "tags" {
7+
type = map(string)
8+
default = {}
9+
}

tests/integration/terraform/gcp/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ module "gke" {
1414
source = "git::https://github.com/fluxcd/test-infra.git//tf-modules/gcp/gke"
1515

1616
name = local.name
17+
tags = var.tags
1718
}
1819

1920
module "gcr" {
2021
source = "git::https://github.com/fluxcd/test-infra.git//tf-modules/gcp/gcr"
2122

2223
name = local.name
24+
tags = var.tags
2325
}

tests/integration/terraform/gcp/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ variable "gcr_region" {
1616
type = string
1717
default = "" // Empty default to use gcr.io.
1818
}
19+
20+
variable "tags" {
21+
type = map(string)
22+
default = {}
23+
}

0 commit comments

Comments
 (0)