Skip to content

Commit a07cb0f

Browse files
authored
chore: add missing auth policy from complete example (#275)
1 parent 8899dc0 commit a07cb0f

File tree

5 files changed

+38
-10
lines changed

5 files changed

+38
-10
lines changed

examples/complete/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This examples handles the provisioning of a new Secrets Manager instance.
99
|------|---------|
1010
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= v1.0.0 |
1111
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >=1.70.0 |
12+
| <a name="requirement_time"></a> [time](#requirement\_time) | 0.12.1 |
1213

1314
### Modules
1415

@@ -21,7 +22,10 @@ This examples handles the provisioning of a new Secrets Manager instance.
2122

2223
### Resources
2324

24-
No resources.
25+
| Name | Type |
26+
|------|------|
27+
| [ibm_iam_authorization_policy.en_policy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/iam_authorization_policy) | resource |
28+
| [time_sleep.wait_for_en_policy](https://registry.terraform.io/providers/hashicorp/time/0.12.1/docs/resources/sleep) | resource |
2529

2630
### Inputs
2731

examples/complete/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,26 @@ module "event_notification" {
3636
region = var.en_region
3737
}
3838

39+
resource "ibm_iam_authorization_policy" "en_policy" {
40+
source_service_name = "secrets-manager"
41+
roles = ["Key Manager"]
42+
target_service_name = "event-notifications"
43+
target_resource_instance_id = module.event_notification.guid
44+
description = "Allow the Secret manager Key Manager role access to event-notifications with guid ${module.event_notification.guid}."
45+
# Scope of policy now includes the key, so ensure to create new policy before
46+
# destroying old one to prevent any disruption to every day services.
47+
lifecycle {
48+
create_before_destroy = true
49+
}
50+
}
51+
52+
resource "time_sleep" "wait_for_en_policy" {
53+
depends_on = [ibm_iam_authorization_policy.en_policy]
54+
create_duration = "30s"
55+
}
56+
3957
module "secrets_manager" {
58+
depends_on = [time_sleep.wait_for_en_policy]
4059
source = "../.."
4160
resource_group_id = module.resource_group.resource_group_id
4261
region = var.region

examples/complete/version.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@ terraform {
55
source = "IBM-Cloud/ibm"
66
version = ">=1.70.0"
77
}
8+
time = {
9+
source = "hashicorp/time"
10+
version = "0.12.1"
11+
}
812
}
913
}

tests/other_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestRunBasicExample(t *testing.T) {
2727
func TestRunCompleteExample(t *testing.T) {
2828
t.Parallel()
2929

30-
options := setupOptions(t, "secrets-mgr")
30+
options := setupOptions(t, "secrets-mgr", false)
3131

3232
output, err := options.RunTestConsistency()
3333
assert.Nil(t, err, "This should not have errored")
@@ -57,8 +57,8 @@ func TestFSCloudInSchematics(t *testing.T) {
5757
{Name: "ibmcloud_api_key", Value: options.RequiredEnvironmentVars["TF_VAR_ibmcloud_api_key"], DataType: "string", Secure: true},
5858
{Name: "region", Value: validRegions[rand.Intn(len(validRegions))], DataType: "string"},
5959
{Name: "prefix", Value: options.Prefix, DataType: "string"},
60-
{Name: "existing_kms_instance_guid", Value: permanentResources["hpcs_east"], DataType: "string"},
61-
{Name: "kms_key_crn", Value: permanentResources["hpcs_east_root_key_crn"], DataType: "string"},
60+
{Name: "existing_kms_instance_guid", Value: permanentResources["hpcs_south"], DataType: "string"},
61+
{Name: "kms_key_crn", Value: permanentResources["hpcs_south_root_key_crn"], DataType: "string"},
6262
{Name: "sm_service_plan", Value: "trial", DataType: "string"},
6363
}
6464

tests/pr_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ func TestMain(m *testing.M) {
5353
os.Exit(m.Run())
5454
}
5555

56-
func setupOptions(t *testing.T, prefix string) *testhelper.TestOptions {
56+
func setupOptions(t *testing.T, prefix string, checkApplyResultForUpgrade bool) *testhelper.TestOptions {
5757
options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{
58-
Testing: t,
59-
TerraformDir: completeExampleTerraformDir,
60-
Prefix: prefix,
61-
Region: validRegions[rand.Intn(len(validRegions))],
58+
Testing: t,
59+
TerraformDir: completeExampleTerraformDir,
60+
Prefix: prefix,
61+
Region: validRegions[rand.Intn(len(validRegions))],
62+
CheckApplyResultForUpgrade: checkApplyResultForUpgrade,
6263
/*
6364
Comment out the 'ResourceGroup' input to force this tests to create a unique resource group. This is because
6465
there is a restriction with the Event Notification service, which allows only one Lite plan instance per resource group.
@@ -72,7 +73,7 @@ func setupOptions(t *testing.T, prefix string) *testhelper.TestOptions {
7273
func TestRunUpgradeExample(t *testing.T) {
7374
t.Parallel()
7475

75-
options := setupOptions(t, "secrets-mgr-upg")
76+
options := setupOptions(t, "secrets-mgr-upg", true)
7677

7778
output, err := options.RunTestUpgrade()
7879
if !options.UpgradeTestSkipped {

0 commit comments

Comments
 (0)