Skip to content

Commit 63793ae

Browse files
authored
feat: initial release
2 parents b854c2e + 76b63dd commit 63793ae

35 files changed

+1222
-269
lines changed

.github/settings.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ repository:
1515
# By changing this field, you rename the repository.
1616

1717
# Uncomment this name property and set the name to the current repo name.
18-
# name: ""
18+
name: "terraform-ibm-icd-postgresql"
1919

2020
# The description is displayed under the repository name on the
2121
# organization page and in the 'About' section of the repository.
2222

2323
# Uncomment this description property
2424
# and update the description to the current repo description.
25-
# description: ""
25+
description: "Implements a ICD Postgresql instance with tags, users, memory allocation, disk allocation, cpu allocation and context based restrictions"

.secrets.baseline

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": "go.sum|^.secrets.baseline$",
44
"lines": null
55
},
6-
"generated_at": "2022-12-29T22:59:55Z",
6+
"generated_at": "2023-02-07T13:40:16Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -76,7 +76,18 @@
7676
"name": "TwilioKeyDetector"
7777
}
7878
],
79-
"results": {},
79+
"results": {
80+
"README.md": [
81+
{
82+
"hashed_secret": "8acbd0ff478f744859b92e1251622e4124bceef0",
83+
"is_secret": false,
84+
"is_verified": false,
85+
"line_number": 22,
86+
"type": "Secret Keyword",
87+
"verified_result": null
88+
}
89+
]
90+
},
8091
"version": "0.13.1+ibm.56.dss",
8192
"word_list": {
8293
"file": null,

README.md

Lines changed: 45 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,160 +1,93 @@
11
<!-- BEGIN MODULE HOOK -->
22

33
<!-- Update the title to match the module name and add a description -->
4-
# Terraform Modules Template Project
4+
# IBM Cloud Databases for ICD Postgresql module
55
<!-- UPDATE BADGE: Update the link for the following badge-->
66
[![Incubating (Not yet consumable)](https://img.shields.io/badge/status-Incubating%20(Not%20yet%20consumable)-red)](https://terraform-ibm-modules.github.io/documentation/#/badge-status)
77
[![Build status](https://github.com/terraform-ibm-modules/terraform-ibm-module-template/actions/workflows/ci.yml/badge.svg)](https://github.com/terraform-ibm-modules/terraform-ibm-module-template/actions/workflows/ci.yml)
88
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
9-
[![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-module-template?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-module-template/releases/latest)
9+
[![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-icd-postgresql?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-icd-postgresql/releases/latest)
1010
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)
1111
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
1212

13-
<!-- Remove the content in this H2 heading after completing the steps -->
14-
15-
## Submit a new module
16-
17-
:+1::tada: Thank you for taking the time to contribute! :tada::+1:
18-
19-
This template repository exists to help you create Terraform modules for IBM Cloud.
20-
21-
The default structure includes the following files:
22-
23-
- `README.md`: A description of the module
24-
- `main.tf`: The logic for the module
25-
- `version.tf`: The required terraform and provider versions
26-
- `variables.tf`: The input variables for the module
27-
- `outputs.tf`: The values that are output from the module
28-
For more information, see [Module structure](https://terraform-ibm-modules.github.io/documentation/#/module-structure) in the project documentation.
29-
30-
You can add other content to support what your module does and how it works. For example, you might add a `scripts/` directory that contains shell scripts that are run by a `local-exec` `null_resource` in the Terraform module.
31-
32-
Follow this process to create and submit a Terraform module.
33-
34-
### Create a repo from this repo template
35-
36-
1. Create a repository from this repository template by clicking `Use this template` in the upper right of the GitHub UI.
37-
&emsp;&emsp;&emsp;&emsp;<br>For more information about creating a repository from a template, see the [GitHub docs](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template).
38-
1. Select `terraform-ibm-modules` as the owner.
39-
1. Enter a name for the module in format `terraform-ibm-<NAME>`, where `<NAME>` reflects the type of infrastructure that the module manages.
40-
&emsp;&emsp;&emsp;&emsp;<br>Use hyphens as delimiters for names with multiple words (for example, terraform-ibm-`activity-tracker`).
41-
1. Provide a short description of the module.
42-
&emsp;&emsp;&emsp;&emsp;<br>The description is displayed under the repository name on the [organization page](https://github.com/terraform-ibm-modules) and in the **About** section of the repository. Use the description to help users understand the purpose of your module. For more information, see [module names and descriptions](https://terraform-ibm-modules.github.io/documentation/#/implementation-guidelines?id=module-names-and-descriptions) in the docs.
43-
44-
### Clone the repo and set up your development environment
45-
46-
Locally clone the new repository and set up your development environment by completing the tasks in [Local development setup](https://terraform-ibm-modules.github.io/documentation/#/local-dev-setup) in the project documentation.
47-
48-
### Update the repo name and description in source control
49-
50-
To help make sure that the repo name and description are not changed except through pull requests, they are defined in the `settings.yml` file.
51-
52-
Check to make sure that values are uncommented and correct:
53-
54-
1. Open the [settings.yml](.github/settings.yml) file.
55-
1. If not already updated, uncomment the `name` and `description` properties and set the values to what you specified when you requested the repo.
56-
57-
### Update the Terraform files
58-
59-
Implement the logic for your module by updating the `main.tf`, `version.tf`, `variables.tf`, and `outputs.tf` Terraform files. For more information, see [Creating Terraform on IBM Cloud templates](https://cloud.ibm.com/docs/ibm-cloud-provider-for-terraform?topic=ibm-cloud-provider-for-terraform-create-tf-config).
60-
61-
### Create examples and tests
62-
63-
Add one or more examples in the `examples` directory that consume your new module, and configure tests for them in the `tests` directory. For more information about tests, see [Tests](https://terraform-ibm-modules.github.io/documentation/#/tests).
64-
65-
### Update the content in the readme file
66-
67-
After you implement the logic for your module and create examples and tests, update this readme file in your repository by following these steps:
68-
69-
1. Update the title heading and add a description about your module.
70-
1. Update the badge links.
71-
1. Remove all the content in this H2 heading section.
72-
1. Complete the [Usage](#usage) and [Required IAM access policies](#required-iam-access-policies) sections. The [Examples](#examples) and [Requirements](#requirements) section are populated by a pre-commit hook.
73-
74-
### Commit your code and submit your module for review
75-
76-
1. Before you commit any code, review [Contributing to the IBM Cloud Terraform modules project](https://terraform-ibm-modules.github.io/documentation/#/contribute-module) in the project documentation.
77-
1. Create a pull request for review.
78-
79-
### Post-merge steps
80-
81-
After the first PR for your module is merged, follow these post-merge steps:
82-
83-
1. Create a PR to enable the upgrade test by removing the `t.Skip` line in `tests/pr_test.go`.
84-
85-
<!-- Remove the content in this previous H2 heading -->
8613

8714
## Usage
8815

89-
<!--
90-
Add an example of the use of the module in the following code block.
91-
92-
Use real values instead of "var.<var_name>" or other placeholder values
93-
unless real values don't help users know what to change.
94-
-->
16+
> WARNING: **This module does not support major version upgrade or updates to encryption and backup encryption keys**: To upgrade version create a new postgresql instance with the updated version and follow the [Upgrading PostgreSQL docs](https://cloud.ibm.com/docs/databases-for-postgresql?topic=databases-for-postgresql-upgrading&interface=cli)
9517
9618
```hcl
97-
19+
module "postgresql_db" {
20+
# replace main with version
21+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-icd-postgresql?ref=main"
22+
admin_password = var.admin_password
23+
resource_group_id = module.resource_group.resource_group_id
24+
name = var.name
25+
}
9826
```
9927

10028
## Required IAM access policies
10129

102-
<!-- PERMISSIONS REQUIRED TO RUN MODULE
103-
If this module requires permissions, uncomment the following block and update
104-
the sample permissions, following the format.
105-
Replace the sample Account and IBM Cloud service names and roles with the
106-
information in the console at
107-
Manage > Access (IAM) > Access groups > Access policies.
108-
-->
109-
110-
<!--
11130
You need the following permissions to run this module.
11231

11332
- Account Management
114-
- **Sample Account Service** service
115-
- `Editor` platform access
116-
- `Manager` service access
117-
- IAM Services
118-
- **Sample Cloud Service** service
119-
- `Administrator` platform access
120-
-->
121-
122-
<!-- NO PERMISSIONS FOR MODULE
123-
If no permissions are required for the module, uncomment the following
124-
statement instead the previous block.
125-
-->
126-
127-
<!-- No permissions are needed to run this module.-->
33+
- **Databases for PostgreSQL** service
34+
- `Editor` role access
12835
<!-- END MODULE HOOK -->
12936
<!-- BEGIN EXAMPLES HOOK -->
13037
## Examples
13138

39+
- [ Autoscale example](examples/autoscale)
40+
- [ Complete example with byok encryption, CBR rules and storing credentials in secrets manager](examples/complete)
13241
- [ Default example](examples/default)
133-
- [ Example that uses existing resources](examples/existing-resources)
134-
- [ Non default example](examples/non-default)
13542
<!-- END EXAMPLES HOOK -->
13643
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
13744
## Requirements
13845

13946
| Name | Version |
14047
|------|---------|
141-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
48+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
49+
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.49.0 |
14250

14351
## Modules
14452

145-
No modules.
53+
| Name | Source | Version |
54+
|------|--------|---------|
55+
| <a name="module_cbr_rule"></a> [cbr\_rule](#module\_cbr\_rule) | git::https://github.com/terraform-ibm-modules/terraform-ibm-cbr//cbr-rule-module | v1.1.2 |
14656

14757
## Resources
14858

149-
No resources.
59+
| Name | Type |
60+
|------|------|
61+
| [ibm_database.postgresql_db](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database) | resource |
15062

15163
## Inputs
15264

153-
No inputs.
65+
| Name | Description | Type | Default | Required |
66+
|------|-------------|------|---------|:--------:|
67+
| <a name="input_allowlist"></a> [allowlist](#input\_allowlist) | Set of IP address and description to allowlist in database | <pre>list(object({<br> address = optional(string)<br> description = optional(string)<br> }))</pre> | `[]` | no |
68+
| <a name="input_auto_scaling"></a> [auto\_scaling](#input\_auto\_scaling) | (Optional) Configure rules to allow your database to automatically increase its resources. Single block of autoscaling is allowed at once. | <pre>object({<br> cpu = object({<br> rate_increase_percent = optional(number)<br> rate_limit_count_per_member = optional(number)<br> rate_period_seconds = optional(number)<br> rate_units = optional(string)<br> })<br> disk = object({<br> capacity_enabled = optional(bool)<br> free_space_less_than_percent = optional(number)<br> io_above_percent = optional(number)<br> io_enabled = optional(bool)<br> io_over_period = optional(string)<br> rate_increase_percent = optional(number)<br> rate_limit_mb_per_member = optional(number)<br> rate_period_seconds = optional(number)<br> rate_units = optional(string)<br> })<br> memory = object({<br> io_above_percent = optional(number)<br> io_enabled = optional(bool)<br> io_over_period = optional(string)<br> rate_increase_percent = optional(number)<br> rate_limit_mb_per_member = optional(number)<br> rate_period_seconds = optional(number)<br> rate_units = optional(string)<br> })<br> })</pre> | <pre>{<br> "cpu": {},<br> "disk": {},<br> "memory": {}<br>}</pre> | no |
69+
| <a name="input_backup_encryption_key_crn"></a> [backup\_encryption\_key\_crn](#input\_backup\_encryption\_key\_crn) | (Optional) The CRN of a key protect key, that you want to use for encrypting disk that holds deployment backups. If null, will use 'key\_protect\_key\_crn' as encryption key. If 'key\_protect\_key\_crn' is also null database is encrypted by using randomly generated keys. | `string` | `null` | no |
70+
| <a name="input_cbr_rules"></a> [cbr\_rules](#input\_cbr\_rules) | (Optional, list) List of CBR rules to create, if operations is not set it will default to api-type:data-plane | <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> tags = optional(list(object({<br> name = string<br> value = string<br> })))<br> operations = optional(list(object({<br> api_types = list(object({<br> api_type_id = string<br> }))<br> })))<br> }))</pre> | `[]` | no |
71+
| <a name="input_configuration"></a> [configuration](#input\_configuration) | (Optional, Json String) Database Configuration in JSON format. | <pre>object({<br> max_connections = optional(number)<br> max_prepared_transactions = optional(number)<br> deadlock_timeout = optional(number)<br> effective_io_concurrency = optional(number)<br> max_replication_slots = optional(number)<br> max_wal_senders = optional(number)<br> shared_buffers = optional(number)<br> synchronous_commit = optional(string)<br> wal_level = optional(string)<br> archive_timeout = optional(number)<br> log_min_duration_statement = optional(number)<br> })</pre> | `null` | no |
72+
| <a name="input_key_protect_key_crn"></a> [key\_protect\_key\_crn](#input\_key\_protect\_key\_crn) | (Optional) The root key CRN of a Key Management Service like Key Protect or Hyper Protect Crypto Service (HPCS) that you want to use for disk encryption. If `null`, database is encrypted by using randomly generated keys. See https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-key-protect&interface=ui#key-byok for current list of supported regions for BYOK | `string` | `null` | no |
73+
| <a name="input_member_cpu_count"></a> [member\_cpu\_count](#input\_member\_cpu\_count) | CPU allocation required for postgresql database | `string` | `"3"` | no |
74+
| <a name="input_member_disk_mb"></a> [member\_disk\_mb](#input\_member\_disk\_mb) | Disk allocation required for postgresql database | `string` | `"5120"` | no |
75+
| <a name="input_member_memory_mb"></a> [member\_memory\_mb](#input\_member\_memory\_mb) | Memory allocation required for postgresql database | `string` | `"1024"` | no |
76+
| <a name="input_members"></a> [members](#input\_members) | Number of members | `number` | `3` | no |
77+
| <a name="input_name"></a> [name](#input\_name) | Name of the Postgresql instance | `string` | n/a | yes |
78+
| <a name="input_pg_version"></a> [pg\_version](#input\_pg\_version) | Version of the postgresql instance | `string` | `null` | no |
79+
| <a name="input_plan_validation"></a> [plan\_validation](#input\_plan\_validation) | Enable or disable validating the database parameters for postgres during the plan phase | `bool` | `true` | no |
80+
| <a name="input_region"></a> [region](#input\_region) | The region postgresql is to be created on. The region must support BYOK if key\_protect\_key\_crn is used | `string` | `"us-south"` | no |
81+
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The resource group ID where the postgresql will be created | `string` | n/a | yes |
82+
| <a name="input_resource_tags"></a> [resource\_tags](#input\_resource\_tags) | Optional list of tags to be added to created resources | `list(string)` | `[]` | no |
83+
| <a name="input_service_endpoints"></a> [service\_endpoints](#input\_service\_endpoints) | Sets the endpoint of the Postgresql instance, valid values are 'public', 'private', or 'public-and-private' | `string` | `"private"` | no |
15484

15585
## Outputs
15686

157-
No outputs.
87+
| Name | Description |
88+
|------|-------------|
89+
| <a name="output_id"></a> [id](#output\_id) | Postgresl instance id |
90+
| <a name="output_version"></a> [version](#output\_version) | Postgresql instance version |
15891
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
15992
<!-- BEGIN CONTRIBUTING HOOK -->
16093

examples/autoscale/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Autoscale example
2+
3+
An end-to-end example that uses the module's default variable values. This example uses the IBM Cloud terraform provider to:
4+
5+
- Create a new resource group if one is not passed in.
6+
- Create a new ICD Postgresql database instance with auto-scaling (automatically increase resources) enabled..

examples/autoscale/main.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
##############################################################################
2+
# Resource Group
3+
##############################################################################
4+
5+
module "resource_group" {
6+
source = "git::https://github.com/terraform-ibm-modules/terraform-ibm-resource-group.git?ref=v1.0.5"
7+
# if an existing resource group is not set (null) create a new one using prefix
8+
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
9+
existing_resource_group_name = var.resource_group
10+
}
11+
12+
##############################################################################
13+
# ICD postgresql database
14+
##############################################################################
15+
16+
module "postgresql_db" {
17+
source = "../.."
18+
resource_group_id = module.resource_group.resource_group_id
19+
name = "${var.prefix}-postgres"
20+
region = var.region
21+
resource_tags = var.resource_tags
22+
member_memory_mb = var.member_memory_mb
23+
member_disk_mb = var.member_disk_mb
24+
member_cpu_count = var.member_cpu_count
25+
auto_scaling = var.auto_scaling
26+
}

examples/autoscale/outputs.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
##############################################################################
2+
# Outputs
3+
##############################################################################
4+
output "id" {
5+
description = "Postgresql instance id"
6+
value = module.postgresql_db.id
7+
}
8+
9+
output "version" {
10+
description = "Postgresql instance version"
11+
value = module.postgresql_db.version
12+
}

0 commit comments

Comments
 (0)