Skip to content

Commit cc1ef7f

Browse files
authoredFeb 7, 2025··
feat: The DA has been locked down to only support private only instances. So the existing_secrets_endpoint_type and allowed_network inputs have been removed. (#259)
1 parent 77597be commit cc1ef7f

File tree

12 files changed

+107
-137
lines changed

12 files changed

+107
-137
lines changed
 

‎ibm_catalog.json

+18-13
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,6 @@
153153
}
154154
]
155155
},
156-
{
157-
"key": "allowed_network",
158-
"options": [
159-
{
160-
"displayname": "Public and private",
161-
"value": "public-and-private"
162-
},
163-
{
164-
"displayname": "Private only",
165-
"value": "private-only"
166-
}
167-
]
168-
},
169156
{
170157
"key": "secret_manager_tags"
171158
},
@@ -217,6 +204,24 @@
217204
{
218205
"key": "skip_kms_iam_authorization_policy"
219206
},
207+
{
208+
"key": "enable_event_notification"
209+
},
210+
{
211+
"key": "existing_secrets_manager_crn"
212+
},
213+
{
214+
"key": "ibmcloud_kms_api_key"
215+
},
216+
{
217+
"key": "sm_en_email_list"
218+
},
219+
{
220+
"key": "sm_en_from_email"
221+
},
222+
{
223+
"key": "sm_en_reply_to_email"
224+
},
220225
{
221226
"key": "existing_secrets_manager_kms_key_crn"
222227
},

‎modules/fscloud/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ No resources.
5151
| <a name="input_enable_event_notification"></a> [enable\_event\_notification](#input\_enable\_event\_notification) | Set this to true to enable lifecycle notifications for your Secrets Manager instance by connecting an Event Notifications service. When setting this to true, a value must be passed for `existing_en_instance_crn` variable. | `bool` | `false` | no |
5252
| <a name="input_existing_en_instance_crn"></a> [existing\_en\_instance\_crn](#input\_existing\_en\_instance\_crn) | The CRN of the Event Notifications service to enable lifecycle notifications for your Secrets Manager instance. | `string` | `null` | no |
5353
| <a name="input_existing_kms_instance_guid"></a> [existing\_kms\_instance\_guid](#input\_existing\_kms\_instance\_guid) | The GUID of the Hyper Protect Crypto Services instance in which the key specified in `kms_key_crn` is coming from. | `string` | n/a | yes |
54+
| <a name="input_existing_sm_instance_crn"></a> [existing\_sm\_instance\_crn](#input\_existing\_sm\_instance\_crn) | The CRN of an existing Secrets Manager instance. If not supplied, a new instance is created. | `string` | `null` | no |
5455
| <a name="input_kms_key_crn"></a> [kms\_key\_crn](#input\_kms\_key\_crn) | The root key CRN of Hyper Protect Crypto Services (HPCS) that you want to use for encryption. | `string` | n/a | yes |
5556
| <a name="input_region"></a> [region](#input\_region) | The region to provision the Secrets Manager instance to. | `string` | n/a | yes |
5657
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | The ID of the resource group to provision the Secrets Manager instance to. | `string` | n/a | yes |
5758
| <a name="input_secrets"></a> [secrets](#input\_secrets) | Secret Manager secrets configurations. | <pre>list(object({<br/> secret_group_name = string<br/> secret_group_description = optional(string)<br/> existing_secret_group = optional(bool, false)<br/> secrets = optional(list(object({<br/> secret_name = string<br/> secret_description = optional(string)<br/> secret_type = optional(string)<br/> imported_cert_certificate = optional(string)<br/> imported_cert_private_key = optional(string)<br/> imported_cert_intermediate = optional(string)<br/> secret_username = optional(string)<br/> secret_labels = optional(list(string), [])<br/> secret_payload_password = optional(string, "")<br/> secret_auto_rotation = optional(bool, true)<br/> secret_auto_rotation_unit = optional(string, "day")<br/> secret_auto_rotation_interval = optional(number, 89)<br/> service_credentials_ttl = optional(string, "7776000") # 90 days<br/> service_credentials_source_service_crn = optional(string)<br/> service_credentials_source_service_role_crn = optional(string)<br/> })))<br/> }))</pre> | `[]` | no |
5859
| <a name="input_secrets_manager_name"></a> [secrets\_manager\_name](#input\_secrets\_manager\_name) | The name to give the Secrets Manager instance. | `string` | n/a | yes |
5960
| <a name="input_service_plan"></a> [service\_plan](#input\_service\_plan) | The Secrets Manager plan to provision. | `string` | `"standard"` | no |
6061
| <a name="input_skip_en_iam_authorization_policy"></a> [skip\_en\_iam\_authorization\_policy](#input\_skip\_en\_iam\_authorization\_policy) | Set to true to skip the creation of an IAM authorization policy that permits all Secrets Manager instances (scoped to the resource group) an 'Event Source Manager' role to the given Event Notifications instance passed in the `existing_en_instance_crn` input variable. In addition, no policy is created if `enable_event_notification` is set to false. | `bool` | `false` | no |
62+
| <a name="input_skip_kms_iam_authorization_policy"></a> [skip\_kms\_iam\_authorization\_policy](#input\_skip\_kms\_iam\_authorization\_policy) | Set to true to skip the creation of an IAM authorization policy that permits all Secrets Manager instances in the resource group to read the encryption key from the KMS instance. If set to false, pass in a value for the KMS instance in the `existing_kms_instance_crn` variable. If a value is specified for `ibmcloud_kms_api_key`, the policy is created in the KMS account. | `bool` | `false` | no |
6163
| <a name="input_sm_tags"></a> [sm\_tags](#input\_sm\_tags) | The list of resource tags that you want to associate with your Secrets Manager instance. | `list(string)` | `[]` | no |
6264

6365
### Outputs

‎modules/fscloud/main.tf

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
module "secrets_manager" {
2-
source = "../.."
3-
resource_group_id = var.resource_group_id
4-
region = var.region
5-
secrets_manager_name = var.secrets_manager_name #tfsec:ignore:general-secrets-no-plaintext-exposure
6-
sm_service_plan = var.service_plan
7-
sm_tags = var.sm_tags
8-
allowed_network = "private-only"
9-
endpoint_type = "private"
10-
kms_encryption_enabled = true
11-
existing_kms_instance_guid = var.existing_kms_instance_guid
12-
enable_event_notification = var.enable_event_notification
13-
existing_en_instance_crn = var.existing_en_instance_crn
14-
skip_en_iam_authorization_policy = var.skip_en_iam_authorization_policy
15-
kms_key_crn = var.kms_key_crn
16-
cbr_rules = var.cbr_rules
17-
secrets = var.secrets
2+
source = "../.."
3+
resource_group_id = var.resource_group_id
4+
region = var.region
5+
secrets_manager_name = var.secrets_manager_name #tfsec:ignore:general-secrets-no-plaintext-exposure
6+
existing_sm_instance_crn = var.existing_sm_instance_crn
7+
sm_service_plan = var.service_plan
8+
sm_tags = var.sm_tags
9+
allowed_network = "private-only"
10+
endpoint_type = "private"
11+
kms_encryption_enabled = true
12+
existing_kms_instance_guid = var.existing_kms_instance_guid
13+
enable_event_notification = var.enable_event_notification
14+
existing_en_instance_crn = var.existing_en_instance_crn
15+
skip_en_iam_authorization_policy = var.skip_en_iam_authorization_policy
16+
skip_kms_iam_authorization_policy = var.skip_kms_iam_authorization_policy
17+
kms_key_crn = var.kms_key_crn
18+
cbr_rules = var.cbr_rules
19+
secrets = var.secrets
1820
}

‎modules/fscloud/variables.tf

+12
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ variable "sm_tags" {
2929
default = []
3030
}
3131

32+
variable "existing_sm_instance_crn" {
33+
type = string
34+
description = "The CRN of an existing Secrets Manager instance. If not supplied, a new instance is created."
35+
default = null
36+
}
37+
38+
variable "skip_kms_iam_authorization_policy" {
39+
type = bool
40+
description = "Set to true to skip the creation of an IAM authorization policy that permits all Secrets Manager instances in the resource group to read the encryption key from the KMS instance. If set to false, pass in a value for the KMS instance in the `existing_kms_instance_crn` variable. If a value is specified for `ibmcloud_kms_api_key`, the policy is created in the KMS account."
41+
default = false
42+
}
43+
3244
##############################################################################
3345
# Key Management Service (KMS)
3446
##############################################################################

‎moved.tf

-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
moved {
2-
from = ibm_iam_authorization_policy.policy
3-
to = ibm_iam_authorization_policy.kms_policy
4-
}
5-
61
moved {
72
from = ibm_resource_instance.secrets_manager_instance
83
to = ibm_resource_instance.secrets_manager_instance[0]

‎solutions/standard/main.tf

+5-9
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,25 @@ locals {
9797
secrets_manager_guid = var.existing_secrets_manager_crn != null ? (length(local.parsed_existing_secrets_manager_crn) > 0 ? local.parsed_existing_secrets_manager_crn[7] : null) : module.secrets_manager.secrets_manager_guid
9898
secrets_manager_crn = var.existing_secrets_manager_crn != null ? var.existing_secrets_manager_crn : module.secrets_manager.secrets_manager_crn
9999
secrets_manager_region = var.existing_secrets_manager_crn != null ? (length(local.parsed_existing_secrets_manager_crn) > 0 ? local.parsed_existing_secrets_manager_crn[5] : null) : module.secrets_manager.secrets_manager_region
100-
sm_endpoint_type = var.existing_secrets_manager_crn != null ? var.existing_secrets_endpoint_type : var.allowed_network == "private-only" ? "private" : "public"
101100
}
102101

103102
module "secrets_manager" {
104103
depends_on = [time_sleep.wait_for_authorization_policy]
105-
source = "../.."
104+
source = "../../modules/fscloud"
106105
existing_sm_instance_crn = var.existing_secrets_manager_crn
107106
resource_group_id = var.existing_secrets_manager_crn == null ? module.resource_group[0].resource_group_id : data.ibm_resource_instance.existing_sm[0].resource_group_id
108107
region = var.region
109108
secrets_manager_name = try("${local.prefix}-${var.secrets_manager_instance_name}", var.secrets_manager_instance_name)
110-
sm_service_plan = var.service_plan
111-
allowed_network = var.allowed_network
109+
service_plan = var.service_plan
112110
sm_tags = var.secret_manager_tags
113111
# kms dependency
114-
kms_encryption_enabled = true
115112
existing_kms_instance_guid = local.existing_kms_guid
116113
kms_key_crn = local.kms_key_crn
117114
skip_kms_iam_authorization_policy = var.skip_kms_iam_authorization_policy || local.create_cross_account_auth_policy
118115
# event notifications dependency
119116
enable_event_notification = var.enable_event_notification
120117
existing_en_instance_crn = var.existing_event_notification_instance_crn
121118
skip_en_iam_authorization_policy = var.skip_event_notification_iam_authorization_policy
122-
endpoint_type = local.sm_endpoint_type
123119
cbr_rules = var.cbr_rules
124120
}
125121

@@ -131,7 +127,7 @@ module "iam_secrets_engine" {
131127
region = local.secrets_manager_region
132128
iam_engine_name = try("${local.prefix}-${var.iam_engine_name}", var.iam_engine_name)
133129
secrets_manager_guid = local.secrets_manager_guid
134-
endpoint_type = local.sm_endpoint_type
130+
endpoint_type = "private"
135131
}
136132

137133
locals {
@@ -157,7 +153,7 @@ module "secrets_manager_public_cert_engine" {
157153
dns_config_name = var.dns_provider_name
158154
ca_config_name = var.ca_name
159155
acme_letsencrypt_private_key = var.acme_letsencrypt_private_key
160-
service_endpoints = local.sm_endpoint_type
156+
service_endpoints = "private"
161157
}
162158

163159

@@ -173,7 +169,7 @@ module "private_secret_engine" {
173169
root_ca_max_ttl = var.root_ca_max_ttl
174170
intermediate_ca_name = var.intermediate_ca_name
175171
certificate_template_name = var.certificate_template_name
176-
endpoint_type = local.sm_endpoint_type
172+
endpoint_type = "private"
177173
}
178174

179175
data "ibm_resource_instance" "existing_sm" {

‎solutions/standard/moved.tf

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
moved {
2+
from = module.secrets_manager.ibm_resource_instance.secrets_manager_instance
3+
to = module.secrets_manager.module.secrets_manager.ibm_resource_instance.secrets_manager_instance
4+
}
5+
6+
moved {
7+
from = module.secrets_manager.ibm_iam_authorization_policy.kms_policy
8+
to = module.secrets_manager.module.secrets_manager.ibm_iam_authorization_policy.kms_policy
9+
}
10+
11+
moved {
12+
from = module.secrets_manager.time_sleep.wait_for_authorization_policy
13+
to = module.secrets_manager.module.secrets_manager.time_sleep.wait_for_authorization_policy
14+
}

‎solutions/standard/variables.tf

-20
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,6 @@ variable "existing_secrets_manager_crn" {
5858
default = null
5959
}
6060

61-
variable "existing_secrets_endpoint_type" {
62-
type = string
63-
description = "The endpoint type to use if existing_secrets_manager_crn is specified. Possible values: public, private."
64-
default = "private"
65-
validation {
66-
condition = contains(["public", "private"], var.existing_secrets_endpoint_type)
67-
error_message = "Only \"public\" and \"private\" are allowed values for 'existing_secrets_endpoint_type'."
68-
}
69-
}
70-
7161
variable "service_plan" {
7262
type = string
7363
description = "The pricing plan to use when provisioning a Secrets Manager instance. Possible values: `standard`, `trial`. Applies only if `provision_sm_instance` is set to `true`."
@@ -78,16 +68,6 @@ variable "service_plan" {
7868
}
7969
}
8070

81-
variable "allowed_network" {
82-
type = string
83-
description = "The types of service endpoints to set on the Secrets Manager instance. Possible values: `private-only`, `public-and-private`."
84-
default = "private-only"
85-
validation {
86-
condition = contains(["private-only", "public-and-private"], var.allowed_network)
87-
error_message = "The specified allowed_network is not a valid selection."
88-
}
89-
}
90-
9171
variable "secret_manager_tags" {
9272
type = list(any)
9373
description = "The list of resource tags you want to associate with your Secrets Manager instance."

‎tests/existing-resources/main.tf

-13
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,3 @@ module "key_protect" {
4747
}
4848
]
4949
}
50-
51-
##############################################################################
52-
# Secrets Manager
53-
##############################################################################
54-
55-
module "secrets_manager" {
56-
source = "../.."
57-
resource_group_id = module.resource_group.resource_group_id
58-
region = var.region
59-
secrets_manager_name = "${var.prefix}-secrets-manager" #tfsec:ignore:general-secrets-no-plaintext-exposure
60-
sm_service_plan = "trial"
61-
sm_tags = var.resource_tags
62-
}

‎tests/existing-resources/outputs.tf

-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,3 @@ output "event_notification_instance_crn" {
2222
value = module.event_notifications.crn
2323
description = "CRN of created event notification"
2424
}
25-
26-
output "secrets_manager_instance_crn" {
27-
value = module.secrets_manager.secrets_manager_crn
28-
description = "CRN of created secret manager instance"
29-
}

‎tests/pr_test.go

+37-55
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,14 @@ func TestRunDASolutionSchematics(t *testing.T) {
9393

9494
// Set up a schematics test
9595
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
96-
Testing: t,
97-
TarIncludePatterns: []string{"*.tf", fmt.Sprintf("%s/*.tf", solutionsTerraformDir), "modules/secrets/*.tf"},
96+
Testing: t,
97+
TarIncludePatterns: []string{
98+
"*.tf",
99+
fmt.Sprintf("%s/*.tf", solutionsTerraformDir),
100+
fmt.Sprintf("%s/*.tf", fscloudExampleTerraformDir),
101+
fmt.Sprintf("%s/*.tf", "modules/secrets"),
102+
fmt.Sprintf("%s/*.tf", "modules/fscloud"),
103+
},
98104
TemplateFolder: solutionsTerraformDir,
99105
ResourceGroup: resourceGroup,
100106
Prefix: "sm-da",
@@ -182,65 +188,41 @@ func TestRunExistingResourcesInstances(t *testing.T) {
182188
assert.True(t, existErr == nil, "Init and Apply of temp existing resource failed")
183189
} else {
184190

185-
// ------------------------------------------------------------------------------------
186-
// Test passing an existing SM, RG, EN
187-
// ------------------------------------------------------------------------------------
188-
189-
options := testhelper.TestOptionsDefault(&testhelper.TestOptions{
190-
Testing: t,
191-
TerraformDir: solutionsTerraformDir,
192-
// Do not hard fail the test if the implicit destroy steps fail to allow a full destroy of resource to occur
193-
ImplicitRequired: false,
194-
TerraformVars: map[string]interface{}{
195-
"ibmcloud_api_key": os.Getenv("TF_VAR_ibmcloud_api_key"),
196-
"region": region,
197-
"resource_group_name": terraform.Output(t, existingTerraformOptions, "resource_group_name"),
198-
"use_existing_resource_group": true,
199-
"enable_event_notification": true,
200-
"existing_event_notification_instance_crn": terraform.Output(t, existingTerraformOptions, "event_notification_instance_crn"),
201-
"existing_secrets_manager_crn": terraform.Output(t, existingTerraformOptions, "secrets_manager_instance_crn"),
202-
"iam_engine_enabled": true,
203-
"private_engine_enabled": true,
204-
"existing_secrets_endpoint_type": "public",
205-
"provider_visibility": "public",
206-
},
207-
})
208-
209-
output, err := options.RunTestConsistency()
210-
assert.Nil(t, err, "This should not have errored")
211-
assert.NotNil(t, output, "Expected some output")
212-
213191
// ------------------------------------------------------------------------------------
214192
// Test passing existing RG, EN, and KMS key
215193
// ------------------------------------------------------------------------------------
216-
217-
options2 := testhelper.TestOptionsDefault(&testhelper.TestOptions{
218-
Testing: t,
219-
TerraformDir: solutionsTerraformDir,
220-
// Do not hard fail the test if the implicit destroy steps fail to allow a full destroy of resource to occur
221-
ImplicitRequired: false,
222-
TerraformVars: map[string]interface{}{
223-
"ibmcloud_api_key": os.Getenv("TF_VAR_ibmcloud_api_key"),
224-
"region": region,
225-
"resource_group_name": terraform.Output(t, existingTerraformOptions, "resource_group_name"),
226-
"use_existing_resource_group": true,
227-
"enable_event_notification": true,
228-
"existing_event_notification_instance_crn": terraform.Output(t, existingTerraformOptions, "event_notification_instance_crn"),
229-
"existing_secrets_manager_kms_key_crn": terraform.Output(t, existingTerraformOptions, "secrets_manager_kms_key_crn"),
230-
"existing_kms_instance_crn": terraform.Output(t, existingTerraformOptions, "secrets_manager_kms_instance_crn"),
231-
"service_plan": "trial",
232-
"iam_engine_enabled": true,
233-
"private_engine_enabled": true,
234-
"existing_secrets_endpoint_type": "public",
235-
"provider_visibility": "public",
236-
"allowed_network": "public-and-private",
194+
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{
195+
Testing: t,
196+
TarIncludePatterns: []string{
197+
"*.tf",
198+
fmt.Sprintf("%s/*.tf", solutionsTerraformDir),
199+
fmt.Sprintf("%s/*.tf", "modules/secrets"),
200+
fmt.Sprintf("%s/*.tf", "modules/fscloud"),
237201
},
202+
TemplateFolder: solutionsTerraformDir,
203+
ResourceGroup: resourceGroup,
204+
Tags: []string{"test-schematic"},
205+
DeleteWorkspaceOnFail: false,
206+
WaitJobCompleteMinutes: 60,
238207
})
239208

240-
output2, err := options2.RunTestConsistency()
241-
assert.Nil(t, err, "This should not have errored")
242-
assert.NotNil(t, output2, "Expected some output")
243-
209+
options.TerraformVars = []testschematic.TestSchematicTerraformVar{
210+
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
211+
{Name: "region", Value: validRegions[rand.Intn(len(validRegions))], DataType: "string"},
212+
{Name: "resource_group_name", Value: terraform.Output(t, existingTerraformOptions, "resource_group_name"), DataType: "string"},
213+
{Name: "use_existing_resource_group", Value: true, DataType: "bool"},
214+
{Name: "enable_event_notification", Value: true, DataType: "bool"},
215+
{Name: "existing_event_notification_instance_crn", Value: terraform.Output(t, existingTerraformOptions, "event_notification_instance_crn"), DataType: "string"},
216+
{Name: "existing_secrets_manager_kms_key_crn", Value: permanentResources["hpcs_south_root_key_crn"], DataType: "string"},
217+
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
218+
{Name: "service_plan", Value: "trial", DataType: "string"},
219+
{Name: "iam_engine_enabled", Value: true, DataType: "bool"},
220+
{Name: "private_engine_enabled", Value: true, DataType: "bool"},
221+
{Name: "existing_kms_instance_crn", Value: permanentResources["hpcs_south_crn"], DataType: "string"},
222+
}
223+
224+
err := options.RunSchematicTest()
225+
assert.NoError(t, err, "Schematic Test had unexpected error")
244226
}
245227

246228
// Check if "DO_NOT_DESTROY_ON_FAILURE" is set

0 commit comments

Comments
 (0)
Please sign in to comment.