generated from terraform-ibm-modules/terraform-ibm-module-template
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add support to create container registry and secret inside build module #258
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
Open
akocbek
wants to merge
2
commits into
main
Choose a base branch
from
fix_build
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+298
−46
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Build example | ||
|
|
||
| An end-to-end apps example that will provision the following: | ||
| - A new resource group if one is not passed in. | ||
| - Code Engine project | ||
| - Code Engine build | ||
| - Code Engine registry secret | ||
| - Container registry namespace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| ######################################################################################################################## | ||
| # Resource group | ||
| ######################################################################################################################## | ||
|
|
||
| module "resource_group" { | ||
| source = "terraform-ibm-modules/resource-group/ibm" | ||
| version = "1.3.0" | ||
| # 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 | ||
| } | ||
|
|
||
| ######################################################################################################################## | ||
| # Code Engine instance | ||
| ######################################################################################################################## | ||
|
|
||
| module "code_engine" { | ||
| source = "../.." | ||
| ibmcloud_api_key = var.ibmcloud_api_key | ||
| resource_group_id = module.resource_group.resource_group_id | ||
| project_name = "${var.prefix}-project" | ||
| builds = { | ||
| "${var.prefix}-build1" = { | ||
| source_url = "https://github.com/IBM/CodeEngine" | ||
| container_registry_namespace = "cr-ce" | ||
| prefix = var.prefix | ||
| region = var.region | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| ######################################################################################################################## | ||
| # Outputs | ||
| ######################################################################################################################## | ||
|
|
||
| output "resource_group_id" { | ||
| description = "The id of created resource group." | ||
| value = module.resource_group.resource_group_id | ||
| } | ||
|
|
||
| output "resource_group_name" { | ||
| description = "The name of created resource group." | ||
| value = module.resource_group.resource_group_name | ||
| } | ||
|
|
||
| output "project_id" { | ||
| description = "ID of the created code engine project." | ||
| value = module.code_engine.project_id | ||
| } | ||
|
|
||
| output "build" { | ||
| description = "Configuration of the created code engine domain mapping." | ||
| value = module.code_engine.build | ||
| sensitive = true | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| ######################################################################################################################## | ||
| # Input variables | ||
| ######################################################################################################################## | ||
|
|
||
| variable "ibmcloud_api_key" { | ||
| type = string | ||
| description = "The IBM Cloud API Key" | ||
| sensitive = true | ||
| } | ||
|
|
||
| variable "region" { | ||
| type = string | ||
| description = "Region to provision all resources created by this example" | ||
| default = "us-south" | ||
| } | ||
|
|
||
| variable "prefix" { | ||
| type = string | ||
| description = "Prefix to append to all resources created by this example" | ||
| default = "ce-build" | ||
| } | ||
|
|
||
| variable "resource_group" { | ||
| 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" | ||
| default = null | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
|
|
||
| terraform { | ||
| required_version = ">= 1.9.0" | ||
| # Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main | ||
| # module's version.tf (this example), and 1 example that will always use the latest provider version (jobs examples). | ||
| required_providers { | ||
| ibm = { | ||
| source = "IBM-Cloud/ibm" | ||
| version = ">= 1.79.0, < 2.0.0" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,15 @@ | |
| # Create Code Engine build | ||
| ############################################################################## | ||
|
|
||
| locals { | ||
| prefix = var.prefix != null ? (trimspace(var.prefix) != "" ? "${var.prefix}-" : "") : "" | ||
| } | ||
|
|
||
| resource "ibm_code_engine_build" "ce_build" { | ||
| project_id = var.project_id | ||
| name = var.name | ||
| output_image = var.output_image | ||
| output_secret = var.output_secret | ||
| output_image = local.output_image | ||
| output_secret = var.output_secret != null ? var.output_secret : module.secret[0].name | ||
| source_url = var.source_url | ||
| source_context_dir = var.source_context_dir | ||
| source_revision = var.source_revision | ||
|
|
@@ -39,3 +43,46 @@ resource "terraform_data" "run_build" { | |
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| ############################################################################## | ||
| # Container Registry | ||
| ############################################################################## | ||
|
|
||
| locals { | ||
| create_cr_namespace = var.output_image == null && var.container_registry_namespace != null ? true : false | ||
| image_container = local.create_cr_namespace ? "${module.cr_endpoint[0].container_registry_endpoint_private}/${module.cr_namespace[0].namespace_name}" : null | ||
| output_image = local.create_cr_namespace ? "${local.image_container}/${var.name}" : var.output_image | ||
| } | ||
|
|
||
| module "cr_namespace" { | ||
| count = local.create_cr_namespace ? 1 : 0 | ||
| source = "terraform-ibm-modules/container-registry/ibm" | ||
| version = "2.1.0" | ||
| namespace_name = "${local.prefix}${var.container_registry_namespace}" | ||
| resource_group_id = var.existing_resource_group_id | ||
| } | ||
|
|
||
| module "cr_endpoint" { | ||
| count = local.create_cr_namespace ? 1 : 0 | ||
| source = "terraform-ibm-modules/container-registry/ibm//modules/endpoint" | ||
| version = "2.1.0" | ||
| region = var.region | ||
| } | ||
|
|
||
| ############################################################################## | ||
| # Code Engine Secret | ||
| ############################################################################## | ||
|
|
||
| module "secret" { | ||
| count = var.output_secret == null ? 1 : 0 | ||
| source = "../../modules/secret" | ||
| project_id = var.project_id | ||
| name = "${local.prefix}registry-access-secret" | ||
| data = { | ||
| password = var.container_registry_api_key != null ? var.container_registry_api_key : var.ibmcloud_api_key, | ||
| username = "iamapikey", | ||
| server = module.cr_endpoint[0].container_registry_endpoint_private | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The value of server may be undefined. When local.create_name_space is false module.cr_endpoint does not exist. See comment on module definition. |
||
| } | ||
| format = "registry" | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the count cause an issue an existing namespace is passed?
It seems there should be no count and the module should always be created. The value is used when creating a code engine secret to access the container registry, which is unrelated to namespace creation.
Additional comment included where this is used.