Skip to content

Commit

Permalink
fix: allow prefix as empty string, set default value as devand upda…
Browse files Browse the repository at this point in the history
…tes resource group logic to handle `existing_resource_group` (#48)

* refactor: Updated DA prefix and resource group logic, added related variables

* fix: Update cra-config.yaml

* fix: Update variable.tf

* fix: Update pr_test.go

* fix:: Update prefix logic and resolved comments

---------

Co-authored-by: Arya Girish K <[email protected]>
  • Loading branch information
arya-girish-k and Arya Girish K authored Feb 3, 2025
1 parent 41698e8 commit a78308b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_config_repo"></a> [config\_repo](#input\_config\_repo) | The URL for the repository storing the configuration to use for the application to run through Enterprise Application Service on IBM Cloud. | `string` | `null` | no |
| <a name="input_ease_name"></a> [ease\_name](#input\_ease\_name) | The name for the newly provisioned Enterprise Application Service instance. | `string` | n/a | yes |
| <a name="input_ease_name"></a> [ease\_name](#input\_ease\_name) | The name for the newly provisioned Enterprise Application Service instance. | `string` | `"instance"` | no |
| <a name="input_maven_repository_password"></a> [maven\_repository\_password](#input\_maven\_repository\_password) | Maven repository authentication password if needed. Default to null. | `string` | `null` | no |
| <a name="input_maven_repository_username"></a> [maven\_repository\_username](#input\_maven\_repository\_username) | Maven repository authentication username if needed. Default to null. | `string` | `null` | no |
| <a name="input_plan"></a> [plan](#input\_plan) | The desired pricing plan for Enterprise Application Service instance. | `string` | `"standard"` | no |
Expand Down
1 change: 1 addition & 0 deletions cra-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ CRA_TARGETS:
TF_VAR_source_repo: "https://github.com/tim-openliberty-appflow-test/sample-getting-started"
TF_VAR_repos_git_token_secret_crn: "crn:v1:bluemix:public:secrets-manager:us-south:a/abac0df06b644a9cabc6e44f55b3880e:79c6d411-c18f-4670-b009-b0044a238667:secret:825a3797-1bc8-f47a-611a-c9bd2b0ef846" # pragma: allowlist secret
TF_VAR_subscription_id_secret_crn: "crn:v1:bluemix:public:secrets-manager:us-south:a/abac0df06b644a9cabc6e44f55b3880e:79c6d411-c18f-4670-b009-b0044a238667:secret:71363d27-db8d-dd07-c72b-59ecb3884a8f" # pragma: allowlist secret
TF_VAR_resource_group_name: "Default"
12 changes: 9 additions & 3 deletions ibm_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@
"required": true
},
{
"key": "resource_group"
"key": "use_existing_resource_group"
},
{
"key": "resource_group_name"
},
{
"key": "ease_name"
},
{
"key": "region",
Expand All @@ -102,8 +108,8 @@
},
{
"key": "prefix",
"default_value": "",
"required": true
"required": true,
"description": "Prefix to add to all resources created by this solution. To not use any prefix value, you can enter the string `__NULL__`."
},
{
"key": "plan",
Expand Down
7 changes: 4 additions & 3 deletions solutions/standard/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
locals {
sleep_create = "30s"
prefix = var.prefix != null ? (var.prefix != "" ? var.prefix : null) : null
}

########################################################################################################################
Expand All @@ -10,8 +11,8 @@ module "resource_group" {
source = "terraform-ibm-modules/resource-group/ibm"
version = "1.1.6"
# if an existing resource group is not set (null) create a new one using prefix
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
existing_resource_group_name = var.resource_group
resource_group_name = var.use_existing_resource_group == false ? try("${local.prefix}-${var.resource_group_name}", var.resource_group_name) : null
existing_resource_group_name = var.use_existing_resource_group == true ? var.resource_group_name : null
}

########################################################################################################################
Expand Down Expand Up @@ -82,7 +83,7 @@ locals {

module "ease" {
source = "../../"
ease_name = "${var.prefix}-app"
ease_name = try("${var.prefix}-${var.ease_name}", var.ease_name)
resource_group_id = module.resource_group.resource_group_id
tags = var.resource_tags
plan = var.plan
Expand Down
21 changes: 16 additions & 5 deletions solutions/standard/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@ variable "resource_tags" {

variable "prefix" {
type = string
description = "Prefix to append to all resources created by this deployable architecture"
default = "ease-da"
description = "Prefix to add to all resources created by this deployable architecture . To not use any prefix value, you can set this value to `null` or an empty string."
default = "dev"
}

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

variable "resource_group_name" {
type = string
description = "The name of an existing resource group to provision resources in to. If not set a new resource group will be created using the prefix variable value"
default = null
description = "The name of a new or an existing resource group to provision resources in to. If not set a new resource group will be created using the prefix variable value"
}

variable "ease_name" {
type = string
description = "The name for the newly provisioned Enterprise Application Service instance."
default = "instance"
}

variable "plan" {
Expand Down
7 changes: 6 additions & 1 deletion tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ func TestRunDrCompleteExample(t *testing.T) {
func TestRunUpgradeExample(t *testing.T) {
t.Parallel()

options := setupOptions(t, "ease-upgrade", basicExampleDir, nil)
extTerraformVars := map[string]interface{}{
"subscription_id_secret_crn": subscriptionIdSecretCRN,
"plan": testPlan,
}

options := setupOptions(t, "ease-upgrade", basicExampleDir, extTerraformVars)

output, err := options.RunTestUpgrade()
if !options.UpgradeTestSkipped {
Expand Down
1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ variable "resource_group_id" {
variable "ease_name" {
type = string
description = "The name for the newly provisioned Enterprise Application Service instance."
default = "instance"
}

variable "tags" {
Expand Down

0 comments on commit a78308b

Please sign in to comment.