Skip to content
This repository was archived by the owner on Jul 17, 2023. It is now read-only.

Commit 5a43c99

Browse files
umarali-nagoorhkantare
authored andcommitted
Added resource_group & region to database datasource
1 parent 6edd516 commit 5a43c99

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

examples/service-credentials/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ module "db-service-credentials" {
2323
| Name | Description | Type | Default | Required |
2424
|----------------------|---------------------------------------------------|----------|---------|----------|
2525
| db_name | Existing db Name. | string | n/a | yes |
26+
| ibm_region | Provider level region. | string | n/a | no |
27+
| resource_group | Name of the resource group | string | n/a | no |
28+
| location | Location to which DB instance belongs to | string | n/a | no |
2629
| key_name | Name of key to be created. | string | n/a | yes |
2730
| key_role | Name of the user role | string | n/a | yes |
2831

examples/service-credentials/main.tf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
###########################################################
55

66
provider "ibm" {
7+
region = var.ibm_region
8+
}
79

10+
data "ibm_resource_group" "resource_group" {
11+
name = var.resource_group != null ? var.resource_group : "default"
812
}
913

1014
module "db-service-credentials" {
11-
source = "../../modules/service-credentials"
12-
db_name = var.db_name
13-
key_name = var.key_name
14-
key_role = var.key_role
15+
source = "../../modules/service-credentials"
16+
db_name = var.db_name
17+
location = var.location
18+
resource_group_id = data.ibm_resource_group.resource_group.id
19+
key_name = var.key_name
20+
key_role = var.key_role
1521
}

examples/service-credentials/variables.tf

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,31 @@
33
# Copyright 2021 IBM
44
###########################################################
55

6-
76
variable "db_name" {
87
type = string
98
description = "Name of an existing Database"
109
}
10+
11+
variable "ibm_region" {
12+
type = string
13+
description = "IBM Provider level region"
14+
default = "us-south"
15+
}
16+
variable "resource_group" {
17+
type = string
18+
description = "Name of the resource group, DB instance belongs to"
19+
default = null
20+
}
21+
22+
variable "location" {
23+
type = string
24+
description = "Location in which DB instance exists"
25+
default = null
26+
}
27+
1128
variable "key_name" {
1229
type = string
13-
description = "Nam eof the Key instance to be created"
30+
description = "Name of the Key instance to be created"
1431
}
1532
variable "key_role" {
1633
type = string

modules/service-credentials/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module "db-service-credentials" {
2323
| Name | Description | Type | Default | Required |
2424
|----------------------|---------------------------------------------------|----------|---------|----------|
2525
| db_name | Existing db Name. | string | n/a | yes |
26+
| resource_group_id | ID of the resource group | string | n/a | no |
27+
| location | Location to which DB instance belongs to | string | n/a | no |
2628
| key_name | Name of key to be created. | string | n/a | yes |
2729
| key_role | name of the user role | string | n/a | yes |
2830

modules/service-credentials/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# Create service credentials to existing DB instance
33
# Copyright 2021 IBM
44
###########################################################
5-
65
data "ibm_database" "db" {
7-
name = var.db_name
6+
name = var.db_name
7+
location = var.location != null ? var.location : null
8+
resource_group_id = var.resource_group_id != null ? var.resource_group_id : null
89
}
910

1011
resource "ibm_resource_key" "dbKey" {

modules/service-credentials/variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,25 @@ variable "db_name" {
88
type = string
99
description = "Name of an existing Database"
1010
}
11+
12+
variable "resource_group_id" {
13+
type = string
14+
description = "ID of the resource group, DB instance belongs to"
15+
default = null
16+
}
17+
18+
variable "location" {
19+
type = string
20+
description = "Location in which DB instance exists"
21+
default = null
22+
}
23+
1124
variable "key_name" {
1225
type = string
1326
description = "Nam eof the Key instance to be created"
1427
}
1528
variable "key_role" {
1629
type = string
1730
description = "Name of a user role. Valid roles are Writer, Reader, Manager, Administrator, Operator, Viewer, and Editor."
31+
default = "Viewer"
1832
}

0 commit comments

Comments
 (0)