Skip to content

Ce projects da #92

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

Merged
merged 13 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
39 changes: 39 additions & 0 deletions ibm_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,45 @@
}
]
}
},
{
"label": "New Code Engine projects",
"name": "projects",
"install_type": "fullstack",
"working_directory": "solutions/projects",
"iam_permissions": [
{
"role_crns": [
"crn:v1:bluemix:public:iam::::serviceRole:Writer"
],
"service_name": "codeengine"
},
{
"role_crns": [
"crn:v1:bluemix:public:iam::::role:Editor"
],
"service_name": "codeengine"
}
],
"architecture": {
"descriptions": "This deployable architecture creates IBM Cloud Code Engine projects",
"features": [
{
"title": "IBM Cloud Code Engine project",
"description": "Yes"
}
],
"diagrams": [
{
"diagram": {
"caption": "IBM Cloud Code Engine application solution.",
"url": "https://raw.githubusercontent.com/terraform-ibm-modules/terraform-ibm-code-engine/main/reference-architecture/ce-projects-da.svg",
"type": "image/svg+xml"
},
"description": "This deployable architecture creates IBM Cloud Code Engine projects"
}
]
}
}
]
}
Expand Down
114 changes: 114 additions & 0 deletions reference-architecture/ce-projects-da.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions solutions/projects/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# IBM Cloud Code Engine projects deployable architecture

This deployable architecture creates IBM Cloud Code Engine projects and the following optional resources:

- A resource group.
- A Code Engine projects.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you already mention on line 3 that is creates code engine projects


![ce-apps-da](../../reference-architecture/ce-projects-da.svg)
8 changes: 8 additions & 0 deletions solutions/projects/catalogValidationValues.json.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"ibmcloud_api_key": $VALIDATION_APIKEY,
"resource_group_name": $PREFIX,
"prefix": $PREFIX,
"project_names": [
Copy link
Contributor

@ocofaigh ocofaigh Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this syntax is not supported. The variable substitution only works for strings right now. However you should be able to do this and it will add the prefix value to each project name right? So the validation wont have ant name clashes.

"project_names": "[\"project1\", \"project2\"]"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A list of project names is required input. Is there another way of passing the values?

Copy link
Contributor

@ocofaigh ocofaigh Aug 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That string will convert to a terraform list when passed to projects / schematics. Just like it does here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daniel-butler-irl you still need to update to "project_names": "[\"project1\", \"project2\"]" for this to work

$PREFIX
]
}
30 changes: 30 additions & 0 deletions solutions/projects/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
locals {
# add prefix to all projects created by this solution if prefix is not null
projects = [
for project in var.project_names : (
var.prefix != null ? "${var.prefix}-${project}" : project
)
]
}

########################################################################################################################
# Resource group
########################################################################################################################

module "resource_group" {
source = "terraform-ibm-modules/resource-group/ibm"
version = "1.1.6"
resource_group_name = var.existing_resource_group == false ? var.resource_group_name : null
existing_resource_group_name = var.existing_resource_group == true ? var.resource_group_name : null
}

########################################################################################################################
# Code Engine Projects
########################################################################################################################

module "project" {
for_each = toset(local.projects)
source = "../../modules/project"
name = each.value
resource_group_id = module.resource_group.resource_group_id
}
60 changes: 60 additions & 0 deletions solutions/projects/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
########################################################################################################################
# Outputs
########################################################################################################################

output "project_name_id_map" {
description = "Map of project names to their corresponding IDs."
value = { for p in module.project : p.name => p.project_id }
}

# IBM Projects Stacks do not support complex outputs at this time,
# As a workaround, we will output the first 5 projects individually. If a project does not exist, the output will be null.
output "project_1_name" {
description = "Name of the first project."
value = length(values(module.project)) > 0 ? values(module.project)[0].name : null
}

output "project_1_id" {
description = "ID of the first project."
value = length(values(module.project)) > 0 ? values(module.project)[0].project_id : null
}

output "project_2_name" {
description = "Name of the second project."
value = length(values(module.project)) > 1 ? values(module.project)[1].name : null
}

output "project_2_id" {
description = "ID of the second project."
value = length(values(module.project)) > 1 ? values(module.project)[1].project_id : null
}

output "project_3_name" {
description = "Name of the third project."
value = length(values(module.project)) > 2 ? values(module.project)[2].name : null
}

output "project_3_id" {
description = "ID of the third project."
value = length(values(module.project)) > 2 ? values(module.project)[2].project_id : null
}

output "project_4_name" {
description = "Name of the fourth project."
value = length(values(module.project)) > 3 ? values(module.project)[3].name : null
}

output "project_4_id" {
description = "ID of the fourth project."
value = length(values(module.project)) > 3 ? values(module.project)[3].project_id : null
}

output "project_5_name" {
description = "Name of the fifth project."
value = length(values(module.project)) > 4 ? values(module.project)[4].name : null
}

output "project_5_id" {
description = "ID of the fifth project."
value = length(values(module.project)) > 4 ? values(module.project)[4].project_id : null
}
8 changes: 8 additions & 0 deletions solutions/projects/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
########################################################################################################################
# Provider config
########################################################################################################################

provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
region = var.region
}
38 changes: 38 additions & 0 deletions solutions/projects/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
########################################################################################################################
# Input variables
########################################################################################################################

variable "ibmcloud_api_key" {
type = string
description = "The IBM Cloud API key."
sensitive = true
}

variable "prefix" {
type = string
description = "Prefix to added to all projects created by this solution."
default = null
nullable = true
}

variable "region" {
type = string
description = "The region in which to provision all resources created by this solution."
default = "us-south"
}

variable "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 a new or an existing resource group to provision the IBM Cloud Code Engine resources to."
}

variable "project_names" {
description = "The names of the projects to add the IBM Cloud Code Engine."
type = list(string)
}
10 changes: 10 additions & 0 deletions solutions/projects/version.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

terraform {
required_version = ">= 1.3.0"
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = "1.68.1"
}
}
}
21 changes: 21 additions & 0 deletions tests/pr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,24 @@ func TestRunUpgradeAppSolution(t *testing.T) {
assert.NotNil(t, output, "Expected some output")
}
}

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

options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
Testing: t,
TerraformDir: "solutions/projects",
Prefix: "ce-da",
})

options.TerraformVars = map[string]interface{}{
"resource_group_name": resourceGroup,
"existing_resource_group": true,
"prefix": options.Prefix,
"project_names": "[\"test-1\", \"test-2\"]",
}

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