-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Is your feature request related to a problem? Please describe.
When using large lists of licenses for allowed_licenses
or banned_licenses
in an xray_license_policy
resource, the amount of time required to read/write the resource is excessive and becomes unusable.
Using the Xray API directly does not appear to exhibit the same issue.
Describe the solution you'd like
Any solution that makes the execution times reasonable when using large lists of licenses (e.g. > 100).
Quote from #262 (comment):
Another possible approach is to add another attribute (says
allowed_licenses_json
) which is a string with all the licenses in JSON format.
Describe alternatives you've considered
I do not have any ideas for alternatives.
Additional context
To demonstrate the issue this request would resolve:
-
The following changes were made to commit 07c3ec9
diff --git a/pkg/xray/resource/resource_xray_license_policy_test.go b/pkg/xray/resource/resource_xray_license_policy_test.go index e4e63759..1d2c32a1 100644 --- a/pkg/xray/resource/resource_xray_license_policy_test.go +++ b/pkg/xray/resource/resource_xray_license_policy_test.go @@ -1,6 +1,7 @@ package xray_test import ( + "encoding/json" "fmt" "regexp" "testing" @@ -568,3 +569,91 @@ func TestAccLicensePolicy_MigrateSetToList(t *testing.T) { }, }) } + +var testDataLicenseLots = map[string]string{ + "resource_name": "", + "policy_name": "terraform-license-policy", + "policy_description": "policy created by xray acceptance tests", + "rule_name": "test-license-rule", + "license_list": largeLicenseList(10), + "mails_0": "[email protected]", + "mails_1": "[email protected]", + "allow_unknown": "true", + "multi_license_permissive": "false", + "block_release_bundle_distribution": "true", + "block_release_bundle_promotion": "true", + "fail_build": "true", + "notify_watch_recipients": "true", + "notify_deployer": "true", + "create_ticket_enabled": "false", + "custom_severity": "High", + "grace_period_days": "5", + "block_unscanned": "true", + "block_active": "true", + "allowedOrBanned": "banned_licenses", +} + +func TestAccLicensePolicy_createAllowedLicLots(t *testing.T) { + _, fqrn, resourceName := testutil.MkNames("policy-", "xray_license_policy") + testData := sdk.MergeMaps(testDataLicenseLots) + + testData["resource_name"] = resourceName + testData["policy_name"] = fmt.Sprintf("terraform-license-policy-3-%d", testutil.RandomInt()) + testData["rule_name"] = fmt.Sprintf("test-license-rule-3-%d", testutil.RandomInt()) + testData["multi_license_permissive"] = "true" + testData["allowedOrBanned"] = "allowed_licenses" + + resource.Test(t, resource.TestCase{ + CheckDestroy: acctest.VerifyDeleted(fqrn, "", acctest.CheckPolicy), + ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, + Steps: []resource.TestStep{ + { + Config: util.ExecuteTemplate(fqrn, licensePolicyTemplateLarge, testData), + }, + { + ResourceName: fqrn, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func largeLicenseList(number_of_licenses int) string { + var largeLicenseList = make([]string, number_of_licenses) + for i := 0; i < number_of_licenses; i++ { + largeLicenseList[i] = fmt.Sprintf("example-license-%d", i) + } + largeLicenseListString, _ := json.Marshal(largeLicenseList) + return string(largeLicenseListString) +} + +const licensePolicyTemplateLarge = `resource "xray_license_policy" "{{ .resource_name }}" { + name = "{{ .policy_name }}" + description = "{{ .policy_description }}" + type = "license" + rule { + name = "{{ .rule_name }}" + priority = 1 + criteria { + {{ .allowedOrBanned }} = {{ .license_list }} + allow_unknown = {{ .allow_unknown }} + multi_license_permissive = {{ .multi_license_permissive }} + } + actions { + mails = ["{{ .mails_0 }}", "{{ .mails_1 }}"] + block_download { + unscanned = {{ .block_unscanned }} + active = {{ .block_active }} + } + block_release_bundle_distribution = {{ .block_release_bundle_distribution }} + block_release_bundle_promotion = {{ .block_release_bundle_promotion }} + fail_build = {{ .fail_build }} + notify_watch_recipients = {{ .notify_watch_recipients }} + notify_deployer = {{ .notify_deployer }} + create_ticket_enabled = {{ .create_ticket_enabled }} + custom_severity = "{{ .custom_severity }}" + build_failure_grace_period_in_days = {{ .grace_period_days }} + } + } +}`
-
Then run test as follows to get a rough estimate of time required:
TF_ACC=true go test -v pkg/xray/resource/resource_xray_license_policy_test.go -timeout=60m -parallel=4 -run "^TestAccLicensePolicy_createAllowedLicLots$"
-
Repeat previous step with progressively larger values for
largeLicenseList(X)
-
Plot resulting reported test execution times:
xychart-beta x-axis "# Licenses" [50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550] y-axis "Execution time (minutes)" line [0.24, 0.53, 1.35, 2.50, 5.22, 8.08, 11.58, 18.57, 24.32, 33.15, 47.14]