From 4348821cbbf0fd73fc7f1fe99bf667627f238a43 Mon Sep 17 00:00:00 2001 From: Carlos Gajardo Date: Thu, 8 Feb 2024 12:59:12 -0300 Subject: [PATCH] Require explicit resource_type in standards_resource(s)_scores --- go.mod | 1 + go.sum | 2 + ...rce_pagerduty_standards_resource_scores.go | 21 +- ...agerduty_standards_resource_scores_test.go | 4 +- ...ce_pagerduty_standards_resources_scores.go | 15 +- ...gerduty_standards_resources_scores_test.go | 4 +- .../LICENSE | 356 ++++++++++++++++++ .../helpers/validatordiag/diag.go | 84 +++++ .../helpers/validatordiag/doc.go | 5 + .../internal/schemavalidator/also_requires.go | 228 +++++++++++ .../schemavalidator/at_least_one_of.go | 224 +++++++++++ .../schemavalidator/conflicts_with.go | 228 +++++++++++ .../internal/schemavalidator/doc.go | 14 + .../schemavalidator/exactly_one_of.go | 248 ++++++++++++ .../stringvalidator/all.go | 57 +++ .../stringvalidator/also_requires.go | 26 ++ .../stringvalidator/any.go | 65 ++++ .../stringvalidator/any_with_all_warnings.go | 67 ++++ .../stringvalidator/at_least_one_of.go | 27 ++ .../stringvalidator/conflicts_with.go | 27 ++ .../stringvalidator/doc.go | 5 + .../stringvalidator/exactly_one_of.go | 28 ++ .../stringvalidator/length_at_least.go | 65 ++++ .../stringvalidator/length_at_most.go | 64 ++++ .../stringvalidator/length_between.go | 65 ++++ .../stringvalidator/none_of.go | 65 ++++ .../none_of_case_insensitive.go | 64 ++++ .../stringvalidator/one_of.go | 63 ++++ .../one_of_case_insensitive.go | 64 ++++ .../stringvalidator/regex_matches.go | 67 ++++ .../stringvalidator/utf8_length_at_least.go | 68 ++++ .../stringvalidator/utf8_length_at_most.go | 68 ++++ .../stringvalidator/utf8_length_between.go | 70 ++++ vendor/modules.txt | 5 + 34 files changed, 2441 insertions(+), 23 deletions(-) create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/LICENSE create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag/diag.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag/doc.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/also_requires.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/at_least_one_of.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/conflicts_with.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/doc.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/exactly_one_of.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/all.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/also_requires.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/any.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/any_with_all_warnings.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/at_least_one_of.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/conflicts_with.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/doc.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/exactly_one_of.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_at_least.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_at_most.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_between.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/none_of.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/none_of_case_insensitive.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/one_of.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/one_of_case_insensitive.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/regex_matches.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_at_least.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_at_most.go create mode 100644 vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_between.go diff --git a/go.mod b/go.mod index 6edeab651..040e9906e 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/hashicorp/terraform-exec v0.20.0 github.com/hashicorp/terraform-json v0.20.0 github.com/hashicorp/terraform-plugin-framework v1.5.0 + github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 github.com/hashicorp/terraform-plugin-go v0.20.0 github.com/hashicorp/terraform-plugin-mux v0.13.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.31.0 diff --git a/go.sum b/go.sum index 11ae6360c..2e39e5e26 100644 --- a/go.sum +++ b/go.sum @@ -75,6 +75,8 @@ github.com/hashicorp/terraform-json v0.20.0 h1:cJcvn4gIOTi0SD7pIy+xiofV1zFA3hza+ github.com/hashicorp/terraform-json v0.20.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk= github.com/hashicorp/terraform-plugin-framework v1.5.0 h1:8kcvqJs/x6QyOFSdeAyEgsenVOUeC/IyKpi2ul4fjTg= github.com/hashicorp/terraform-plugin-framework v1.5.0/go.mod h1:6waavirukIlFpVpthbGd2PUNYaFedB0RwW3MDzJ/rtc= +github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc= +github.com/hashicorp/terraform-plugin-framework-validators v0.12.0/go.mod h1:jfHGE/gzjxYz6XoUwi/aYiiKrJDeutQNUtGQXkaHklg= github.com/hashicorp/terraform-plugin-go v0.20.0 h1:oqvoUlL+2EUbKNsJbIt3zqqZ7wi6lzn4ufkn/UA51xQ= github.com/hashicorp/terraform-plugin-go v0.20.0/go.mod h1:Rr8LBdMlY53a3Z/HpP+ZU3/xCDqtKNCkeI9qOyT10QE= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= diff --git a/pagerdutyplugin/data_source_pagerduty_standards_resource_scores.go b/pagerdutyplugin/data_source_pagerduty_standards_resource_scores.go index eeddd6a0a..dcb70a59b 100644 --- a/pagerdutyplugin/data_source_pagerduty_standards_resource_scores.go +++ b/pagerdutyplugin/data_source_pagerduty_standards_resource_scores.go @@ -4,10 +4,12 @@ import ( "context" "github.com/PagerDuty/go-pagerduty" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -24,8 +26,13 @@ func (d *dataSourceStandardsResourceScores) Metadata(ctx context.Context, req da func (d *dataSourceStandardsResourceScores) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ - "id": schema.StringAttribute{Required: true}, - "resource_type": schema.StringAttribute{Required: true}, + "id": schema.StringAttribute{Required: true}, + "resource_type": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf("technical_services"), + }, + }, "score": schema.ObjectAttribute{ AttributeTypes: resourceScoresObjectType.AttrTypes, Computed: true, @@ -48,12 +55,8 @@ func (d *dataSourceStandardsResourceScores) Read(ctx context.Context, req dataso id := data.ID.ValueString() rt := data.ResourceType.ValueString() - rtUrl, ok := resourceStandardsToURLMapping[rt] - if !ok { - rtUrl = rt - } - scores, err := d.client.ListResourceStandardScores(ctx, id, rtUrl) + scores, err := d.client.ListResourceStandardScores(ctx, id, rt) if err != nil { resp.Diagnostics.Append(diag.NewErrorDiagnostic( "Error calling ListResourceStandardScores", @@ -124,7 +127,3 @@ func resourceStandardsToModel(standards []pagerduty.ResourceStandard) (types.Lis diags.Append(di...) return modelStandards, diags } - -var resourceStandardsToURLMapping = map[string]string{ - "technical_service": "technical_services", -} diff --git a/pagerdutyplugin/data_source_pagerduty_standards_resource_scores_test.go b/pagerdutyplugin/data_source_pagerduty_standards_resource_scores_test.go index 95b033584..7cb808889 100644 --- a/pagerdutyplugin/data_source_pagerduty_standards_resource_scores_test.go +++ b/pagerdutyplugin/data_source_pagerduty_standards_resource_scores_test.go @@ -79,10 +79,8 @@ resource "pagerduty_service" "example" { } } -data "pagerduty_standards" "all" {} - data "pagerduty_standards_resource_scores" "%s" { - resource_type = data.pagerduty_standards.all.standards.0.resource_type + resource_type = "technical_services" id = pagerduty_service.example.id }`, name) } diff --git a/pagerdutyplugin/data_source_pagerduty_standards_resources_scores.go b/pagerdutyplugin/data_source_pagerduty_standards_resources_scores.go index aad7e2294..8368c9fd4 100644 --- a/pagerdutyplugin/data_source_pagerduty_standards_resources_scores.go +++ b/pagerdutyplugin/data_source_pagerduty_standards_resources_scores.go @@ -4,10 +4,12 @@ import ( "context" "github.com/PagerDuty/go-pagerduty" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/datasource" "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -28,7 +30,12 @@ func (d *dataSourceStandardsResourcesScores) Schema(ctx context.Context, req dat ElementType: types.StringType, Required: true, }, - "resource_type": schema.StringAttribute{Required: true}, + "resource_type": schema.StringAttribute{ + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf("technical_services"), + }, + }, "resources": schema.ListAttribute{ ElementType: resourceStandardScoreObjectType, Computed: true, @@ -46,15 +53,11 @@ func (d *dataSourceStandardsResourcesScores) Read(ctx context.Context, req datas resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) rt := data.ResourceType.ValueString() - rtUrl, ok := resourceStandardsToURLMapping[rt] - if !ok { - rtUrl = rt - } ids := make([]string, 0) resp.Diagnostics.Append(data.IDs.ElementsAs(ctx, &ids, true)...) opt := pagerduty.ListMultiResourcesStandardScoresOptions{IDs: ids} - scores, err := d.client.ListMultiResourcesStandardScores(ctx, rtUrl, opt) + scores, err := d.client.ListMultiResourcesStandardScores(ctx, rt, opt) if err != nil { resp.Diagnostics.Append(diag.NewErrorDiagnostic( "Error calling ListResourceStandardScores", diff --git a/pagerdutyplugin/data_source_pagerduty_standards_resources_scores_test.go b/pagerdutyplugin/data_source_pagerduty_standards_resources_scores_test.go index 02c156441..4d5ae2459 100644 --- a/pagerdutyplugin/data_source_pagerduty_standards_resources_scores_test.go +++ b/pagerdutyplugin/data_source_pagerduty_standards_resources_scores_test.go @@ -85,10 +85,8 @@ resource "pagerduty_service" "example" { } } -data "pagerduty_standards" "all" {} - data "pagerduty_standards_resources_scores" "%s" { - resource_type = data.pagerduty_standards.all.standards.0.resource_type + resource_type = "technical_services" ids = [pagerduty_service.example.id] }`, name) } diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/LICENSE b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/LICENSE new file mode 100644 index 000000000..0f5a4e378 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/LICENSE @@ -0,0 +1,356 @@ +Copyright (c) 2022 HashiCorp, Inc. + +Mozilla Public License, version 2.0 + +1. Definitions + +1.1. “Contributor” + + means each individual or legal entity that creates, contributes to the + creation of, or owns Covered Software. + +1.2. “Contributor Version” + + means the combination of the Contributions of others (if any) used by a + Contributor and that particular Contributor’s Contribution. + +1.3. “Contribution” + + means Covered Software of a particular Contributor. + +1.4. “Covered Software” + + means Source Code Form to which the initial Contributor has attached the + notice in Exhibit A, the Executable Form of such Source Code Form, and + Modifications of such Source Code Form, in each case including portions + thereof. + +1.5. “Incompatible With Secondary Licenses” + means + + a. that the initial Contributor has attached the notice described in + Exhibit B to the Covered Software; or + + b. that the Covered Software was made available under the terms of version + 1.1 or earlier of the License, but not also under the terms of a + Secondary License. + +1.6. “Executable Form” + + means any form of the work other than Source Code Form. + +1.7. “Larger Work” + + means a work that combines Covered Software with other material, in a separate + file or files, that is not Covered Software. + +1.8. “License” + + means this document. + +1.9. “Licensable” + + means having the right to grant, to the maximum extent possible, whether at the + time of the initial grant or subsequently, any and all of the rights conveyed by + this License. + +1.10. “Modifications” + + means any of the following: + + a. any file in Source Code Form that results from an addition to, deletion + from, or modification of the contents of Covered Software; or + + b. any new file in Source Code Form that contains any Covered Software. + +1.11. “Patent Claims” of a Contributor + + means any patent claim(s), including without limitation, method, process, + and apparatus claims, in any patent Licensable by such Contributor that + would be infringed, but for the grant of the License, by the making, + using, selling, offering for sale, having made, import, or transfer of + either its Contributions or its Contributor Version. + +1.12. “Secondary License” + + means either the GNU General Public License, Version 2.0, the GNU Lesser + General Public License, Version 2.1, the GNU Affero General Public + License, Version 3.0, or any later versions of those licenses. + +1.13. “Source Code Form” + + means the form of the work preferred for making modifications. + +1.14. “You” (or “Your”) + + means an individual or a legal entity exercising rights under this + License. For legal entities, “You” includes any entity that controls, is + controlled by, or is under common control with You. For purposes of this + definition, “control” means (a) the power, direct or indirect, to cause + the direction or management of such entity, whether by contract or + otherwise, or (b) ownership of more than fifty percent (50%) of the + outstanding shares or beneficial ownership of such entity. + + +2. License Grants and Conditions + +2.1. Grants + + Each Contributor hereby grants You a world-wide, royalty-free, + non-exclusive license: + + a. under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or as + part of a Larger Work; and + + b. under Patent Claims of such Contributor to make, use, sell, offer for + sale, have made, import, and otherwise transfer either its Contributions + or its Contributor Version. + +2.2. Effective Date + + The licenses granted in Section 2.1 with respect to any Contribution become + effective for each Contribution on the date the Contributor first distributes + such Contribution. + +2.3. Limitations on Grant Scope + + The licenses granted in this Section 2 are the only rights granted under this + License. No additional rights or licenses will be implied from the distribution + or licensing of Covered Software under this License. Notwithstanding Section + 2.1(b) above, no patent license is granted by a Contributor: + + a. for any code that a Contributor has removed from Covered Software; or + + b. for infringements caused by: (i) Your and any other third party’s + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + + c. under Patent Claims infringed by Covered Software in the absence of its + Contributions. + + This License does not grant any rights in the trademarks, service marks, or + logos of any Contributor (except as may be necessary to comply with the + notice requirements in Section 3.4). + +2.4. Subsequent Licenses + + No Contributor makes additional grants as a result of Your choice to + distribute the Covered Software under a subsequent version of this License + (see Section 10.2) or under the terms of a Secondary License (if permitted + under the terms of Section 3.3). + +2.5. Representation + + Each Contributor represents that the Contributor believes its Contributions + are its original creation(s) or it has sufficient rights to grant the + rights to its Contributions conveyed by this License. + +2.6. Fair Use + + This License is not intended to limit any rights You have under applicable + copyright doctrines of fair use, fair dealing, or other equivalents. + +2.7. Conditions + + Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in + Section 2.1. + + +3. Responsibilities + +3.1. Distribution of Source Form + + All distribution of Covered Software in Source Code Form, including any + Modifications that You create or to which You contribute, must be under the + terms of this License. You must inform recipients that the Source Code Form + of the Covered Software is governed by the terms of this License, and how + they can obtain a copy of this License. You may not attempt to alter or + restrict the recipients’ rights in the Source Code Form. + +3.2. Distribution of Executable Form + + If You distribute Covered Software in Executable Form then: + + a. such Covered Software must also be made available in Source Code Form, + as described in Section 3.1, and You must inform recipients of the + Executable Form how they can obtain a copy of such Source Code Form by + reasonable means in a timely manner, at a charge no more than the cost + of distribution to the recipient; and + + b. You may distribute such Executable Form under the terms of this License, + or sublicense it under different terms, provided that the license for + the Executable Form does not attempt to limit or alter the recipients’ + rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + + You may create and distribute a Larger Work under terms of Your choice, + provided that You also comply with the requirements of this License for the + Covered Software. If the Larger Work is a combination of Covered Software + with a work governed by one or more Secondary Licenses, and the Covered + Software is not Incompatible With Secondary Licenses, this License permits + You to additionally distribute such Covered Software under the terms of + such Secondary License(s), so that the recipient of the Larger Work may, at + their option, further distribute the Covered Software under the terms of + either this License or such Secondary License(s). + +3.4. Notices + + You may not remove or alter the substance of any license notices (including + copyright notices, patent notices, disclaimers of warranty, or limitations + of liability) contained within the Source Code Form of the Covered + Software, except that You may alter any license notices to the extent + required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + + You may choose to offer, and to charge a fee for, warranty, support, + indemnity or liability obligations to one or more recipients of Covered + Software. However, You may do so only on Your own behalf, and not on behalf + of any Contributor. You must make it absolutely clear that any such + warranty, support, indemnity, or liability obligation is offered by You + alone, and You hereby agree to indemnify every Contributor for any + liability incurred by such Contributor as a result of warranty, support, + indemnity or liability terms You offer. You may include additional + disclaimers of warranty and limitations of liability specific to any + jurisdiction. + +4. Inability to Comply Due to Statute or Regulation + + If it is impossible for You to comply with any of the terms of this License + with respect to some or all of the Covered Software due to statute, judicial + order, or regulation then You must: (a) comply with the terms of this License + to the maximum extent possible; and (b) describe the limitations and the code + they affect. Such description must be placed in a text file included with all + distributions of the Covered Software under this License. Except to the + extent prohibited by statute or regulation, such description must be + sufficiently detailed for a recipient of ordinary skill to be able to + understand it. + +5. Termination + +5.1. The rights granted under this License will terminate automatically if You + fail to comply with any of its terms. However, if You become compliant, + then the rights granted under this License from a particular Contributor + are reinstated (a) provisionally, unless and until such Contributor + explicitly and finally terminates Your grants, and (b) on an ongoing basis, + if such Contributor fails to notify You of the non-compliance by some + reasonable means prior to 60 days after You have come back into compliance. + Moreover, Your grants from a particular Contributor are reinstated on an + ongoing basis if such Contributor notifies You of the non-compliance by + some reasonable means, this is the first time You have received notice of + non-compliance with this License from such Contributor, and You become + compliant prior to 30 days after Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent + infringement claim (excluding declaratory judgment actions, counter-claims, + and cross-claims) alleging that a Contributor Version directly or + indirectly infringes any patent, then the rights granted to You by any and + all Contributors for the Covered Software under Section 2.1 of this License + shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user + license agreements (excluding distributors and resellers) which have been + validly granted by You or Your distributors under this License prior to + termination shall survive termination. + +6. Disclaimer of Warranty + + Covered Software is provided under this License on an “as is” basis, without + warranty of any kind, either expressed, implied, or statutory, including, + without limitation, warranties that the Covered Software is free of defects, + merchantable, fit for a particular purpose or non-infringing. The entire + risk as to the quality and performance of the Covered Software is with You. + Should any Covered Software prove defective in any respect, You (not any + Contributor) assume the cost of any necessary servicing, repair, or + correction. This disclaimer of warranty constitutes an essential part of this + License. No use of any Covered Software is authorized under this License + except under this disclaimer. + +7. Limitation of Liability + + Under no circumstances and under no legal theory, whether tort (including + negligence), contract, or otherwise, shall any Contributor, or anyone who + distributes Covered Software as permitted above, be liable to You for any + direct, indirect, special, incidental, or consequential damages of any + character including, without limitation, damages for lost profits, loss of + goodwill, work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses, even if such party shall have been + informed of the possibility of such damages. This limitation of liability + shall not apply to liability for death or personal injury resulting from such + party’s negligence to the extent applicable law prohibits such limitation. + Some jurisdictions do not allow the exclusion or limitation of incidental or + consequential damages, so this exclusion and limitation may not apply to You. + +8. Litigation + + Any litigation relating to this License may be brought only in the courts of + a jurisdiction where the defendant maintains its principal place of business + and such litigation shall be governed by laws of that jurisdiction, without + reference to its conflict-of-law provisions. Nothing in this Section shall + prevent a party’s ability to bring cross-claims or counter-claims. + +9. Miscellaneous + + This License represents the complete agreement concerning the subject matter + hereof. If any provision of this License is held to be unenforceable, such + provision shall be reformed only to the extent necessary to make it + enforceable. Any law or regulation which provides that the language of a + contract shall be construed against the drafter shall not be used to construe + this License against a Contributor. + + +10. Versions of the License + +10.1. New Versions + + Mozilla Foundation is the license steward. Except as provided in Section + 10.3, no one other than the license steward has the right to modify or + publish new versions of this License. Each version will be given a + distinguishing version number. + +10.2. Effect of New Versions + + You may distribute the Covered Software under the terms of the version of + the License under which You originally received the Covered Software, or + under the terms of any subsequent version published by the license + steward. + +10.3. Modified Versions + + If you create software not governed by this License, and you want to + create a new license for such software, you may create and use a modified + version of this License if you rename the license and remove any + references to the name of the license steward (except to note that such + modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses + If You choose to distribute Source Code Form that is Incompatible With + Secondary Licenses under the terms of this version of the License, the + notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice + + This Source Code Form is subject to the + terms of the Mozilla Public License, v. + 2.0. If a copy of the MPL was not + distributed with this file, You can + obtain one at + http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular file, then +You may include the notice in a location (such as a LICENSE file in a relevant +directory) where a recipient would be likely to look for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - “Incompatible With Secondary Licenses” Notice + + This Source Code Form is “Incompatible + With Secondary Licenses”, as defined by + the Mozilla Public License, v. 2.0. + diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag/diag.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag/diag.go new file mode 100644 index 000000000..09a65e6bf --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag/diag.go @@ -0,0 +1,84 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package validatordiag + +import ( + "fmt" + "unicode" + "unicode/utf8" + + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" +) + +// InvalidBlockDiagnostic returns an error Diagnostic to be used when a block is invalid +func InvalidBlockDiagnostic(path path.Path, description string) diag.Diagnostic { + return diag.NewAttributeErrorDiagnostic( + path, + "Invalid Block", + fmt.Sprintf("Block %s %s", path, description), + ) +} + +// InvalidAttributeValueDiagnostic returns an error Diagnostic to be used when an attribute has an invalid value. +func InvalidAttributeValueDiagnostic(path path.Path, description string, value string) diag.Diagnostic { + return diag.NewAttributeErrorDiagnostic( + path, + "Invalid Attribute Value", + fmt.Sprintf("Attribute %s %s, got: %s", path, description, value), + ) +} + +// InvalidAttributeValueLengthDiagnostic returns an error Diagnostic to be used when an attribute's value has an invalid length. +func InvalidAttributeValueLengthDiagnostic(path path.Path, description string, value string) diag.Diagnostic { + return diag.NewAttributeErrorDiagnostic( + path, + "Invalid Attribute Value Length", + fmt.Sprintf("Attribute %s %s, got: %s", path, description, value), + ) +} + +// InvalidAttributeValueMatchDiagnostic returns an error Diagnostic to be used when an attribute's value has an invalid match. +func InvalidAttributeValueMatchDiagnostic(path path.Path, description string, value string) diag.Diagnostic { + return diag.NewAttributeErrorDiagnostic( + path, + "Invalid Attribute Value Match", + fmt.Sprintf("Attribute %s %s, got: %s", path, description, value), + ) +} + +// InvalidAttributeCombinationDiagnostic returns an error Diagnostic to be used when a schemavalidator of attributes is invalid. +func InvalidAttributeCombinationDiagnostic(path path.Path, description string) diag.Diagnostic { + return diag.NewAttributeErrorDiagnostic( + path, + "Invalid Attribute Combination", + capitalize(description), + ) +} + +// InvalidAttributeTypeDiagnostic returns an error Diagnostic to be used when an attribute has an invalid type. +func InvalidAttributeTypeDiagnostic(path path.Path, description string, value string) diag.Diagnostic { + return diag.NewAttributeErrorDiagnostic( + path, + "Invalid Attribute Type", + fmt.Sprintf("Attribute %s %s, got: %s", path, description, value), + ) +} + +func BugInProviderDiagnostic(summary string) diag.Diagnostic { + return diag.NewErrorDiagnostic(summary, + "This is a bug in the provider, which should be reported in the provider's own issue tracker", + ) +} + +// capitalize will uppercase the first letter in a UTF-8 string. +func capitalize(str string) string { + if str == "" { + return "" + } + + firstRune, size := utf8.DecodeRuneInString(str) + + return string(unicode.ToUpper(firstRune)) + str[size:] +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag/doc.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag/doc.go new file mode 100644 index 000000000..c6f8dcff5 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag/doc.go @@ -0,0 +1,5 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// Package validatordiag provides diagnostics helpers for validator implementations. +package validatordiag diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/also_requires.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/also_requires.go new file mode 100644 index 000000000..2d4c38a31 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/also_requires.go @@ -0,0 +1,228 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schemavalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// This type of validator must satisfy all types. +var ( + _ validator.Bool = AlsoRequiresValidator{} + _ validator.Float64 = AlsoRequiresValidator{} + _ validator.Int64 = AlsoRequiresValidator{} + _ validator.List = AlsoRequiresValidator{} + _ validator.Map = AlsoRequiresValidator{} + _ validator.Number = AlsoRequiresValidator{} + _ validator.Object = AlsoRequiresValidator{} + _ validator.Set = AlsoRequiresValidator{} + _ validator.String = AlsoRequiresValidator{} +) + +// AlsoRequiresValidator is the underlying struct implementing AlsoRequires. +type AlsoRequiresValidator struct { + PathExpressions path.Expressions +} + +type AlsoRequiresValidatorRequest struct { + Config tfsdk.Config + ConfigValue attr.Value + Path path.Path + PathExpression path.Expression +} + +type AlsoRequiresValidatorResponse struct { + Diagnostics diag.Diagnostics +} + +func (av AlsoRequiresValidator) Description(ctx context.Context) string { + return av.MarkdownDescription(ctx) +} + +func (av AlsoRequiresValidator) MarkdownDescription(_ context.Context) string { + return fmt.Sprintf("Ensure that if an attribute is set, also these are set: %q", av.PathExpressions) +} + +func (av AlsoRequiresValidator) Validate(ctx context.Context, req AlsoRequiresValidatorRequest, res *AlsoRequiresValidatorResponse) { + // If attribute configuration is null, there is nothing else to validate + if req.ConfigValue.IsNull() { + return + } + + expressions := req.PathExpression.MergeExpressions(av.PathExpressions...) + + for _, expression := range expressions { + matchedPaths, diags := req.Config.PathMatches(ctx, expression) + + res.Diagnostics.Append(diags...) + + // Collect all errors + if diags.HasError() { + continue + } + + for _, mp := range matchedPaths { + // If the user specifies the same attribute this validator is applied to, + // also as part of the input, skip it + if mp.Equal(req.Path) { + continue + } + + var mpVal attr.Value + diags := req.Config.GetAttribute(ctx, mp, &mpVal) + res.Diagnostics.Append(diags...) + + // Collect all errors + if diags.HasError() { + continue + } + + // Delay validation until all involved attribute have a known value + if mpVal.IsUnknown() { + return + } + + if mpVal.IsNull() { + res.Diagnostics.Append(validatordiag.InvalidAttributeCombinationDiagnostic( + req.Path, + fmt.Sprintf("Attribute %q must be specified when %q is specified", mp, req.Path), + )) + } + } + } +} + +func (av AlsoRequiresValidator) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse) { + validateReq := AlsoRequiresValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AlsoRequiresValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AlsoRequiresValidator) ValidateFloat64(ctx context.Context, req validator.Float64Request, resp *validator.Float64Response) { + validateReq := AlsoRequiresValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AlsoRequiresValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AlsoRequiresValidator) ValidateInt64(ctx context.Context, req validator.Int64Request, resp *validator.Int64Response) { + validateReq := AlsoRequiresValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AlsoRequiresValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AlsoRequiresValidator) ValidateList(ctx context.Context, req validator.ListRequest, resp *validator.ListResponse) { + validateReq := AlsoRequiresValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AlsoRequiresValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AlsoRequiresValidator) ValidateMap(ctx context.Context, req validator.MapRequest, resp *validator.MapResponse) { + validateReq := AlsoRequiresValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AlsoRequiresValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AlsoRequiresValidator) ValidateNumber(ctx context.Context, req validator.NumberRequest, resp *validator.NumberResponse) { + validateReq := AlsoRequiresValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AlsoRequiresValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AlsoRequiresValidator) ValidateObject(ctx context.Context, req validator.ObjectRequest, resp *validator.ObjectResponse) { + validateReq := AlsoRequiresValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AlsoRequiresValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AlsoRequiresValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + validateReq := AlsoRequiresValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AlsoRequiresValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AlsoRequiresValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { + validateReq := AlsoRequiresValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AlsoRequiresValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/at_least_one_of.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/at_least_one_of.go new file mode 100644 index 000000000..708d59e0f --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/at_least_one_of.go @@ -0,0 +1,224 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schemavalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// This type of validator must satisfy all types. +var ( + _ validator.Bool = AtLeastOneOfValidator{} + _ validator.Float64 = AtLeastOneOfValidator{} + _ validator.Int64 = AtLeastOneOfValidator{} + _ validator.List = AtLeastOneOfValidator{} + _ validator.Map = AtLeastOneOfValidator{} + _ validator.Number = AtLeastOneOfValidator{} + _ validator.Object = AtLeastOneOfValidator{} + _ validator.Set = AtLeastOneOfValidator{} + _ validator.String = AtLeastOneOfValidator{} +) + +// AtLeastOneOfValidator is the underlying struct implementing AtLeastOneOf. +type AtLeastOneOfValidator struct { + PathExpressions path.Expressions +} + +type AtLeastOneOfValidatorRequest struct { + Config tfsdk.Config + ConfigValue attr.Value + Path path.Path + PathExpression path.Expression +} + +type AtLeastOneOfValidatorResponse struct { + Diagnostics diag.Diagnostics +} + +func (av AtLeastOneOfValidator) Description(ctx context.Context) string { + return av.MarkdownDescription(ctx) +} + +func (av AtLeastOneOfValidator) MarkdownDescription(_ context.Context) string { + return fmt.Sprintf("Ensure that at least one attribute from this collection is set: %s", av.PathExpressions) +} + +func (av AtLeastOneOfValidator) Validate(ctx context.Context, req AtLeastOneOfValidatorRequest, res *AtLeastOneOfValidatorResponse) { + // If attribute configuration is not null, validator already succeeded. + if !req.ConfigValue.IsNull() { + return + } + + expressions := req.PathExpression.MergeExpressions(av.PathExpressions...) + + for _, expression := range expressions { + matchedPaths, diags := req.Config.PathMatches(ctx, expression) + + res.Diagnostics.Append(diags...) + + // Collect all errors + if diags.HasError() { + continue + } + + for _, mp := range matchedPaths { + var mpVal attr.Value + diags := req.Config.GetAttribute(ctx, mp, &mpVal) + res.Diagnostics.Append(diags...) + + // Collect all errors + if diags.HasError() { + continue + } + + // Delay validation until all involved attribute have a known value + if mpVal.IsUnknown() { + return + } + + if !mpVal.IsNull() { + return + } + } + } + + res.Diagnostics.Append(validatordiag.InvalidAttributeCombinationDiagnostic( + req.Path, + fmt.Sprintf("At least one attribute out of %s must be specified", expressions), + )) +} + +func (av AtLeastOneOfValidator) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse) { + validateReq := AtLeastOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AtLeastOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AtLeastOneOfValidator) ValidateFloat64(ctx context.Context, req validator.Float64Request, resp *validator.Float64Response) { + validateReq := AtLeastOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AtLeastOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AtLeastOneOfValidator) ValidateInt64(ctx context.Context, req validator.Int64Request, resp *validator.Int64Response) { + validateReq := AtLeastOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AtLeastOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AtLeastOneOfValidator) ValidateList(ctx context.Context, req validator.ListRequest, resp *validator.ListResponse) { + validateReq := AtLeastOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AtLeastOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AtLeastOneOfValidator) ValidateMap(ctx context.Context, req validator.MapRequest, resp *validator.MapResponse) { + validateReq := AtLeastOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AtLeastOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AtLeastOneOfValidator) ValidateNumber(ctx context.Context, req validator.NumberRequest, resp *validator.NumberResponse) { + validateReq := AtLeastOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AtLeastOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AtLeastOneOfValidator) ValidateObject(ctx context.Context, req validator.ObjectRequest, resp *validator.ObjectResponse) { + validateReq := AtLeastOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AtLeastOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AtLeastOneOfValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + validateReq := AtLeastOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AtLeastOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av AtLeastOneOfValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { + validateReq := AtLeastOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &AtLeastOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/conflicts_with.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/conflicts_with.go new file mode 100644 index 000000000..b554953fd --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/conflicts_with.go @@ -0,0 +1,228 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schemavalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// This type of validator must satisfy all types. +var ( + _ validator.Bool = ConflictsWithValidator{} + _ validator.Float64 = ConflictsWithValidator{} + _ validator.Int64 = ConflictsWithValidator{} + _ validator.List = ConflictsWithValidator{} + _ validator.Map = ConflictsWithValidator{} + _ validator.Number = ConflictsWithValidator{} + _ validator.Object = ConflictsWithValidator{} + _ validator.Set = ConflictsWithValidator{} + _ validator.String = ConflictsWithValidator{} +) + +// ConflictsWithValidator is the underlying struct implementing ConflictsWith. +type ConflictsWithValidator struct { + PathExpressions path.Expressions +} + +type ConflictsWithValidatorRequest struct { + Config tfsdk.Config + ConfigValue attr.Value + Path path.Path + PathExpression path.Expression +} + +type ConflictsWithValidatorResponse struct { + Diagnostics diag.Diagnostics +} + +func (av ConflictsWithValidator) Description(ctx context.Context) string { + return av.MarkdownDescription(ctx) +} + +func (av ConflictsWithValidator) MarkdownDescription(_ context.Context) string { + return fmt.Sprintf("Ensure that if an attribute is set, these are not set: %q", av.PathExpressions) +} + +func (av ConflictsWithValidator) Validate(ctx context.Context, req ConflictsWithValidatorRequest, res *ConflictsWithValidatorResponse) { + // If attribute configuration is null, it cannot conflict with others + if req.ConfigValue.IsNull() { + return + } + + expressions := req.PathExpression.MergeExpressions(av.PathExpressions...) + + for _, expression := range expressions { + matchedPaths, diags := req.Config.PathMatches(ctx, expression) + + res.Diagnostics.Append(diags...) + + // Collect all errors + if diags.HasError() { + continue + } + + for _, mp := range matchedPaths { + // If the user specifies the same attribute this validator is applied to, + // also as part of the input, skip it + if mp.Equal(req.Path) { + continue + } + + var mpVal attr.Value + diags := req.Config.GetAttribute(ctx, mp, &mpVal) + res.Diagnostics.Append(diags...) + + // Collect all errors + if diags.HasError() { + continue + } + + // Delay validation until all involved attribute have a known value + if mpVal.IsUnknown() { + return + } + + if !mpVal.IsNull() { + res.Diagnostics.Append(validatordiag.InvalidAttributeCombinationDiagnostic( + req.Path, + fmt.Sprintf("Attribute %q cannot be specified when %q is specified", mp, req.Path), + )) + } + } + } +} + +func (av ConflictsWithValidator) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse) { + validateReq := ConflictsWithValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ConflictsWithValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ConflictsWithValidator) ValidateFloat64(ctx context.Context, req validator.Float64Request, resp *validator.Float64Response) { + validateReq := ConflictsWithValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ConflictsWithValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ConflictsWithValidator) ValidateInt64(ctx context.Context, req validator.Int64Request, resp *validator.Int64Response) { + validateReq := ConflictsWithValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ConflictsWithValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ConflictsWithValidator) ValidateList(ctx context.Context, req validator.ListRequest, resp *validator.ListResponse) { + validateReq := ConflictsWithValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ConflictsWithValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ConflictsWithValidator) ValidateMap(ctx context.Context, req validator.MapRequest, resp *validator.MapResponse) { + validateReq := ConflictsWithValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ConflictsWithValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ConflictsWithValidator) ValidateNumber(ctx context.Context, req validator.NumberRequest, resp *validator.NumberResponse) { + validateReq := ConflictsWithValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ConflictsWithValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ConflictsWithValidator) ValidateObject(ctx context.Context, req validator.ObjectRequest, resp *validator.ObjectResponse) { + validateReq := ConflictsWithValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ConflictsWithValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ConflictsWithValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + validateReq := ConflictsWithValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ConflictsWithValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ConflictsWithValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { + validateReq := ConflictsWithValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ConflictsWithValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/doc.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/doc.go new file mode 100644 index 000000000..612dce36e --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/doc.go @@ -0,0 +1,14 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// Package schemavalidator provides validators to express relationships between +// multiple attributes within the schema of a resource, data source, or provider. +// For example, checking that an attribute is present when another is present, or vice-versa. +// +// These validators are implemented on a starting attribute, where +// relationships can be expressed as absolute paths to others or relative to +// the starting attribute. For multiple attribute validators that are defined +// outside the schema, which may be easier to implement in provider code +// generation situations or suit provider code preferences differently, refer +// to the datasourcevalidator, providervalidator, or resourcevalidator package. +package schemavalidator diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/exactly_one_of.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/exactly_one_of.go new file mode 100644 index 000000000..f284fe275 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator/exactly_one_of.go @@ -0,0 +1,248 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schemavalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/tfsdk" +) + +// This type of validator must satisfy all types. +var ( + _ validator.Bool = ExactlyOneOfValidator{} + _ validator.Float64 = ExactlyOneOfValidator{} + _ validator.Int64 = ExactlyOneOfValidator{} + _ validator.List = ExactlyOneOfValidator{} + _ validator.Map = ExactlyOneOfValidator{} + _ validator.Number = ExactlyOneOfValidator{} + _ validator.Object = ExactlyOneOfValidator{} + _ validator.Set = ExactlyOneOfValidator{} + _ validator.String = ExactlyOneOfValidator{} +) + +// ExactlyOneOfValidator is the underlying struct implementing ExactlyOneOf. +type ExactlyOneOfValidator struct { + PathExpressions path.Expressions +} + +type ExactlyOneOfValidatorRequest struct { + Config tfsdk.Config + ConfigValue attr.Value + Path path.Path + PathExpression path.Expression +} + +type ExactlyOneOfValidatorResponse struct { + Diagnostics diag.Diagnostics +} + +func (av ExactlyOneOfValidator) Description(ctx context.Context) string { + return av.MarkdownDescription(ctx) +} + +func (av ExactlyOneOfValidator) MarkdownDescription(_ context.Context) string { + return fmt.Sprintf("Ensure that one and only one attribute from this collection is set: %q", av.PathExpressions) +} + +func (av ExactlyOneOfValidator) Validate(ctx context.Context, req ExactlyOneOfValidatorRequest, res *ExactlyOneOfValidatorResponse) { + count := 0 + expressions := req.PathExpression.MergeExpressions(av.PathExpressions...) + + // If current attribute is unknown, delay validation + if req.ConfigValue.IsUnknown() { + return + } + + // Now that we know the current attribute is known, check whether it is + // null to determine if it should contribute to the count. Later logic + // will remove a duplicate matching path, should it be included in the + // given expressions. + if !req.ConfigValue.IsNull() { + count++ + } + + for _, expression := range expressions { + matchedPaths, diags := req.Config.PathMatches(ctx, expression) + + res.Diagnostics.Append(diags...) + + // Collect all errors + if diags.HasError() { + continue + } + + for _, mp := range matchedPaths { + // If the user specifies the same attribute this validator is applied to, + // also as part of the input, skip it + if mp.Equal(req.Path) { + continue + } + + var mpVal attr.Value + diags := req.Config.GetAttribute(ctx, mp, &mpVal) + res.Diagnostics.Append(diags...) + + // Collect all errors + if diags.HasError() { + continue + } + + // Delay validation until all involved attribute have a known value + if mpVal.IsUnknown() { + return + } + + if !mpVal.IsNull() { + count++ + } + } + } + + if count == 0 { + res.Diagnostics.Append(validatordiag.InvalidAttributeCombinationDiagnostic( + req.Path, + fmt.Sprintf("No attribute specified when one (and only one) of %s is required", expressions), + )) + } + + if count > 1 { + res.Diagnostics.Append(validatordiag.InvalidAttributeCombinationDiagnostic( + req.Path, + fmt.Sprintf("%d attributes specified when one (and only one) of %s is required", count, expressions), + )) + } +} + +func (av ExactlyOneOfValidator) ValidateBool(ctx context.Context, req validator.BoolRequest, resp *validator.BoolResponse) { + validateReq := ExactlyOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ExactlyOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ExactlyOneOfValidator) ValidateFloat64(ctx context.Context, req validator.Float64Request, resp *validator.Float64Response) { + validateReq := ExactlyOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ExactlyOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ExactlyOneOfValidator) ValidateInt64(ctx context.Context, req validator.Int64Request, resp *validator.Int64Response) { + validateReq := ExactlyOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ExactlyOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ExactlyOneOfValidator) ValidateList(ctx context.Context, req validator.ListRequest, resp *validator.ListResponse) { + validateReq := ExactlyOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ExactlyOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ExactlyOneOfValidator) ValidateMap(ctx context.Context, req validator.MapRequest, resp *validator.MapResponse) { + validateReq := ExactlyOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ExactlyOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ExactlyOneOfValidator) ValidateNumber(ctx context.Context, req validator.NumberRequest, resp *validator.NumberResponse) { + validateReq := ExactlyOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ExactlyOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ExactlyOneOfValidator) ValidateObject(ctx context.Context, req validator.ObjectRequest, resp *validator.ObjectResponse) { + validateReq := ExactlyOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ExactlyOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ExactlyOneOfValidator) ValidateSet(ctx context.Context, req validator.SetRequest, resp *validator.SetResponse) { + validateReq := ExactlyOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ExactlyOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} + +func (av ExactlyOneOfValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { + validateReq := ExactlyOneOfValidatorRequest{ + Config: req.Config, + ConfigValue: req.ConfigValue, + Path: req.Path, + PathExpression: req.PathExpression, + } + validateResp := &ExactlyOneOfValidatorResponse{} + + av.Validate(ctx, validateReq, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/all.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/all.go new file mode 100644 index 000000000..f53caba25 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/all.go @@ -0,0 +1,57 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// All returns a validator which ensures that any configured attribute value +// attribute value validates against all the given validators. +// +// Use of All is only necessary when used in conjunction with Any or AnyWithAllWarnings +// as the Validators field automatically applies a logical AND. +func All(validators ...validator.String) validator.String { + return allValidator{ + validators: validators, + } +} + +var _ validator.String = allValidator{} + +// allValidator implements the validator. +type allValidator struct { + validators []validator.String +} + +// Description describes the validation in plain text formatting. +func (v allValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, subValidator := range v.validators { + descriptions = append(descriptions, subValidator.Description(ctx)) + } + + return fmt.Sprintf("Value must satisfy all of the validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v allValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateString performs the validation. +func (v allValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { + for _, subValidator := range v.validators { + validateResp := &validator.StringResponse{} + + subValidator.ValidateString(ctx, req, validateResp) + + resp.Diagnostics.Append(validateResp.Diagnostics...) + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/also_requires.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/also_requires.go new file mode 100644 index 000000000..97ca59b73 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/also_requires.go @@ -0,0 +1,26 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// AlsoRequires checks that a set of path.Expression has a non-null value, +// if the current attribute or block also has a non-null value. +// +// This implements the validation logic declaratively within the schema. +// Refer to [datasourcevalidator.RequiredTogether], +// [providervalidator.RequiredTogether], or [resourcevalidator.RequiredTogether] +// for declaring this type of validation outside the schema definition. +// +// Relative path.Expression will be resolved using the attribute or block +// being validated. +func AlsoRequires(expressions ...path.Expression) validator.String { + return schemavalidator.AlsoRequiresValidator{ + PathExpressions: expressions, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/any.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/any.go new file mode 100644 index 000000000..ba8f218ac --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/any.go @@ -0,0 +1,65 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// Any returns a validator which ensures that any configured attribute value +// passes at least one of the given validators. +// +// To prevent practitioner confusion should non-passing validators have +// conflicting logic, only warnings from the passing validator are returned. +// Use AnyWithAllWarnings() to return warnings from non-passing validators +// as well. +func Any(validators ...validator.String) validator.String { + return anyValidator{ + validators: validators, + } +} + +var _ validator.String = anyValidator{} + +// anyValidator implements the validator. +type anyValidator struct { + validators []validator.String +} + +// Description describes the validation in plain text formatting. +func (v anyValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, subValidator := range v.validators { + descriptions = append(descriptions, subValidator.Description(ctx)) + } + + return fmt.Sprintf("Value must satisfy at least one of the validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v anyValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateString performs the validation. +func (v anyValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { + for _, subValidator := range v.validators { + validateResp := &validator.StringResponse{} + + subValidator.ValidateString(ctx, req, validateResp) + + if !validateResp.Diagnostics.HasError() { + resp.Diagnostics = validateResp.Diagnostics + + return + } + + resp.Diagnostics.Append(validateResp.Diagnostics...) + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/any_with_all_warnings.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/any_with_all_warnings.go new file mode 100644 index 000000000..e857424c9 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/any_with_all_warnings.go @@ -0,0 +1,67 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// AnyWithAllWarnings returns a validator which ensures that any configured +// attribute value passes at least one of the given validators. This validator +// returns all warnings, including failed validators. +// +// Use Any() to return warnings only from the passing validator. +func AnyWithAllWarnings(validators ...validator.String) validator.String { + return anyWithAllWarningsValidator{ + validators: validators, + } +} + +var _ validator.String = anyWithAllWarningsValidator{} + +// anyWithAllWarningsValidator implements the validator. +type anyWithAllWarningsValidator struct { + validators []validator.String +} + +// Description describes the validation in plain text formatting. +func (v anyWithAllWarningsValidator) Description(ctx context.Context) string { + var descriptions []string + + for _, subValidator := range v.validators { + descriptions = append(descriptions, subValidator.Description(ctx)) + } + + return fmt.Sprintf("Value must satisfy at least one of the validations: %s", strings.Join(descriptions, " + ")) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v anyWithAllWarningsValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// ValidateString performs the validation. +func (v anyWithAllWarningsValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { + anyValid := false + + for _, subValidator := range v.validators { + validateResp := &validator.StringResponse{} + + subValidator.ValidateString(ctx, req, validateResp) + + if !validateResp.Diagnostics.HasError() { + anyValid = true + } + + resp.Diagnostics.Append(validateResp.Diagnostics...) + } + + if anyValid { + resp.Diagnostics = resp.Diagnostics.Warnings() + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/at_least_one_of.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/at_least_one_of.go new file mode 100644 index 000000000..4434fad2b --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/at_least_one_of.go @@ -0,0 +1,27 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// AtLeastOneOf checks that of a set of path.Expression, +// including the attribute this validator is applied to, +// at least one has a non-null value. +// +// This implements the validation logic declaratively within the tfsdk.Schema. +// Refer to [datasourcevalidator.AtLeastOneOf], +// [providervalidator.AtLeastOneOf], or [resourcevalidator.AtLeastOneOf] +// for declaring this type of validation outside the schema definition. +// +// Any relative path.Expression will be resolved using the attribute being +// validated. +func AtLeastOneOf(expressions ...path.Expression) validator.String { + return schemavalidator.AtLeastOneOfValidator{ + PathExpressions: expressions, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/conflicts_with.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/conflicts_with.go new file mode 100644 index 000000000..42f514539 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/conflicts_with.go @@ -0,0 +1,27 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// ConflictsWith checks that a set of path.Expression, +// including the attribute the validator is applied to, +// do not have a value simultaneously. +// +// This implements the validation logic declaratively within the schema. +// Refer to [datasourcevalidator.Conflicting], +// [providervalidator.Conflicting], or [resourcevalidator.Conflicting] +// for declaring this type of validation outside the schema definition. +// +// Relative path.Expression will be resolved using the attribute being +// validated. +func ConflictsWith(expressions ...path.Expression) validator.String { + return schemavalidator.ConflictsWithValidator{ + PathExpressions: expressions, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/doc.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/doc.go new file mode 100644 index 000000000..6d95e874d --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/doc.go @@ -0,0 +1,5 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// Package stringvalidator provides validators for types.String attributes. +package stringvalidator diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/exactly_one_of.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/exactly_one_of.go new file mode 100644 index 000000000..e3f557d3c --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/exactly_one_of.go @@ -0,0 +1,28 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator" + "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +// ExactlyOneOf checks that of a set of path.Expression, +// including the attribute the validator is applied to, +// one and only one attribute has a value. +// It will also cause a validation error if none are specified. +// +// This implements the validation logic declaratively within the schema. +// Refer to [datasourcevalidator.ExactlyOneOf], +// [providervalidator.ExactlyOneOf], or [resourcevalidator.ExactlyOneOf] +// for declaring this type of validation outside the schema definition. +// +// Relative path.Expression will be resolved using the attribute being +// validated. +func ExactlyOneOf(expressions ...path.Expression) validator.String { + return schemavalidator.ExactlyOneOfValidator{ + PathExpressions: expressions, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_at_least.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_at_least.go new file mode 100644 index 000000000..0ebaffae5 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_at_least.go @@ -0,0 +1,65 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" +) + +var _ validator.String = lengthAtLeastValidator{} + +// stringLenAtLeastValidator validates that a string Attribute's length is at least a certain value. +type lengthAtLeastValidator struct { + minLength int +} + +// Description describes the validation in plain text formatting. +func (validator lengthAtLeastValidator) Description(_ context.Context) string { + return fmt.Sprintf("string length must be at least %d", validator.minLength) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (validator lengthAtLeastValidator) MarkdownDescription(ctx context.Context) string { + return validator.Description(ctx) +} + +// Validate performs the validation. +func (v lengthAtLeastValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue.ValueString() + + if l := len(value); l < v.minLength { + response.Diagnostics.Append(validatordiag.InvalidAttributeValueLengthDiagnostic( + request.Path, + v.Description(ctx), + fmt.Sprintf("%d", l), + )) + + return + } +} + +// LengthAtLeast returns an validator which ensures that any configured +// attribute value is of single-byte character length greater than or equal +// to the given minimum. Null (unconfigured) and unknown (known after apply) +// values are skipped. +// +// Use UTF8LengthAtLeast for checking multiple-byte characters. +func LengthAtLeast(minLength int) validator.String { + if minLength < 0 { + return nil + } + + return lengthAtLeastValidator{ + minLength: minLength, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_at_most.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_at_most.go new file mode 100644 index 000000000..a793a0b09 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_at_most.go @@ -0,0 +1,64 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.String = lengthAtMostValidator{} + +// lengthAtMostValidator validates that a string Attribute's length is at most a certain value. +type lengthAtMostValidator struct { + maxLength int +} + +// Description describes the validation in plain text formatting. +func (validator lengthAtMostValidator) Description(_ context.Context) string { + return fmt.Sprintf("string length must be at most %d", validator.maxLength) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (validator lengthAtMostValidator) MarkdownDescription(ctx context.Context) string { + return validator.Description(ctx) +} + +// Validate performs the validation. +func (v lengthAtMostValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue.ValueString() + + if l := len(value); l > v.maxLength { + response.Diagnostics.Append(validatordiag.InvalidAttributeValueLengthDiagnostic( + request.Path, + v.Description(ctx), + fmt.Sprintf("%d", l), + )) + + return + } +} + +// LengthAtMost returns an validator which ensures that any configured +// attribute value is of single-byte character length less than or equal +// to the given maximum. Null (unconfigured) and unknown (known after apply) +// values are skipped. +// +// Use UTF8LengthAtMost for checking multiple-byte characters. +func LengthAtMost(maxLength int) validator.String { + if maxLength < 0 { + return nil + } + + return lengthAtMostValidator{ + maxLength: maxLength, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_between.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_between.go new file mode 100644 index 000000000..c70f4c05c --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/length_between.go @@ -0,0 +1,65 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.String = lengthBetweenValidator{} + +// stringLenBetweenValidator validates that a string Attribute's length is in a range. +type lengthBetweenValidator struct { + minLength, maxLength int +} + +// Description describes the validation in plain text formatting. +func (validator lengthBetweenValidator) Description(_ context.Context) string { + return fmt.Sprintf("string length must be between %d and %d", validator.minLength, validator.maxLength) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (validator lengthBetweenValidator) MarkdownDescription(ctx context.Context) string { + return validator.Description(ctx) +} + +// Validate performs the validation. +func (v lengthBetweenValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue.ValueString() + + if l := len(value); l < v.minLength || l > v.maxLength { + response.Diagnostics.Append(validatordiag.InvalidAttributeValueLengthDiagnostic( + request.Path, + v.Description(ctx), + fmt.Sprintf("%d", l), + )) + + return + } +} + +// LengthBetween returns a validator which ensures that any configured +// attribute value is of single-byte character length greater than or equal +// to the given minimum and less than or equal to the given maximum. Null +// (unconfigured) and unknown (known after apply) values are skipped. +// +// Use UTF8LengthBetween for checking multiple-byte characters. +func LengthBetween(minLength, maxLength int) validator.String { + if minLength < 0 || minLength > maxLength { + return nil + } + + return lengthBetweenValidator{ + minLength: minLength, + maxLength: maxLength, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/none_of.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/none_of.go new file mode 100644 index 000000000..6bf7dce88 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/none_of.go @@ -0,0 +1,65 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" +) + +var _ validator.String = noneOfValidator{} + +// noneOfValidator validates that the value does not match one of the values. +type noneOfValidator struct { + values []types.String +} + +func (v noneOfValidator) Description(ctx context.Context) string { + return v.MarkdownDescription(ctx) +} + +func (v noneOfValidator) MarkdownDescription(_ context.Context) string { + return fmt.Sprintf("value must be none of: %s", v.values) +} + +func (v noneOfValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue + + for _, otherValue := range v.values { + if !value.Equal(otherValue) { + continue + } + + response.Diagnostics.Append(validatordiag.InvalidAttributeValueMatchDiagnostic( + request.Path, + v.Description(ctx), + value.String(), + )) + + break + } +} + +// NoneOf checks that the String held in the attribute +// is none of the given `values`. +func NoneOf(values ...string) validator.String { + frameworkValues := make([]types.String, 0, len(values)) + + for _, value := range values { + frameworkValues = append(frameworkValues, types.StringValue(value)) + } + + return noneOfValidator{ + values: frameworkValues, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/none_of_case_insensitive.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/none_of_case_insensitive.go new file mode 100644 index 000000000..aedb0949a --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/none_of_case_insensitive.go @@ -0,0 +1,64 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" +) + +var _ validator.String = noneOfCaseInsensitiveValidator{} + +// noneOfCaseInsensitiveValidator validates that the value matches one of expected values. +type noneOfCaseInsensitiveValidator struct { + values []types.String +} + +func (v noneOfCaseInsensitiveValidator) Description(ctx context.Context) string { + return v.MarkdownDescription(ctx) +} + +func (v noneOfCaseInsensitiveValidator) MarkdownDescription(_ context.Context) string { + return fmt.Sprintf("value must be none of: %s", v.values) +} + +func (v noneOfCaseInsensitiveValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue + + for _, otherValue := range v.values { + if strings.EqualFold(value.ValueString(), otherValue.ValueString()) { + response.Diagnostics.Append(validatordiag.InvalidAttributeValueMatchDiagnostic( + request.Path, + v.Description(ctx), + value.String(), + )) + + return + } + } +} + +// NoneOfCaseInsensitive checks that the String held in the attribute +// is none of the given `values`. +func NoneOfCaseInsensitive(values ...string) validator.String { + frameworkValues := make([]types.String, 0, len(values)) + + for _, value := range values { + frameworkValues = append(frameworkValues, types.StringValue(value)) + } + + return noneOfCaseInsensitiveValidator{ + values: frameworkValues, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/one_of.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/one_of.go new file mode 100644 index 000000000..c3ae055bd --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/one_of.go @@ -0,0 +1,63 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" +) + +var _ validator.String = oneOfValidator{} + +// oneOfValidator validates that the value matches one of expected values. +type oneOfValidator struct { + values []types.String +} + +func (v oneOfValidator) Description(ctx context.Context) string { + return v.MarkdownDescription(ctx) +} + +func (v oneOfValidator) MarkdownDescription(_ context.Context) string { + return fmt.Sprintf("value must be one of: %s", v.values) +} + +func (v oneOfValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue + + for _, otherValue := range v.values { + if value.Equal(otherValue) { + return + } + } + + response.Diagnostics.Append(validatordiag.InvalidAttributeValueMatchDiagnostic( + request.Path, + v.Description(ctx), + value.String(), + )) +} + +// OneOf checks that the String held in the attribute +// is one of the given `values`. +func OneOf(values ...string) validator.String { + frameworkValues := make([]types.String, 0, len(values)) + + for _, value := range values { + frameworkValues = append(frameworkValues, types.StringValue(value)) + } + + return oneOfValidator{ + values: frameworkValues, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/one_of_case_insensitive.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/one_of_case_insensitive.go new file mode 100644 index 000000000..7e5912ab7 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/one_of_case_insensitive.go @@ -0,0 +1,64 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" +) + +var _ validator.String = oneOfCaseInsensitiveValidator{} + +// oneOfCaseInsensitiveValidator validates that the value matches one of expected values. +type oneOfCaseInsensitiveValidator struct { + values []types.String +} + +func (v oneOfCaseInsensitiveValidator) Description(ctx context.Context) string { + return v.MarkdownDescription(ctx) +} + +func (v oneOfCaseInsensitiveValidator) MarkdownDescription(_ context.Context) string { + return fmt.Sprintf("value must be one of: %s", v.values) +} + +func (v oneOfCaseInsensitiveValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue + + for _, otherValue := range v.values { + if strings.EqualFold(value.ValueString(), otherValue.ValueString()) { + return + } + } + + response.Diagnostics.Append(validatordiag.InvalidAttributeValueMatchDiagnostic( + request.Path, + v.Description(ctx), + value.String(), + )) +} + +// OneOfCaseInsensitive checks that the String held in the attribute +// is one of the given `values`. +func OneOfCaseInsensitive(values ...string) validator.String { + frameworkValues := make([]types.String, 0, len(values)) + + for _, value := range values { + frameworkValues = append(frameworkValues, types.StringValue(value)) + } + + return oneOfCaseInsensitiveValidator{ + values: frameworkValues, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/regex_matches.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/regex_matches.go new file mode 100644 index 000000000..4cab99757 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/regex_matches.go @@ -0,0 +1,67 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + "regexp" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" +) + +var _ validator.String = regexMatchesValidator{} + +// regexMatchesValidator validates that a string Attribute's value matches the specified regular expression. +type regexMatchesValidator struct { + regexp *regexp.Regexp + message string +} + +// Description describes the validation in plain text formatting. +func (validator regexMatchesValidator) Description(_ context.Context) string { + if validator.message != "" { + return validator.message + } + return fmt.Sprintf("value must match regular expression '%s'", validator.regexp) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (validator regexMatchesValidator) MarkdownDescription(ctx context.Context) string { + return validator.Description(ctx) +} + +// Validate performs the validation. +func (v regexMatchesValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue.ValueString() + + if !v.regexp.MatchString(value) { + response.Diagnostics.Append(validatordiag.InvalidAttributeValueMatchDiagnostic( + request.Path, + v.Description(ctx), + value, + )) + } +} + +// RegexMatches returns an AttributeValidator which ensures that any configured +// attribute value: +// +// - Is a string. +// - Matches the given regular expression https://github.com/google/re2/wiki/Syntax. +// +// Null (unconfigured) and unknown (known after apply) values are skipped. +// Optionally an error message can be provided to return something friendlier +// than "value must match regular expression 'regexp'". +func RegexMatches(regexp *regexp.Regexp, message string) validator.String { + return regexMatchesValidator{ + regexp: regexp, + message: message, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_at_least.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_at_least.go new file mode 100644 index 000000000..6159eab57 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_at_least.go @@ -0,0 +1,68 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + "unicode/utf8" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" +) + +var _ validator.String = utf8LengthAtLeastValidator{} + +// utf8LengthAtLeastValidator implements the validator. +type utf8LengthAtLeastValidator struct { + minLength int +} + +// Description describes the validation in plain text formatting. +func (validator utf8LengthAtLeastValidator) Description(_ context.Context) string { + return fmt.Sprintf("UTF-8 character count must be at least %d", validator.minLength) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (validator utf8LengthAtLeastValidator) MarkdownDescription(ctx context.Context) string { + return validator.Description(ctx) +} + +// Validate performs the validation. +func (v utf8LengthAtLeastValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue.ValueString() + + count := utf8.RuneCountInString(value) + + if count < v.minLength { + response.Diagnostics.Append(validatordiag.InvalidAttributeValueLengthDiagnostic( + request.Path, + v.Description(ctx), + fmt.Sprintf("%d", count), + )) + + return + } +} + +// UTF8LengthAtLeast returns an validator which ensures that any configured +// attribute value is of UTF-8 character count greater than or equal to the +// given minimum. Null (unconfigured) and unknown (known after apply) values +// are skipped. +// +// Use LengthAtLeast for checking single-byte character counts. +func UTF8LengthAtLeast(minLength int) validator.String { + if minLength < 0 { + return nil + } + + return utf8LengthAtLeastValidator{ + minLength: minLength, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_at_most.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_at_most.go new file mode 100644 index 000000000..1653d5f88 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_at_most.go @@ -0,0 +1,68 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + "unicode/utf8" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" +) + +var _ validator.String = utf8LengthAtMostValidator{} + +// utf8LengthAtMostValidator implements the validator. +type utf8LengthAtMostValidator struct { + maxLength int +} + +// Description describes the validation in plain text formatting. +func (validator utf8LengthAtMostValidator) Description(_ context.Context) string { + return fmt.Sprintf("UTF-8 character count must be at most %d", validator.maxLength) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (validator utf8LengthAtMostValidator) MarkdownDescription(ctx context.Context) string { + return validator.Description(ctx) +} + +// Validate performs the validation. +func (v utf8LengthAtMostValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue.ValueString() + + count := utf8.RuneCountInString(value) + + if count > v.maxLength { + response.Diagnostics.Append(validatordiag.InvalidAttributeValueLengthDiagnostic( + request.Path, + v.Description(ctx), + fmt.Sprintf("%d", count), + )) + + return + } +} + +// UTF8LengthAtMost returns an validator which ensures that any configured +// attribute value is of UTF-8 character count less than or equal to the +// given maximum. Null (unconfigured) and unknown (known after apply) values +// are skipped. +// +// Use LengthAtMost for checking single-byte character counts. +func UTF8LengthAtMost(maxLength int) validator.String { + if maxLength < 0 { + return nil + } + + return utf8LengthAtMostValidator{ + maxLength: maxLength, + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_between.go b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_between.go new file mode 100644 index 000000000..791b9a569 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator/utf8_length_between.go @@ -0,0 +1,70 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package stringvalidator + +import ( + "context" + "fmt" + "unicode/utf8" + + "github.com/hashicorp/terraform-plugin-framework/schema/validator" + + "github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" +) + +var _ validator.String = utf8LengthBetweenValidator{} + +// utf8LengthBetweenValidator implements the validator. +type utf8LengthBetweenValidator struct { + maxLength int + minLength int +} + +// Description describes the validation in plain text formatting. +func (v utf8LengthBetweenValidator) Description(_ context.Context) string { + return fmt.Sprintf("UTF-8 character count must be between %d and %d", v.minLength, v.maxLength) +} + +// MarkdownDescription describes the validation in Markdown formatting. +func (v utf8LengthBetweenValidator) MarkdownDescription(ctx context.Context) string { + return v.Description(ctx) +} + +// Validate performs the validation. +func (v utf8LengthBetweenValidator) ValidateString(ctx context.Context, request validator.StringRequest, response *validator.StringResponse) { + if request.ConfigValue.IsNull() || request.ConfigValue.IsUnknown() { + return + } + + value := request.ConfigValue.ValueString() + + count := utf8.RuneCountInString(value) + + if count < v.minLength || count > v.maxLength { + response.Diagnostics.Append(validatordiag.InvalidAttributeValueLengthDiagnostic( + request.Path, + v.Description(ctx), + fmt.Sprintf("%d", count), + )) + + return + } +} + +// UTF8LengthBetween returns an validator which ensures that any configured +// attribute value is of UTF-8 character count greater than or equal to the +// given minimum and less than or equal to the given maximum. Null +// (unconfigured) and unknown (known after apply) values are skipped. +// +// Use LengthBetween for checking single-byte character counts. +func UTF8LengthBetween(minLength int, maxLength int) validator.String { + if minLength < 0 || maxLength < 0 || minLength > maxLength { + return nil + } + + return utf8LengthBetweenValidator{ + maxLength: maxLength, + minLength: minLength, + } +} diff --git a/vendor/modules.txt b/vendor/modules.txt index b2ab7fac5..76ec5f675 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -170,6 +170,11 @@ github.com/hashicorp/terraform-plugin-framework/schema/validator github.com/hashicorp/terraform-plugin-framework/tfsdk github.com/hashicorp/terraform-plugin-framework/types github.com/hashicorp/terraform-plugin-framework/types/basetypes +# github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 +## explicit; go 1.19 +github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag +github.com/hashicorp/terraform-plugin-framework-validators/internal/schemavalidator +github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator # github.com/hashicorp/terraform-plugin-go v0.20.0 ## explicit; go 1.20 github.com/hashicorp/terraform-plugin-go/internal/logging