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

fix: output error when management or workload rg are not present. #937

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 7 additions & 6 deletions examples/override-example/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
##############################################################################

module "landing_zone" {
source = "../../patterns/vsi/module"
prefix = var.prefix
region = var.region
ssh_public_key = var.ssh_key
override = true
tags = var.resource_tags
source = "../../patterns/vsi/module"
prefix = var.prefix
region = var.region
ssh_public_key = var.ssh_key
override = true
tags = var.resource_tags
override_json_string = var.override_json_string
}
6 changes: 6 additions & 0 deletions examples/override-example/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ variable "resource_tags" {
description = "Optional list of tags to be added to created resources"
default = []
}

variable "override_json_string" {
description = "Override default values with a JSON object. Any JSON other than an empty string overrides other configuration changes. You can use the [landing zone configuration tool](https://terraform-ibm-modules.github.io/landing-zone-config-tool/#/home) to create the JSON."
type = string
default = ""
}
18 changes: 9 additions & 9 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -287,34 +287,34 @@ output "resource_group_data" {

output "management_rg_id" {
description = "Resource group ID for the management resource group used within landing zone."
value = [
value = try([
for group in var.resource_groups :
local.resource_groups_info[group.use_prefix == true ? "${var.prefix}-${group.name}" : group.name] if endswith(group.name, "management-rg")
][0]
][0], null)
}

output "management_rg_name" {
description = "Resource group name for the management resource group used within landing zone."
value = [
value = try([
for group in var.resource_groups :
group.use_prefix == true ? "${var.prefix}-${group.name}" : group.name if endswith(group.name, "management-rg")
][0]
][0], null)
}

output "workload_rg_id" {
description = "Resource group ID for the workload resource group used within landing zone."
value = [
value = try([
for group in var.resource_groups :
local.resource_groups_info[group.use_prefix == true ? "${var.prefix}-${group.name}" : group.name] if endswith(group.name, "workload-rg")
][0]
][0], null)
}

output "workload_rg_name" {
description = "Resource group name for the workload resource group used within landing zone."
value = [
value = try([
for group in var.resource_groups :
group.use_prefix == true ? "${var.prefix}-${group.name}" : group.name if endswith(group.name, "management-rg")
][0]
group.use_prefix == true ? "${var.prefix}-${group.name}" : group.name if endswith(group.name, "workload-rg")
][0], null)
}

##############################################################################
Expand Down
4 changes: 2 additions & 2 deletions patterns/vsi/module/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "resource_group_data" {

output "management_rg_id" {
description = "Resource group ID for the management resource group used within landing zone."
value = module.landing_zone.resource_group_data[module.landing_zone.management_rg_name]
value = try(module.landing_zone.resource_group_data[module.landing_zone.management_rg_name], null)
}

output "management_rg_name" {
Expand All @@ -29,7 +29,7 @@ output "management_rg_name" {

output "workload_rg_id" {
description = "Resource group ID for the workload resource group used within landing zone."
value = module.landing_zone.resource_group_data[module.landing_zone.workload_rg_name]
value = try(module.landing_zone.resource_group_data[module.landing_zone.workload_rg_name], null)
}

output "workload_rg_name" {
Expand Down
4 changes: 2 additions & 2 deletions patterns/vsi/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ output "resource_group_data" {

output "management_rg_id" {
description = "Resource group ID for the management resource group used within landing zone."
value = module.vsi_landing_zone.resource_group_data[module.vsi_landing_zone.management_rg_name]
value = try(module.vsi_landing_zone.resource_group_data[module.vsi_landing_zone.management_rg_name], null)
}

output "management_rg_name" {
Expand All @@ -29,7 +29,7 @@ output "management_rg_name" {

output "workload_rg_id" {
description = "Resource group ID for the workload resource group used within landing zone."
value = module.vsi_landing_zone.resource_group_data[module.vsi_landing_zone.workload_rg_name]
value = try(module.vsi_landing_zone.resource_group_data[module.vsi_landing_zone.workload_rg_name], null)
}

output "workload_rg_name" {
Expand Down
15 changes: 0 additions & 15 deletions tests/other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/stretchr/testify/assert"
)

const overrideExampleTerraformDir = "examples/override-example"

// NOTE: The HPCS tests may fail if our account already has an existing hpcs auth policy - hence only running once a week so PR pipeline is not impacted
func TestRunRoksPatternWithHPCS(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -50,16 +48,3 @@ func TestRunVSIPatternWithHPCS(t *testing.T) {
assert.Nil(t, err, "This should not have errored")
assert.NotNil(t, output, "Expected some output")
}

func TestRunOverrideExample(t *testing.T) {
t.Parallel()
if enableSchematicsTests {
t.Skip("Skipping terratest for override-example, running Schematics test instead")
}

options := setupOptionsQuickStartPattern(t, "slz-ex", overrideExampleTerraformDir)

output, err := options.RunTestConsistency()
assert.Nil(t, err, "This should not have errored")
assert.NotNil(t, output, "Expected some output")
}
27 changes: 27 additions & 0 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const roksQuickstartPatternTerraformDir = "patterns/roks-quickstart"
const roksPatternTerraformDir = "patterns/roks"
const vsiPatternTerraformDir = "patterns/vsi"
const vpcPatternTerraformDir = "patterns/vpc"
const overrideExampleTerraformDir = "examples/override-example"
const resourceGroup = "geretain-test-resources"
const yamlLocation = "../common-dev-assets/common-go-assets/common-permanent-resources.yaml"

Expand Down Expand Up @@ -691,3 +692,29 @@ func TestRunUpgradeVsiExtention(t *testing.T) {
logger.Log(t, "END: Destroy (existing resources)")
}
}

func TestRunOverrideExample(t *testing.T) {
t.Parallel()

sshPublicKey := sshPublicKey(t)

overrideJsonString, err := os.ReadFile("resources/override-example.json")
if err != nil {
panic(err)
}

options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
Testing: t,
TerraformDir: overrideExampleTerraformDir,
Prefix: "slz-ex",
TerraformVars: map[string]interface{}{
"ssh_key": sshPublicKey,
"override_json_string": string(overrideJsonString),
},
CloudInfoService: sharedInfoSvc,
})

output, err := options.RunTestConsistency()
assert.Nil(t, err, "This should not have errored")
assert.NotNil(t, output, "Expected some output")
}
Loading