Skip to content

Commit 7c3cff0

Browse files
authored
feat: add support to create container registry and secret inside build module (#258)
1 parent 9eabb71 commit 7c3cff0

File tree

16 files changed

+280
-107
lines changed

16 files changed

+280
-107
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This module provisions the IBM Cloud Code Engine fully managed and serverless pl
2626
* [secret](./modules/secret)
2727
* [Examples](./examples)
2828
* <div style="display: inline-block;"><a href="./examples/apps">Apps example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=ce-apps-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-code-engine/tree/main/examples/apps" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
29+
* <div style="display: inline-block;"><a href="./examples/build">Build example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=ce-build-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-code-engine/tree/main/examples/build" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
2930
* <div style="display: inline-block;"><a href="./examples/jobs">Jobs example</a></div> <div style="display: inline-block; vertical-align: middle;"><a href="https://cloud.ibm.com/schematics/workspaces/create?workspace_name=ce-jobs-example&repository=https://github.com/terraform-ibm-modules/terraform-ibm-code-engine/tree/main/examples/jobs" target="_blank"><img src="https://cloud.ibm.com/media/docs/images/icons/Deploy_to_cloud.svg" alt="Deploy to IBM Cloud button"></a></div>
3031
* [Contributing](#contributing)
3132
<!-- END OVERVIEW HOOK -->
@@ -157,7 +158,7 @@ No resources.
157158
|------|-------------|------|---------|:--------:|
158159
| <a name="input_apps"></a> [apps](#input\_apps) | A map of code engine apps to be created. | <pre>map(object({<br/> image_reference = string<br/> image_secret = optional(string)<br/> run_env_variables = optional(list(object({<br/> type = optional(string)<br/> name = optional(string)<br/> value = optional(string)<br/> prefix = optional(string)<br/> key = optional(string)<br/> reference = optional(string)<br/> })))<br/> run_volume_mounts = optional(list(object({<br/> mount_path = string<br/> reference = string<br/> name = optional(string)<br/> type = string<br/> })))<br/> image_port = optional(number)<br/> managed_domain_mappings = optional(string)<br/> run_arguments = optional(list(string))<br/> run_as_user = optional(number)<br/> run_commands = optional(list(string))<br/> run_service_account = optional(string)<br/> scale_concurrency = optional(number)<br/> scale_concurrency_target = optional(number)<br/> scale_cpu_limit = optional(string)<br/> scale_ephemeral_storage_limit = optional(string)<br/> scale_initial_instances = optional(number)<br/> scale_max_instances = optional(number)<br/> scale_memory_limit = optional(string)<br/> scale_min_instances = optional(number)<br/> scale_request_timeout = optional(number)<br/> scale_down_delay = optional(number)<br/> }))</pre> | `{}` | no |
159160
| <a name="input_bindings"></a> [bindings](#input\_bindings) | A map of code engine bindings to be created. | <pre>map(object({<br/> secret_name = string<br/> components = list(object({<br/> name = string<br/> resource_type = string<br/> }))<br/> }))</pre> | `{}` | no |
160-
| <a name="input_builds"></a> [builds](#input\_builds) | A map of code engine builds to be created. Requires 'ibmcloud\_api\_key' to be set for authentication and execution. | <pre>map(object({<br/> output_image = string<br/> output_secret = string # pragma: allowlist secret<br/> source_url = string<br/> strategy_type = string<br/> source_context_dir = optional(string)<br/> source_revision = optional(string)<br/> source_secret = optional(string)<br/> source_type = optional(string)<br/> strategy_size = optional(string)<br/> strategy_spec_file = optional(string)<br/> timeout = optional(number)<br/> }))</pre> | `{}` | no |
161+
| <a name="input_builds"></a> [builds](#input\_builds) | A map of code engine builds to be created. Requires 'ibmcloud\_api\_key' to be set for authentication and execution. | <pre>map(object({<br/> output_image = optional(string)<br/> output_secret = optional(string) # pragma: allowlist secret<br/> source_url = string<br/> strategy_type = optional(string)<br/> source_context_dir = optional(string)<br/> source_revision = optional(string)<br/> source_secret = optional(string)<br/> source_type = optional(string)<br/> strategy_size = optional(string)<br/> strategy_spec_file = optional(string)<br/> timeout = optional(number)<br/> region = optional(string)<br/> container_registry_namespace = optional(string)<br/> prefix = optional(string)<br/> }))</pre> | `{}` | no |
161162
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | The context-based restrictions rule to create. Only one rule is allowed. | <pre>list(object({<br/> description = string<br/> account_id = string<br/> rule_contexts = list(object({<br/> attributes = optional(list(object({<br/> name = string<br/> value = string<br/> }))) }))<br/> enforcement_mode = string<br/> operations = optional(list(object({<br/> api_types = list(object({<br/> api_type_id = string<br/> }))<br/> })))<br/> }))</pre> | `[]` | no |
162163
| <a name="input_config_maps"></a> [config\_maps](#input\_config\_maps) | A map of code engine config maps to be created. | <pre>map(object({<br/> data = map(string)<br/> }))</pre> | `{}` | no |
163164
| <a name="input_domain_mappings"></a> [domain\_mappings](#input\_domain\_mappings) | A map of code engine domain mappings to be created. | <pre>map(object({<br/> tls_secret = string # pragma: allowlist secret<br/> components = list(object({<br/> name = string<br/> resource_type = string<br/> }))<br/> }))</pre> | `{}` | no |

examples/build/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Build example
2+
3+
An end-to-end apps example that will provision the following:
4+
- A new resource group if one is not passed in.
5+
- Code Engine project
6+
- Code Engine build
7+
- Code Engine registry secret
8+
- Container registry namespace

tests/resources/main.tf renamed to examples/build/main.tf

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ module "resource_group" {
1111
}
1212

1313
########################################################################################################################
14-
# Secrets Manager resources
14+
# Code Engine instance
1515
########################################################################################################################
1616

17-
data "ibm_sm_public_certificate" "public_certificate" {
18-
# depends_on = [resource.ibm_sm_public_certificate.secrets_manager_public_certificate]
19-
instance_id = var.existing_sm_instance_guid
20-
region = var.existing_sm_instance_region
21-
secret_id = var.existing_cert_secret_id
22-
}
23-
24-
25-
module "namespace" {
26-
source = "terraform-ibm-modules/container-registry/ibm"
27-
version = "2.3.5"
28-
namespace_name = "${var.prefix}-namespace"
17+
module "code_engine" {
18+
source = "../.."
19+
ibmcloud_api_key = var.ibmcloud_api_key
2920
resource_group_id = module.resource_group.resource_group_id
30-
images_per_repo = 1
21+
project_name = "${var.prefix}-project"
22+
builds = {
23+
"${var.prefix}-build1" = {
24+
source_url = "https://github.com/IBM/CodeEngine"
25+
container_registry_namespace = "cr-ce"
26+
prefix = var.prefix
27+
region = var.region
28+
}
29+
}
3130
}

examples/build/outputs.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
########################################################################################################################
2+
# Outputs
3+
########################################################################################################################
4+
5+
output "resource_group_id" {
6+
description = "The id of created resource group."
7+
value = module.resource_group.resource_group_id
8+
}
9+
10+
output "resource_group_name" {
11+
description = "The name of created resource group."
12+
value = module.resource_group.resource_group_name
13+
}
14+
15+
output "project_id" {
16+
description = "ID of the created code engine project."
17+
value = module.code_engine.project_id
18+
}
19+
20+
output "build" {
21+
description = "Configuration of the created code engine domain mapping."
22+
value = module.code_engine.build
23+
sensitive = true
24+
}

tests/resources/provider.tf renamed to examples/build/provider.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
provider "ibm" {
66
ibmcloud_api_key = var.ibmcloud_api_key
7-
region = var.existing_sm_instance_region
7+
region = var.region
88
}

tests/resources/variables.tf renamed to examples/build/variables.tf

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,20 @@ variable "ibmcloud_api_key" {
88
sensitive = true
99
}
1010

11+
variable "region" {
12+
type = string
13+
description = "Region to provision all resources created by this example"
14+
default = "us-south"
15+
}
16+
1117
variable "prefix" {
1218
type = string
1319
description = "Prefix to append to all resources created by this example"
14-
default = "ce-prj"
20+
default = "ce-build"
1521
}
1622

1723
variable "resource_group" {
1824
type = string
1925
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"
2026
default = null
2127
}
22-
23-
##############################################################
24-
# Secret Manager
25-
##############################################################
26-
27-
variable "existing_sm_instance_guid" {
28-
type = string
29-
description = "An existing Secrets Manager GUID. The existing Secret Manager instance must have private certificate engine configured. If not provided an new instance will be provisioned."
30-
default = null
31-
}
32-
33-
variable "existing_sm_instance_region" {
34-
type = string
35-
description = "Required if value is passed into `var.existing_sm_instance_guid`."
36-
default = null
37-
}
38-
39-
variable "existing_cert_secret_id" {
40-
type = string
41-
description = "Required if value is passed into `var.existing_sm_instance_guid`."
42-
default = null
43-
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
terraform {
3-
required_version = ">= 1.3.0"
3+
required_version = ">= 1.9.0"
44
# Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main
55
# module's version.tf (this example), and 1 example that will always use the latest provider version (jobs examples).
66
required_providers {
77
ibm = {
88
source = "IBM-Cloud/ibm"
9-
version = ">= 1.70.0, < 2.0.0"
9+
version = ">= 1.79.0, < 2.0.0"
1010
}
1111
}
1212
}

main.tf

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,24 +99,27 @@ module "secret" {
9999
# Code Engine Build
100100
##############################################################################
101101
module "build" {
102-
depends_on = [module.secret]
103-
source = "./modules/build"
104-
for_each = var.builds
105-
ibmcloud_api_key = var.ibmcloud_api_key
106-
existing_resource_group_id = var.resource_group_id
107-
project_id = local.project_id
108-
name = each.key
109-
output_image = each.value.output_image
110-
output_secret = each.value.output_secret
111-
source_url = each.value.source_url
112-
strategy_type = each.value.strategy_type
113-
source_context_dir = each.value.source_context_dir
114-
source_revision = each.value.source_revision
115-
source_secret = each.value.source_secret
116-
source_type = each.value.source_type
117-
strategy_size = each.value.strategy_size
118-
strategy_spec_file = each.value.strategy_spec_file
119-
timeout = each.value.timeout
102+
depends_on = [module.secret]
103+
source = "./modules/build"
104+
for_each = var.builds
105+
ibmcloud_api_key = var.ibmcloud_api_key
106+
existing_resource_group_id = var.resource_group_id
107+
project_id = local.project_id
108+
name = each.key
109+
output_image = each.value.output_image
110+
output_secret = each.value.output_secret
111+
source_url = each.value.source_url
112+
strategy_type = each.value.strategy_type
113+
source_context_dir = each.value.source_context_dir
114+
source_revision = each.value.source_revision
115+
source_secret = each.value.source_secret
116+
source_type = each.value.source_type
117+
strategy_size = each.value.strategy_size
118+
strategy_spec_file = each.value.strategy_spec_file
119+
timeout = each.value.timeout
120+
region = each.value.region
121+
container_registry_namespace = each.value.container_registry_namespace
122+
prefix = each.value.prefix
120123
}
121124

122125
##############################################################################

modules/build/README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ You need the following permissions to run this module.
4040

4141
### Modules
4242

43-
No modules.
43+
| Name | Source | Version |
44+
|------|--------|---------|
45+
| <a name="module_cr_endpoint"></a> [cr\_endpoint](#module\_cr\_endpoint) | terraform-ibm-modules/container-registry/ibm//modules/endpoint | 2.1.0 |
46+
| <a name="module_cr_namespace"></a> [cr\_namespace](#module\_cr\_namespace) | terraform-ibm-modules/container-registry/ibm | 2.1.0 |
47+
| <a name="module_secret"></a> [secret](#module\_secret) | ../../modules/secret | n/a |
4448

4549
### Resources
4650

@@ -54,21 +58,24 @@ No modules.
5458

5559
| Name | Description | Type | Default | Required |
5660
|------|-------------|------|---------|:--------:|
61+
| <a name="input_container_registry_api_key"></a> [container\_registry\_api\_key](#input\_container\_registry\_api\_key) | The API key for the container registry in the target account. This is only used if 'output\_secret' is not set and a new registry secret needs to be created. If not provided, the IBM Cloud API key (ibmcloud\_api\_key) will be used instead. | `string` | `null` | no |
62+
| <a name="input_container_registry_namespace"></a> [container\_registry\_namespace](#input\_container\_registry\_namespace) | The name of the namespace to create in IBM Cloud Container Registry for organizing container images. Must be set if 'output\_image' is not set. If a prefix input variable is specified, the prefix is added to the name in the `<prefix>-<container_registry_namespace>` format. | `string` | `null` | no |
5763
| <a name="input_existing_resource_group_id"></a> [existing\_resource\_group\_id](#input\_existing\_resource\_group\_id) | The ID of an existing resource group where build will be provisioned. This must be the same resource group in which the code engine project was created. | `string` | n/a | yes |
5864
| <a name="input_ibmcloud_api_key"></a> [ibmcloud\_api\_key](#input\_ibmcloud\_api\_key) | The IBM Cloud API key. | `string` | n/a | yes |
5965
| <a name="input_name"></a> [name](#input\_name) | The name of the build. | `string` | n/a | yes |
60-
| <a name="input_output_image"></a> [output\_image](#input\_output\_image) | The name of the image. | `string` | n/a | yes |
61-
| <a name="input_output_secret"></a> [output\_secret](#input\_output\_secret) | The secret that is required to access the image registry. | `string` | n/a | yes |
66+
| <a name="input_output_image"></a> [output\_image](#input\_output\_image) | A container image can be identified by a container image reference with the following structure: registry / namespace / repository:tag. [Learn more](https://cloud.ibm.com/docs/codeengine?topic=codeengine-getting-started).<br/><br/>If not provided, the value will be derived from the 'container\_registry\_namespace' input variable, which must not be null in that case. | `string` | `null` | no |
67+
| <a name="input_output_secret"></a> [output\_secret](#input\_output\_secret) | The name of the Code Engine secret that contains an API key to access the IBM Cloud Container Registry.<br/>The API key stored in this secret must have push permissions for the specified container registry namespace.<br/>If this secret is not provided, a Code Engine secret named `<prefix>-<registry-access-secret>` will be created automatically. Its value will be taken from 'container\_registry\_api\_key' if set, otherwise from 'ibmcloud\_api\_key'. | `string` | `null` | no |
68+
| <a name="input_prefix"></a> [prefix](#input\_prefix) | Prefix appended to the container registry namespace and registry secret if created. | `string` | `null` | no |
6269
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | The ID of the project where build will be created. | `string` | n/a | yes |
6370
| <a name="input_region"></a> [region](#input\_region) | The region in which to provision the build. This must be the same region in which the code engine project was created. | `string` | `"us-south"` | no |
6471
| <a name="input_source_context_dir"></a> [source\_context\_dir](#input\_source\_context\_dir) | The directory in the repository that contains the buildpacks file or the Dockerfile. | `string` | `null` | no |
6572
| <a name="input_source_revision"></a> [source\_revision](#input\_source\_revision) | Commit, tag, or branch in the source repository to pull. | `string` | `null` | no |
66-
| <a name="input_source_secret"></a> [source\_secret](#input\_source\_secret) | The name of the secret that is used access the repository source. If the var.source\_type value is `local`, this field must be omitted. | `string` | `null` | no |
67-
| <a name="input_source_type"></a> [source\_type](#input\_source\_type) | Specifies the type of source to determine if your build source is in a repository or based on local source code. | `string` | `null` | no |
73+
| <a name="input_source_secret"></a> [source\_secret](#input\_source\_secret) | The name of the secret that is used access the repository source. If the var.source\_type value is `local`, this input must be omitted. | `string` | `null` | no |
74+
| <a name="input_source_type"></a> [source\_type](#input\_source\_type) | Specifies the type of source to determine if your build source is in a repository or based on local source code. If the value is `local`, then 'source\_secret' input must be omitted. | `string` | `null` | no |
6875
| <a name="input_source_url"></a> [source\_url](#input\_source\_url) | The URL of the code repository. | `string` | n/a | yes |
6976
| <a name="input_strategy_size"></a> [strategy\_size](#input\_strategy\_size) | The size for the build, which determines the amount of resources used. | `string` | `null` | no |
7077
| <a name="input_strategy_spec_file"></a> [strategy\_spec\_file](#input\_strategy\_spec\_file) | The path to the specification file that is used for build strategies for building an image. | `string` | `null` | no |
71-
| <a name="input_strategy_type"></a> [strategy\_type](#input\_strategy\_type) | The strategy to use for building the image. | `string` | n/a | yes |
78+
| <a name="input_strategy_type"></a> [strategy\_type](#input\_strategy\_type) | The strategy to use for building the image. | `string` | `"dockerfile"` | no |
7279
| <a name="input_timeout"></a> [timeout](#input\_timeout) | The maximum amount of time, in seconds, that can pass before the build must succeed or fail. | `number` | `600` | no |
7380

7481
### Outputs

0 commit comments

Comments
 (0)