-
Notifications
You must be signed in to change notification settings - Fork 0
fix: handles null COS instance CRN in locals to prevent parsing errors #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
/run pipeline |
|
/run pipeline |
Co-authored-by: Md Anam Raihan <md.anam.raihan17@gmail.com>
Co-authored-by: Md Anam Raihan <md.anam.raihan17@gmail.com>
|
/run pipeline |
iamar7
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
/run pipeline |
| activity_tracker_cos_target_bucket_name = try("${local.prefix}-${var.activity_tracker_cos_target_bucket_name}", var.activity_tracker_cos_target_bucket_name) | ||
|
|
||
| cos_instance_guid = element(split(":", var.existing_cos_instance_crn), length(split(":", var.existing_cos_instance_crn)) - 3) | ||
| cos_instance_guid = try(module.cos_crn_parser[0].service_instance, null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trying to track where this is used to ensure this doesn't cause an issue if it gets set to null. What I found is this:
local.cos_instance_guidis only used by theibm_iam_authorization_policy.policyresource in the DA- The count around the
ibm_iam_authorization_policy.policyresource is usinglocal.create_cross_account_auth_policyto determine if the auth policy should be created or not local.create_cross_account_auth_policyis only getting set to true if!var.skip_cos_kms_auth_policy && var.ibmcloud_kms_api_key != null. This is NOT correct for the COS auth policy. The COS auth policy needs to useibmcloud_cos_api_keyin its logic to determine if the cross account COS policy should be created, NOTibmcloud_kms_api_key.
I suggest to create two different locals: local.create_kms_cross_account_auth_policy and local.create_cos_cross_account_auth_policy
ocofaigh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ocofaigh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did a test with the following inputs:
TF_VAR_ibmcloud_api_key=XXX
TF_VAR_prefix=dd
TF_VAR_ibmcloud_kms_api_key=XXX
TF_VAR_provider_visibility=public
TF_VAR_enable_activity_tracker_event_routing_to_cos_bucket=false
TF_VAR_enable_activity_tracker_event_routing_to_cloud_logs=true
TF_VAR_existing_cloud_logs_instance_crn=crn:v1:bluemix:public:logs:us-east:a/abac0df06b644a9cabc6e44f55b3880e:6e931667-0f47-4c59-be2e-fa9b9f13f1a4::
And I got this error:
│ Error: Invalid template interpolation value
│
│ on main.tf line 213, in resource "ibm_iam_authorization_policy" "policy":
│ 213: description = "Allow the COS instance ${local.cos_instance_guid} to read the ${local.kms_service} key ${local.cos_kms_key_id} from the instance ${local.existing_kms_guid}"
│ ├────────────────
│ │ local.cos_instance_guid is null
│
│ The expression result is null. Cannot include a null value in a string template.
The count around the ibm_iam_authorization_policy.policy resource is not smart enough to take into consideration the use case where user is not passing a COS instance CRN
Description
Refactor to use the
crn-parsermodule forexisting_cos_instance_crnand handling the case when it is set to null.Release required?
x.x.X)x.X.x)X.x.x)Release notes content
Refactor to use the
crn-parsermodule forexisting_cos_instance_crnand handling the case when it is set to null.Run the pipeline
If the CI pipeline doesn't run when you create the PR, the PR requires a user with GitHub collaborators access to run the pipeline.
Run the CI pipeline when the PR is ready for review and you expect tests to pass. Add a comment to the PR with the following text:
Checklist for reviewers
For mergers