Skip to content
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

Exporter: fix generation of names for databricks_library resources #2832

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

alexott
Copy link
Contributor

@alexott alexott commented Oct 23, 2023

Changes

Internally, the exporter uses the following resource ID for databricks_library: <cluster_id>/<type>:coordinate (i.e., 0426-122546-8xi8q5o3/pypi:chispa).

When generating the final name of the resource, this name is normalized and checked if it's starting with a number, as Terraform doesn't allow identifiers to start with a number. If the final name starts with a number, then the artificial final name is generated consisting in the form of r<first 12 digits of MD5 of the original name>. This leads to the generation of duplicate resources in case if cluster ID starts with a number, and the same library was attached to the cluster multiple times, having only differences in the character case, like, Chispa and chispa (our clusters UI allows that).

This PR fixes this issue with the following changes:

  • add the lib_ prefix to the library name together with the first 8 numbers of the MD5 of the library ID
  • when generating resource name in the form of r<first 12 digits of MD5 of the original name>, calculate MD5 of the original string, not the lower-cased form

Please note that you will need to perform a full export because resource names has changed

Tests

  • make test run locally
  • tested manually
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • relevant acceptance tests are passing
  • using Go SDK

@alexott alexott requested review from a team as code owners October 23, 2023 11:46
@alexott alexott requested review from mgyucht and removed request for a team October 23, 2023 11:46
@alexott alexott force-pushed the exporter-library-names-fix branch from 6c2449e to 6d77c9f Compare October 23, 2023 11:52
Internally, exporter uses following resource ID for `databricks_library`:
`<cluster_id>/<type>:coordinate` (i.e., `0426-122546-8xi8q5o3/pypi:chispa`).

When generating final name of the resource, this name is normalized, and checked if it's
starting with a number, as Terraform doesn't allow identifiers to start with a number. If
the final name starts with number, then the artificial final name is generated consisting
in form of `r<first 12 digits of MD5 of the original name>`.  This leads to generation of
duplicate resources in case if cluster ID started with a number, and the same library was
attached to the cluster multiple times, having only difference in the character case,
like, `Chispa` and `chispa` (our clusters UI allows that).

This PR fixes this issue with following changes:

* add `lib_` prefix to the library name together with first 8 numbers of the MD5 of
  library ID
* when generating resource name in form of `r<first 12 digits of MD5 of the original name>`,
  calculate MD5 of the original string, not the lower-cased form
@alexott alexott force-pushed the exporter-library-names-fix branch from 6d77c9f to aefa94e Compare October 23, 2023 11:59
@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@cb4a6f0). Click here to learn what that means.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2832   +/-   ##
=========================================
  Coverage          ?   84.65%           
=========================================
  Files             ?      152           
  Lines             ?    13241           
  Branches          ?        0           
=========================================
  Hits              ?    11209           
  Misses            ?     1418           
  Partials          ?      614           
Files Coverage Δ
exporter/importables.go 71.71% <100.00%> (ø)
exporter/context.go 78.54% <66.66%> (ø)

@alexott alexott added the exporter TF configuration generator label Oct 25, 2023
@mgyucht mgyucht added this pull request to the merge queue Oct 25, 2023
Merged via the queue into master with commit 98f5174 Oct 25, 2023
7 checks passed
@mgyucht mgyucht deleted the exporter-library-names-fix branch October 25, 2023 12:23
@mgyucht mgyucht mentioned this pull request Oct 25, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exporter TF configuration generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants