Skip to content

Commit f61815f

Browse files
feat: created a new projects variation for the Code Engine DA (#92)
1 parent ed0be06 commit f61815f

11 files changed

+339
-0
lines changed

.catalog-onboard-pipeline.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ offerings:
1212
scc:
1313
instance_id: 1c7d5f78-9262-44c3-b779-b28fe4d88c37
1414
region: us-south
15+
- name: projects
16+
mark_ready: true
17+
install_type: fullstack
18+
scc:
19+
instance_id: 1c7d5f78-9262-44c3-b779-b28fe4d88c37
20+
region: us-south

ibm_catalog.json

+39
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,45 @@
119119
}
120120
]
121121
}
122+
},
123+
{
124+
"label": "New Code Engine projects",
125+
"name": "projects",
126+
"install_type": "fullstack",
127+
"working_directory": "solutions/projects",
128+
"iam_permissions": [
129+
{
130+
"role_crns": [
131+
"crn:v1:bluemix:public:iam::::serviceRole:Writer"
132+
],
133+
"service_name": "codeengine"
134+
},
135+
{
136+
"role_crns": [
137+
"crn:v1:bluemix:public:iam::::role:Editor"
138+
],
139+
"service_name": "codeengine"
140+
}
141+
],
142+
"architecture": {
143+
"descriptions": "This deployable architecture creates IBM Cloud Code Engine projects",
144+
"features": [
145+
{
146+
"title": "IBM Cloud Code Engine project",
147+
"description": "Yes"
148+
}
149+
],
150+
"diagrams": [
151+
{
152+
"diagram": {
153+
"caption": "IBM Cloud Code Engine application solution.",
154+
"url": "https://raw.githubusercontent.com/terraform-ibm-modules/terraform-ibm-code-engine/main/reference-architecture/ce-projects-da.svg",
155+
"type": "image/svg+xml"
156+
},
157+
"description": "This deployable architecture creates IBM Cloud Code Engine projects"
158+
}
159+
]
160+
}
122161
}
123162
]
124163
}

reference-architecture/ce-projects-da.svg

+114
Loading

solutions/projects/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# IBM Cloud Code Engine projects deployable architecture
2+
3+
This deployable architecture creates IBM Cloud Code Engine projects and the following optional resources:
4+
5+
- A resource group.
6+
7+
![ce-apps-da](../../reference-architecture/ce-projects-da.svg)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ibmcloud_api_key": $VALIDATION_APIKEY,
3+
"resource_group_name": $PREFIX,
4+
"prefix": $PREFIX,
5+
"project_names": "[\"project1\", \"project2\"]"
6+
}

solutions/projects/main.tf

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
locals {
2+
# add prefix to all projects created by this solution if prefix is not null
3+
projects = [
4+
for project in var.project_names : (
5+
var.prefix != null ? "${var.prefix}-${project}" : project
6+
)
7+
]
8+
}
9+
10+
########################################################################################################################
11+
# Resource group
12+
########################################################################################################################
13+
14+
module "resource_group" {
15+
source = "terraform-ibm-modules/resource-group/ibm"
16+
version = "1.1.6"
17+
resource_group_name = var.existing_resource_group == false ? var.resource_group_name : null
18+
existing_resource_group_name = var.existing_resource_group == true ? var.resource_group_name : null
19+
}
20+
21+
########################################################################################################################
22+
# Code Engine Projects
23+
########################################################################################################################
24+
25+
module "project" {
26+
for_each = toset(local.projects)
27+
source = "../../modules/project"
28+
name = each.value
29+
resource_group_id = module.resource_group.resource_group_id
30+
}

solutions/projects/outputs.tf

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
########################################################################################################################
2+
# Outputs
3+
########################################################################################################################
4+
5+
output "project_name_id_map" {
6+
description = "Map of project names to their corresponding IDs."
7+
value = { for p in module.project : p.name => p.project_id }
8+
}
9+
10+
# IBM Projects Stacks do not support complex outputs at this time,
11+
# As a workaround, we will output the first 5 projects individually. If a project does not exist, the output will be null.
12+
output "project_1_name" {
13+
description = "Name of the first project."
14+
value = length(values(module.project)) > 0 ? values(module.project)[0].name : null
15+
}
16+
17+
output "project_1_id" {
18+
description = "ID of the first project."
19+
value = length(values(module.project)) > 0 ? values(module.project)[0].project_id : null
20+
}
21+
22+
output "project_2_name" {
23+
description = "Name of the second project."
24+
value = length(values(module.project)) > 1 ? values(module.project)[1].name : null
25+
}
26+
27+
output "project_2_id" {
28+
description = "ID of the second project."
29+
value = length(values(module.project)) > 1 ? values(module.project)[1].project_id : null
30+
}
31+
32+
output "project_3_name" {
33+
description = "Name of the third project."
34+
value = length(values(module.project)) > 2 ? values(module.project)[2].name : null
35+
}
36+
37+
output "project_3_id" {
38+
description = "ID of the third project."
39+
value = length(values(module.project)) > 2 ? values(module.project)[2].project_id : null
40+
}
41+
42+
output "project_4_name" {
43+
description = "Name of the fourth project."
44+
value = length(values(module.project)) > 3 ? values(module.project)[3].name : null
45+
}
46+
47+
output "project_4_id" {
48+
description = "ID of the fourth project."
49+
value = length(values(module.project)) > 3 ? values(module.project)[3].project_id : null
50+
}
51+
52+
output "project_5_name" {
53+
description = "Name of the fifth project."
54+
value = length(values(module.project)) > 4 ? values(module.project)[4].name : null
55+
}
56+
57+
output "project_5_id" {
58+
description = "ID of the fifth project."
59+
value = length(values(module.project)) > 4 ? values(module.project)[4].project_id : null
60+
}

solutions/projects/provider.tf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
########################################################################################################################
2+
# Provider config
3+
########################################################################################################################
4+
5+
provider "ibm" {
6+
ibmcloud_api_key = var.ibmcloud_api_key
7+
region = var.region
8+
}

solutions/projects/variables.tf

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
########################################################################################################################
2+
# Input variables
3+
########################################################################################################################
4+
5+
variable "ibmcloud_api_key" {
6+
type = string
7+
description = "The IBM Cloud API key."
8+
sensitive = true
9+
}
10+
11+
variable "prefix" {
12+
type = string
13+
description = "Prefix to added to all projects created by this solution."
14+
default = null
15+
nullable = true
16+
}
17+
18+
variable "region" {
19+
type = string
20+
description = "The region in which to provision all resources created by this solution."
21+
default = "us-south"
22+
}
23+
24+
variable "existing_resource_group" {
25+
type = bool
26+
description = "Whether to use an existing resource group."
27+
default = false
28+
}
29+
30+
variable "resource_group_name" {
31+
type = string
32+
description = "The name of a new or an existing resource group to provision the IBM Cloud Code Engine resources to."
33+
}
34+
35+
variable "project_names" {
36+
description = "The names of the projects to add the IBM Cloud Code Engine."
37+
type = list(string)
38+
}

solutions/projects/version.tf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
terraform {
3+
required_version = ">= 1.3.0"
4+
required_providers {
5+
ibm = {
6+
source = "IBM-Cloud/ibm"
7+
version = "1.68.1"
8+
}
9+
}
10+
}

tests/pr_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,24 @@ func TestRunUpgradeAppSolution(t *testing.T) {
173173
assert.NotNil(t, output, "Expected some output")
174174
}
175175
}
176+
177+
func TestDeployCEProjectsDA(t *testing.T) {
178+
t.Parallel()
179+
180+
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
181+
Testing: t,
182+
TerraformDir: "solutions/projects",
183+
Prefix: "ce-da",
184+
})
185+
186+
options.TerraformVars = map[string]interface{}{
187+
"resource_group_name": resourceGroup,
188+
"existing_resource_group": true,
189+
"prefix": options.Prefix,
190+
"project_names": "[\"test-1\", \"test-2\"]",
191+
}
192+
193+
output, err := options.RunTestConsistency()
194+
assert.Nil(t, err, "This should not have errored")
195+
assert.NotNil(t, output, "Expected some output")
196+
}

0 commit comments

Comments
 (0)