Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit ac3f588

Browse files
arya-girish-kArya Girish K
andauthored
fix: added sleep to wait for authorization policy of backup KMS encryption key (#294)
* feat: consistency with other ICD modules * Updated description * fix: Reverted changes --------- Co-authored-by: Arya Girish K <[email protected]>
1 parent fe1d840 commit ac3f588

File tree

9 files changed

+66
-26
lines changed

9 files changed

+66
-26
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ibmcloud_api_key": $VALIDATION_APIKEY,
3+
"region": "us-south",
4+
"resource_tags": $TAGS,
5+
"prefix": $PREFIX
6+
}

examples/backup-restore/main.tf

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

1313
data "ibm_database_backups" "backup_database" {
14-
deployment_id = var.etcd_db_crn
14+
deployment_id = var.existing_database_crn
1515
}
1616

1717
# New etcd db instance pointing to the backup instance
18-
module "restored_etcd_db" {
18+
module "restored_icd_etcd" {
1919
source = "../.."
2020
resource_group_id = module.resource_group.resource_group_id
2121
name = "${var.prefix}-etcd-restored"

examples/backup-restore/outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
# Outputs
33
##############################################################################
44

5-
output "restored_etcd_db_id" {
5+
output "restored_icd_etcd_id" {
66
description = "Restored etcd db instance id"
7-
value = module.restored_etcd_db.id
7+
value = module.restored_icd_etcd.id
88
}
99

10-
output "restored_etcd_db_version" {
10+
output "restored_icd_etcd_version" {
1111
description = "Restored etcd instance version"
12-
value = module.restored_etcd_db.version
12+
value = module.restored_icd_etcd.version
1313
}

examples/backup-restore/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ variable "access_tags" {
4040
default = []
4141
}
4242

43-
variable "etcd_db_crn" {
43+
variable "existing_database_crn" {
4444
type = string
4545
description = "The existing CRN of a etcd instance to fetch the latest backup crn."
4646
}

examples/basic/main.tf

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ module "resource_group" {
1414
# ICD etcd database
1515
##############################################################################
1616

17-
module "etcd_db" {
18-
source = "../.."
19-
resource_group_id = module.resource_group.resource_group_id
20-
name = "${var.prefix}-etcd"
21-
region = var.region
22-
etcd_version = var.etcd_version
23-
tags = var.resource_tags
24-
access_tags = var.access_tags
17+
module "database" {
18+
source = "../.."
19+
resource_group_id = module.resource_group.resource_group_id
20+
name = "${var.prefix}-data-store"
21+
region = var.region
22+
access_tags = var.access_tags
23+
service_endpoints = var.service_endpoints
24+
member_host_flavor = var.member_host_flavor
25+
tags = var.resource_tags
26+
etcd_version = var.etcd_version
27+
service_credential_names = {
28+
"etcd_admin" : "Administrator",
29+
"etcd_operator" : "Operator",
30+
"etcd_viewer" : "Viewer",
31+
"etcd_editor" : "Editor",
32+
}
2533
}

examples/basic/outputs.tf

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,35 @@
33
##############################################################################
44
output "id" {
55
description = "Etcd instance id"
6-
value = module.etcd_db.id
6+
value = module.database.id
7+
}
8+
output "etcd_crn" {
9+
description = "Etcd CRN"
10+
value = module.database.crn
711
}
812

913
output "version" {
1014
description = "Etcd instance version"
11-
value = module.etcd_db.version
15+
value = module.database.version
1216
}
1317

1418
output "adminuser" {
1519
description = "Database admin user name"
16-
value = module.etcd_db.adminuser
20+
value = module.database.adminuser
1721
}
1822

1923
output "hostname" {
2024
description = "Database connection hostname"
21-
value = module.etcd_db.hostname
25+
value = module.database.hostname
2226
}
2327

2428
output "port" {
2529
description = "Database connection port"
26-
value = module.etcd_db.port
30+
value = module.database.port
2731
}
2832

2933
output "certificate_base64" {
3034
description = "Database connection certificate"
31-
value = module.etcd_db.certificate_base64
35+
value = module.database.certificate_base64
3236
sensitive = true
3337
}

examples/basic/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,21 @@ variable "resource_tags" {
3939
description = "Optional list of tags to be added to created resources"
4040
default = []
4141
}
42+
43+
variable "service_endpoints" {
44+
type = string
45+
description = "The type of endpoint of the database instance. Possible values: `public`, `private`, `public-and-private`."
46+
default = "public"
47+
48+
validation {
49+
condition = can(regex("public|public-and-private|private", var.service_endpoints))
50+
error_message = "Valid values for service_endpoints are 'public', 'public-and-private', and 'private'"
51+
}
52+
}
53+
54+
variable "member_host_flavor" {
55+
type = string
56+
description = "The host flavor per member. [Learn more](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#host_flavor)."
57+
default = "multitenant"
58+
# Validation is done in the Terraform plan phase by the IBM provider, so no need to add extra validation here.
59+
}

main.tf

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ locals {
1414
validate_backup_key = !var.use_ibm_owned_encryption_key && var.backup_encryption_key_crn != null && (var.use_default_backup_encryption_key || var.use_same_kms_key_for_backups) ? tobool("When passing a value for 'backup_encryption_key_crn' you cannot set 'use_default_backup_encryption_key' to true or 'use_ibm_owned_encryption_key' to false.") : true
1515
# tflint-ignore: terraform_unused_declarations
1616
validate_backup_key_2 = !var.use_ibm_owned_encryption_key && var.backup_encryption_key_crn == null && !var.use_same_kms_key_for_backups ? tobool("When 'use_same_kms_key_for_backups' is set to false, a value needs to be passed for 'backup_encryption_key_crn'.") : true
17+
}
1718

19+
########################################################################################################################
20+
# Locals
21+
########################################################################################################################
22+
locals {
1823
# If no value passed for 'backup_encryption_key_crn' use the value of 'kms_key_crn' and perform validation of 'kms_key_crn' to check if region is supported by backup encryption key.
1924

2025
# If 'use_ibm_owned_encryption_key' is true or 'use_default_backup_encryption_key' is true, default to null.
@@ -115,9 +120,8 @@ resource "ibm_iam_authorization_policy" "policy" {
115120

116121
# workaround for https://github.com/IBM-Cloud/terraform-provider-ibm/issues/4478
117122
resource "time_sleep" "wait_for_authorization_policy" {
118-
count = local.create_kms_auth_policy
119-
depends_on = [ibm_iam_authorization_policy.policy]
120-
123+
count = local.create_kms_auth_policy
124+
depends_on = [ibm_iam_authorization_policy.policy]
121125
create_duration = "30s"
122126
}
123127

@@ -172,7 +176,7 @@ resource "time_sleep" "wait_for_backup_kms_authorization_policy" {
172176

173177
# Create etcd database
174178
resource "ibm_database" "etcd_db" {
175-
depends_on = [time_sleep.wait_for_authorization_policy]
179+
depends_on = [time_sleep.wait_for_authorization_policy, time_sleep.wait_for_backup_kms_authorization_policy]
176180
resource_group_id = var.resource_group_id
177181
name = var.name
178182
service = "databases-for-etcd"

tests/other_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestRunRestoredDBExample(t *testing.T) {
6464
ResourceGroup: resourceGroup,
6565
Region: fmt.Sprint(permanentResources["etcd_region"]),
6666
TerraformVars: map[string]interface{}{
67-
"etcd_db_crn": permanentResources["etcd_crn"],
67+
"existing_database_crn": permanentResources["etcd_crn"],
6868
},
6969
CloudInfoService: sharedInfoSvc,
7070
})

0 commit comments

Comments
 (0)