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

feat: add an optional audit resource group #77

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions solutions/instances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This deployable architecture creates observability instances in IBM Cloud and supports provisioning the following resources:

* A resource group, if one is not passed in.
* Optionally create a resource group for provisioning audit resources, or use an existing audit resource group if one is not passed in
* An IBM Cloud Log Analysis instance.
* An IBM Cloud Monitoring instance.
* An IBM Cloud Object Storage instance, if one does not exist.
Expand Down
8 changes: 8 additions & 0 deletions solutions/instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ module "resource_group" {
existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null
}

module "audit_resource_group" {
count = var.enable_audit_resource_group ? 1 : 0
source = "terraform-ibm-modules/resource-group/ibm"
version = "1.1.5"
resource_group_name = var.use_existing_audit_resource_group == false ? (var.prefix != null ? "${var.prefix}-${var.audit_resource_group_name}" : var.audit_resource_group_name) : null
existing_resource_group_name = var.use_existing_audit_resource_group == true ? var.audit_resource_group_name : null
}

#######################################################################################################################
# Observability Instance
#######################################################################################################################
Expand Down
18 changes: 18 additions & 0 deletions solutions/instances/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,35 @@ variable "ibmcloud_api_key" {
sensitive = true
}

variable "enable_audit_resource_group" {
type = bool
description = "Whether to use a separate resource group for audit resources."
default = false
}

variable "use_existing_resource_group" {
type = bool
description = "Whether to use an existing resource group."
default = false
}

variable "use_existing_audit_resource_group" {
type = bool
description = "Whether to use an existing resource group."
default = false
}

variable "resource_group_name" {
type = string
description = "The name of a new or existing resource group to provision resources to. If a prefix input variable is passed, it is prefixed to the value in the `<prefix>-value` format."
}

variable "audit_resource_group_name" {
type = string
description = "(Optional) The name of a new or an existing resource group in which to provision audit resources to. If prefix input variable is passed then it will get prefixed infront of the value in the format of '<prefix>-value'. If no value is provided, the value for `observability_resource_group_name` is used."
default = null
}

variable "region" {
description = "The region where observability resources are created."
type = string
Expand Down
2 changes: 2 additions & 0 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestInstancesInSchematics(t *testing.T) {
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
{Name: "resource_group_name", Value: options.Prefix, DataType: "string"},
{Name: "audit_resource_group_name", Value: fmt.Sprintf("%s-%s", options.Prefix, "audit"), DataType: "string"},
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
{Name: "cos_region", Value: region, DataType: "string"},
{Name: "cos_instance_tags", Value: options.Tags, DataType: "list(string)"},
Expand Down Expand Up @@ -109,6 +110,7 @@ func TestRunUpgradeSolutionInstances(t *testing.T) {

options.TerraformVars = map[string]interface{}{
"resource_group_name": options.Prefix,
"audit_resource_group_name": fmt.Sprintf("%s-%s", options.Prefix, "audit"),
"cos_instance_access_tags": permanentResources["accessTags"],
"existing_kms_instance_crn": permanentResources["hpcs_south_crn"],
"kms_endpoint_type": "public",
Expand Down