Skip to content

Commit

Permalink
Merge branch 'master' into ins-vol-att
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ibm committed Nov 26, 2024
2 parents e827315 + 4854242 commit 5d0eb4a
Show file tree
Hide file tree
Showing 84 changed files with 4,156 additions and 335 deletions.
49 changes: 49 additions & 0 deletions examples/ibm-db2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This example shows how to create an instance of IBM Db2 SaaS on IBM Cloud and configure connectivity from a VSI

This sample provisions an IBM Db2 SaaS instance on IBM Cloud.

## Costs

This sample uses chargable services and **will** incur costs for the time the services are deployed. Execution of `terraform destroy` will result in deletion of all resources including the Db2 SaaS service instance. Billing for Db2 SaaS will terminate on the hour.


## Dependencies

- User has IAM permissions to create and configure an IBM Db2 SaaS for IBM Cloud Instance in the resource group specified.

## Configuration

The terraform template requires you to provide values for the terraform variables.
Copy the file `variables.tfvars.example` as `variables.tfvars`. Provide appropriate values to the variables within the file.

The following variables need to be set in the `terraform.tfvars` file before use:

* `ibmcloud_api_key` - An API key for IBM Cloud services. If you don't have one already, go to https://cloud.ibm.com/iam/#/apikeys and create a new key.
* `region` - IBM Cloud region where your Db2 SaaS will be created.
* `resource_group` - Resource group within which Db2 SaaS will be created.


The example is deployed in the us-south region. The `region` parameter in main.tf must be set to the same region as the Db2 SaaS instance will be deployed in as defined by the `location` parameter on the ibm_db2 resource.

## Outputs

The composed connection string of Db2 SaaS Instance CRN. `crn:v1:bluemix:public:dashdb-for-transactions:us-south:a/60970f92286548d8a64cbb45bce39bc1:deae06ff-3966-4534-bfa0-4b42281e7cef::`


## Running the configuration
1. Initialize the terraform project to download the terraform providers and modules
```bash
$ terraform init
```
2. Perform terraform plan with the variables. Run `terraform plan` to see the changes that will be applied to your account after you make any change to the terraform code.
```bash
$ terraform plan -var-file=./variables.tfvars
```

3. Perform terraform apply with the variables. Run `terraform apply` to apply the changes to the IBM Cloud after that will be applied to your account after you make any change to the terraform code.

```bash
$ terraform apply -var-file=./variables.tfvars
```

Run `terraform destroy` to clean up and destroy all the resources created for the toolchain.
38 changes: 38 additions & 0 deletions examples/ibm-db2/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
data "ibm_resource_group" "group" {
name = var.resource_group
}

//Db2 SaaS Instance Creation
resource "ibm_db2" "db2_instance" {
name = "demo-db2"
service = "dashdb-for-transactions"
plan = "performance"
location = var.region
resource_group_id = data.ibm_resource_group.group.id
service_endpoints = "public-and-private"
instance_type = "bx2.4x16"
high_availability = "yes"
backup_location = "us"

parameters_json = <<EOF
{
"disk_encryption_instance_crn": "none",
"disk_encryption_key_crn": "none",
"oracle_compatibility": "no"
}
EOF

timeouts {
create = "720m"
update = "60m"
delete = "30m"
}
}

# //DataSource reading existing instance
# data "ibm_db2" "db2_instance" {
# name = "demo-db2"
# resource_group_id = data.ibm_resource_group.group.id
# location = var.region
# service = "dashdb-for-transactions"
# }
5 changes: 5 additions & 0 deletions examples/ibm-db2/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
region = var.region
}
16 changes: 16 additions & 0 deletions examples/ibm-db2/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
variable "ibmcloud_api_key" {
description = "Enter your IBM Cloud API Key, you can get your IBM Cloud API key using: https://cloud.ibm.com/iam#/apikeys"
type = string
}

variable "region" {
type = string
description = "IBM Cloud region where your IBM Db2 SaaS will be created"
default = "us-south"
}

variable "resource_group" {
type = string
description = "Resource group within which IBM Db2 SaaS will be created"
default = "Default"
}
3 changes: 3 additions & 0 deletions examples/ibm-db2/variables.tfvars.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ibmcloud_api_key = "<ibm-cloud-api-key>"
region = "<ibm-cloud-region>"
resource_group = "<ibm-cloud-resource-group>"
10 changes: 10 additions & 0 deletions examples/ibm-db2/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.2.0, < 2.0.0"

required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = ">= 1.71.3-beta1"
}
}
}
108 changes: 107 additions & 1 deletion examples/ibm-event-streams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The following `"ibm_resource_instance"` arguments are required:

- `resource_group_id`: The ID of the resource group in which the instance will be provisioned. For more information about resource groups, see [Managing resource groups](https://cloud.ibm.com/docs/account?topic=account-rgs).

The `parameters` argument is optional and provides additional provision or update options. Supported parameters are:
The `parameters/parameters_json` argument is optional and provides additional provision or update options. Supported parameters are:

- `throughput`: One of `"150"` (the default), `"300"`, `"450"`. The maximum capacity in MB/s for producing or consuming messages. For more information see [Scaling Enterprise plan capacity](https://cloud.ibm.com/docs/EventStreams?topic=EventStreams-ES_scaling_capacity). *Note:* See [Scaling combinations](https://cloud.ibm.com/docs/EventStreams?topic=EventStreams-ES_scaling_capacity#ES_scaling_combinations) for allowed combinations of `throughput` and `storage_size`.
- Example: `throughput = "300"`
Expand All @@ -38,6 +38,41 @@ The `parameters` argument is optional and provides additional provision or updat
- `kms_key_crn`: The CRN (as a string) of a customer-managed root key provisioned with an IBM Cloud Key Protect or Hyper Protect Crypto Service. If provided, this key is used to encrypt all data at rest. For more information on customer-managed encryption, see [Managing encryption in Event Streams](https://cloud.ibm.com/docs/EventStreams?topic=EventStreams-managing_encryption).
- Example: `kms_key_crn = "crn:v1:prod:public:kms:us-south:a/6db1b0d0b5c54ee5c201552547febcd8:20adf7eb-e095-4dec-08cf-0b7d81e32db6:key:3fa9d921-d3b6-3516-a1ec-d54e27e7638b"`

- `mirroring`: To enable mirroring in the cluster using `parameters_json`. For enterprise instance only. If defined `source_crn` (source cluster CRN as a string), `source_alias` (alias for source cluster as a string), `target_alias` (alias for target cluster as a string) are required. `options` are optional.
- Example:

```terraform
parameters_json = jsonencode(
{
mirroring = {
source_crn = data.ibm_resource_instance.es_instance_source.id
source_alias = "source-alias"
target_alias = "target-alias"
options = {
topic_name_transform = {
type = "rename"
rename = {
add_prefix = "add_prefix"
add_suffix = "add_suffix"
remove_prefix = "remove_prefix"
remove_suffix = "remove_suffix"
}
}
group_id_transform = {
type = "rename"
rename = {
add_prefix = "add_prefix"
add_suffix = "add_suffix"
remove_prefix = "remove_prefix"
remove_suffix = "remove_suffix"
}
}
}
}
}
)
```

The `timeouts` argument is used to specify how long the IBM Cloud terraform provider will wait for the provision, update, or deprovision of the service instance. Values of 15 minutes are sufficient for standard and lite plans. For enterprise plans:
- Use "3h" for create. Add an additional 1 hour for each level of non-default throughput, and an additional 30 minutes for each level of non-default storage size. For example with `throughput = "300"` (one level over default) and `storage_size = "8192"` (three levels over default), use 3 hours + 1 * 1 hour + 3 * 30 minutes = 5.5 hours.
- Use "1h" for update. If increasing the throughput or storage size, add an additional 1 hour for each level of non-default throughput, and an additional 30 minutes for each level of non-default storage size.
Expand Down Expand Up @@ -222,6 +257,77 @@ resource "kafka_consumer_app" "es_kafka_app" {
topics = [data.ibm_event_streams_topic.es_topic_7.name]
}
```
#### Scenario 8: Create a target Event Streams service instance with mirroring enabled and its mirroring config
```terraform
data "ibm_resource_instance" "es_instance_source" {
name = "terraform-integration-source"
resource_group_id = data.ibm_resource_group.group.id
}
# setup s2s at service level for mirroring to work
resource "ibm_iam_authorization_policy" "service-policy" {
source_service_name = "messagehub"
target_service_name = "messagehub"
roles = ["Reader"]
description = "test mirroring setup via terraform"
}
resource "ibm_resource_instance" "es_instance_target" {
name = "terraform-integration-target"
service = "messagehub"
plan = "enterprise-3nodes-2tb"
location = "us-south"
resource_group_id = data.ibm_resource_group.group.id
parameters_json = jsonencode(
{
mirroring = {
source_crn = data.ibm_resource_instance.es_instance_source.id
source_alias = "source-alias"
target_alias = "target-alias"
options = {
topic_name_transform = {
type = "rename"
rename = {
add_prefix = "add_prefix"
add_suffix = "add_suffix"
remove_prefix = "remove_prefix"
remove_suffix = "remove_suffix"
}
}
group_id_transform = {
type = "rename"
rename = {
add_prefix = "add_prefix"
add_suffix = "add_suffix"
remove_prefix = "remove_prefix"
remove_suffix = "remove_suffix"
}
}
}
}
}
)
timeouts {
create = "3h"
update = "1h"
delete = "15m"
}
}
# Configure a service-to-service binding between both instances to allow both instances to communicate.
resource "ibm_iam_authorization_policy" "instance_policy" {
source_service_name = "messagehub"
source_resource_instance_id = ibm_resource_instance.es_instance_target.guid
target_service_name = "messagehub"
target_resource_instance_id = data.ibm_resource_instance.es_instance_source.guid
roles = ["Reader"]
description = "test mirroring setup via terraform"
}
# Select some topics from the source cluster to mirror.
resource "ibm_event_streams_mirroring_config" "es_mirroring_config" {
resource_instance_id = ibm_resource_instance.es_instance_target.id
mirroring_topic_patterns = ["topicA", "topicB"]
}
```

## Dependencies

Expand Down
48 changes: 34 additions & 14 deletions examples/ibm-event-streams/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ resource "ibm_resource_instance" "es_instance_2" {
resource_group_id = data.ibm_resource_group.group.id

parameters = {
throughput = "300"
storage_size = "4096"
service-endpoints = "private"
private_ip_allowlist = "[10.0.0.0/32,10.0.0.1/32]"
metrics = "[topic,consumers]"
throughput = "300"
storage_size = "4096"
service-endpoints = "private"
private_ip_allowlist = "[10.0.0.0/32,10.0.0.1/32]"
metrics = "[topic,consumers]"
}

timeouts {
create = "330m" # 5.5h
update = "210m" # 3.5h
delete = "1h"
create = "330m" # 5.5h
update = "210m" # 3.5h
delete = "1h"
}
}

Expand Down Expand Up @@ -74,8 +74,8 @@ data "ibm_resource_instance" "es_instance_4" {

resource "ibm_event_streams_schema" "es_schema" {
resource_instance_id = data.ibm_resource_instance.es_instance_4.id
schema_id = "tf_schema"
schema = <<SCHEMA
schema_id = "tf_schema"
schema = <<SCHEMA
{
"type": "record",
"name": "record_name",
Expand Down Expand Up @@ -107,10 +107,10 @@ data "ibm_resource_instance" "es_instance_source" {
}
# setup s2s at service level for mirroring to work
resource "ibm_iam_authorization_policy" "service-policy" {
source_service_name = "messagehub"
target_service_name = "messagehub"
roles = ["Reader"]
description = "test mirroring setup via terraform"
source_service_name = "messagehub"
target_service_name = "messagehub"
roles = ["Reader"]
description = "test mirroring setup via terraform"
}

resource "ibm_resource_instance" "es_instance_target" {
Expand All @@ -125,6 +125,26 @@ resource "ibm_resource_instance" "es_instance_target" {
source_crn = data.ibm_resource_instance.es_instance_source.id
source_alias = "source-alias"
target_alias = "target-alias"
options = {
topic_name_transform = {
type = "rename"
rename = {
add_prefix = "add_prefix"
add_suffix = "add_suffix"
remove_prefix = "remove_prefix"
remove_suffix = "remove_suffix"
}
}
group_id_transform = {
type = "rename"
rename = {
add_prefix = "add_prefix"
add_suffix = "add_suffix"
remove_prefix = "remove_prefix"
remove_suffix = "remove_suffix"
}
}
}
}
}
)
Expand Down
Loading

0 comments on commit 5d0eb4a

Please sign in to comment.