From a076794cadacdb24c1f675650833c9d03c3f6d28 Mon Sep 17 00:00:00 2001 From: elena Date: Wed, 17 Sep 2025 09:24:07 +0800 Subject: [PATCH 1/2] new resource azurerm_api_management_workspace_policy_fragment --- ...ment_workspace_policy_fragment_resource.go | 246 ++++++++++++++++++ ...workspace_policy_fragment_resource_test.go | 210 +++++++++++++++ .../services/apimanagement/client/client.go | 9 + .../services/apimanagement/registration.go | 2 + .../2024-05-01/policyfragment/README.md | 218 ++++++++++++++++ .../2024-05-01/policyfragment/client.go | 26 ++ .../2024-05-01/policyfragment/constants.go | 51 ++++ .../policyfragment/id_policyfragment.go | 139 ++++++++++ .../2024-05-01/policyfragment/id_service.go | 130 +++++++++ .../2024-05-01/policyfragment/id_workspace.go | 139 ++++++++++ .../id_workspacepolicyfragment.go | 148 +++++++++++ .../policyfragment/method_createorupdate.go | 104 ++++++++ .../policyfragment/method_delete.go | 77 ++++++ .../2024-05-01/policyfragment/method_get.go | 83 ++++++ .../policyfragment/method_getentitytag.go | 46 ++++ .../policyfragment/method_listbyservice.go | 146 +++++++++++ .../policyfragment/method_listreferences.go | 138 ++++++++++ ...d_workspacepolicyfragmentcreateorupdate.go | 104 ++++++++ .../method_workspacepolicyfragmentdelete.go | 77 ++++++ .../method_workspacepolicyfragmentget.go | 83 ++++++ ...hod_workspacepolicyfragmentgetentitytag.go | 46 ++++ ...od_workspacepolicyfragmentlistbyservice.go | 146 +++++++++++ ...d_workspacepolicyfragmentlistreferences.go | 138 ++++++++++ .../model_policyfragmentcontract.go | 11 + .../model_policyfragmentcontractproperties.go | 11 + .../policyfragment/model_resource.go | 10 + .../2024-05-01/policyfragment/predicates.go | 50 ++++ .../2024-05-01/policyfragment/version.go | 10 + vendor/modules.txt | 1 + ...nt_workspace_policy_fragment.html.markdown | 91 +++++++ 30 files changed, 2690 insertions(+) create mode 100644 internal/services/apimanagement/api_management_workspace_policy_fragment_resource.go create mode 100644 internal/services/apimanagement/api_management_workspace_policy_fragment_resource_test.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_service.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_createorupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_delete.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_get.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_getentitytag.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_listbyservice.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_listreferences.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentcreateorupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentdelete.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentget.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentgetentitytag.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistbyservice.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistreferences.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontract.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontractproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_resource.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/version.go create mode 100644 website/docs/r/api_management_workspace_policy_fragment.html.markdown diff --git a/internal/services/apimanagement/api_management_workspace_policy_fragment_resource.go b/internal/services/apimanagement/api_management_workspace_policy_fragment_resource.go new file mode 100644 index 000000000000..7af197edcb9c --- /dev/null +++ b/internal/services/apimanagement/api_management_workspace_policy_fragment_resource.go @@ -0,0 +1,246 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package apimanagement + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/schemaz" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" +) + +type ApiManagementWorkspacePolicyFragmentModel struct { + Name string `tfschema:"name"` + ApiManagementWorkspaceId string `tfschema:"api_management_workspace_id"` + Description string `tfschema:"description"` + XmlFormat string `tfschema:"xml_format"` + XmlContent string `tfschema:"xml_content"` +} + +type ApiManagementWorkspacePolicyFragmentResource struct{} + +var _ sdk.ResourceWithUpdate = ApiManagementWorkspacePolicyFragmentResource{} + +func (r ApiManagementWorkspacePolicyFragmentResource) ResourceType() string { + return "azurerm_api_management_workspace_policy_fragment" +} + +func (r ApiManagementWorkspacePolicyFragmentResource) ModelObject() interface{} { + return &ApiManagementWorkspacePolicyFragmentModel{} +} + +func (r ApiManagementWorkspacePolicyFragmentResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return policyfragment.ValidateWorkspacePolicyFragmentID +} + +func (r ApiManagementWorkspacePolicyFragmentResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": schemaz.SchemaApiManagementChildName(), + + "api_management_workspace_id": commonschema.ResourceIDReferenceRequiredForceNew(&policyfragment.WorkspaceId{}), + + "xml_content": { + Type: pluginsdk.TypeString, + Required: true, + DiffSuppressFunc: XmlWhitespaceDiffSuppress, + }, + + "xml_format": { + Type: pluginsdk.TypeString, + Optional: true, + Default: string(policyfragment.PolicyFragmentContentFormatXml), + ValidateFunc: validation.StringInSlice(policyfragment.PossibleValuesForPolicyFragmentContentFormat(), false), + }, + + "description": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + } +} + +func (r ApiManagementWorkspacePolicyFragmentResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r ApiManagementWorkspacePolicyFragmentResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.ApiManagement.PolicyFragmentClient_v2024_05_01 + + var model ApiManagementWorkspacePolicyFragmentModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + workspaceId, err := policyfragment.ParseWorkspaceID(model.ApiManagementWorkspaceId) + if err != nil { + return err + } + + id := policyfragment.NewWorkspacePolicyFragmentID(workspaceId.SubscriptionId, workspaceId.ResourceGroupName, workspaceId.ServiceName, workspaceId.WorkspaceId, model.Name) + existing, err := client.WorkspacePolicyFragmentGet(ctx, id, policyfragment.WorkspacePolicyFragmentGetOperationOptions{ + Format: pointer.To(policyfragment.PolicyFragmentContentFormat(model.XmlFormat)), + }) + if err != nil && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + } + + if !response.WasNotFound(existing.HttpResponse) { + return metadata.ResourceRequiresImport(r.ResourceType(), id) + } + + parameters := policyfragment.PolicyFragmentContract{ + Properties: &policyfragment.PolicyFragmentContractProperties{ + Format: pointer.To(policyfragment.PolicyFragmentContentFormat(model.XmlFormat)), + Value: model.XmlContent, + }, + } + + if model.Description != "" { + parameters.Properties.Description = pointer.To(model.Description) + } + + if err := client.WorkspacePolicyFragmentCreateOrUpdateThenPoll(ctx, id, parameters, policyfragment.WorkspacePolicyFragmentCreateOrUpdateOperationOptions{}); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + return nil + }, + } +} + +func (r ApiManagementWorkspacePolicyFragmentResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.ApiManagement.PolicyFragmentClient_v2024_05_01 + + var model ApiManagementWorkspacePolicyFragmentModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + id, err := policyfragment.ParseWorkspacePolicyFragmentID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + resp, err := client.WorkspacePolicyFragmentGet(ctx, *id, policyfragment.WorkspacePolicyFragmentGetOperationOptions{ + Format: pointer.To(policyfragment.PolicyFragmentContentFormat(model.XmlFormat)), + }) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + if resp.Model == nil { + return fmt.Errorf("retrieving %s: `model` was nil", *id) + } + + if resp.Model.Properties == nil { + return fmt.Errorf("retrieving %s: `properties` was nil", *id) + } + + payload := resp.Model + if metadata.ResourceData.HasChange("description") { + payload.Properties.Description = pointer.To(model.Description) + } + + if metadata.ResourceData.HasChange("xml_content") { + payload.Properties.Value = model.XmlContent + } + + if metadata.ResourceData.HasChange("xml_format") { + payload.Properties.Format = pointer.To(policyfragment.PolicyFragmentContentFormat(model.XmlFormat)) + } + + if err := client.WorkspacePolicyFragmentCreateOrUpdateThenPoll(ctx, *id, *payload, policyfragment.WorkspacePolicyFragmentCreateOrUpdateOperationOptions{}); err != nil { + return fmt.Errorf("updating %s: %+v", *id, err) + } + + return nil + }, + } +} + +func (r ApiManagementWorkspacePolicyFragmentResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.ApiManagement.PolicyFragmentClient_v2024_05_01 + + id, err := policyfragment.ParseWorkspacePolicyFragmentID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + format := metadata.ResourceData.Get("xml_format").(string) + if format == "" { + format = string(policyfragment.PolicyFragmentContentFormatXml) + } + resp, err := client.WorkspacePolicyFragmentGet(ctx, *id, policyfragment.WorkspacePolicyFragmentGetOperationOptions{ + Format: pointer.To(policyfragment.PolicyFragmentContentFormat(format)), + }) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(*id) + } + + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + state := ApiManagementWorkspacePolicyFragmentModel{ + Name: id.PolicyFragmentName, + ApiManagementWorkspaceId: policyfragment.NewWorkspaceID(id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId).ID(), + } + + if model := resp.Model; model != nil { + if props := model.Properties; props != nil { + state.Description = pointer.From(props.Description) + state.XmlContent = props.Value + + // The API only returns `xml_format` when set to "rawxml"; the default "xml" is intentionally never returned. + format := policyfragment.PolicyFragmentContentFormatXml + if props.Format != nil { + format = pointer.From(props.Format) + } + state.XmlFormat = string(format) + } + } + + return metadata.Encode(&state) + }, + } +} + +func (r ApiManagementWorkspacePolicyFragmentResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.ApiManagement.PolicyFragmentClient_v2024_05_01 + + id, err := policyfragment.ParseWorkspacePolicyFragmentID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + if _, err := client.WorkspacePolicyFragmentDelete(ctx, *id, policyfragment.WorkspacePolicyFragmentDeleteOperationOptions{}); err != nil { + return fmt.Errorf("deleting %s: %+v", *id, err) + } + + return nil + }, + } +} diff --git a/internal/services/apimanagement/api_management_workspace_policy_fragment_resource_test.go b/internal/services/apimanagement/api_management_workspace_policy_fragment_resource_test.go new file mode 100644 index 000000000000..1dc8f5325cc9 --- /dev/null +++ b/internal/services/apimanagement/api_management_workspace_policy_fragment_resource_test.go @@ -0,0 +1,210 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package apimanagement_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type ApiManagementWorkspacePolicyFragmentTestResource struct{} + +func TestAccApiManagementWorkspacePolicyFragment_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_workspace_policy_fragment", "test") + r := ApiManagementWorkspacePolicyFragmentTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccApiManagementWorkspacePolicyFragment_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_workspace_policy_fragment", "test") + r := ApiManagementWorkspacePolicyFragmentTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccApiManagementWorkspacePolicyFragment_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_workspace_policy_fragment", "test") + r := ApiManagementWorkspacePolicyFragmentTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + // Because of API behavior, Workspace Policy Fragments are always imported as `xml`. + // As a result, the `xml_format` and `xml_content`properties should be ignored when set to `rawxml`. + data.ImportStep("xml_format", "xml_content"), + }) +} + +func TestAccApiManagementWorkspacePolicyFragment_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_api_management_workspace_policy_fragment", "test") + r := ApiManagementWorkspacePolicyFragmentTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + // Because of API behavior, Workspace Policy Fragments are always imported as `xml`. + // As a result, the `xml_format` and `xml_content`properties should be ignored when set to `rawxml`. + data.ImportStep("xml_format", "xml_content"), + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + // Because of API behavior, Workspace Policy Fragments are always imported as `xml`. + // As a result, the `xml_format` and `xml_content`properties should be ignored when set to `rawxml`. + data.ImportStep("xml_format", "xml_content"), + }) +} + +func (ApiManagementWorkspacePolicyFragmentTestResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := policyfragment.ParseWorkspacePolicyFragmentID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.ApiManagement.PolicyFragmentClient_v2024_05_01.WorkspacePolicyFragmentGet(ctx, *id, policyfragment.WorkspacePolicyFragmentGetOperationOptions{}) + if err != nil { + return nil, fmt.Errorf("retrieving %s: %+v", *id, err) + } + + return pointer.To(resp.Model != nil), nil +} + +func (r ApiManagementWorkspacePolicyFragmentTestResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_api_management_workspace_policy_fragment" "test" { + name = "acctestpolicyfragment%d" + api_management_workspace_id = azurerm_api_management_workspace.test.id + xml_content = file("testdata/api_management_policy_fragment_test_xml.xml") +} +`, r.template(data), data.RandomInteger) +} + +func (r ApiManagementWorkspacePolicyFragmentTestResource) requiresImport(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_api_management_workspace_policy_fragment" "import" { + name = azurerm_api_management_workspace_policy_fragment.test.name + api_management_workspace_id = azurerm_api_management_workspace_policy_fragment.test.api_management_workspace_id + xml_content = azurerm_api_management_workspace_policy_fragment.test.xml_content +} +`, r.basic(data)) +} + +func (r ApiManagementWorkspacePolicyFragmentTestResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_api_management_workspace_policy_fragment" "test" { + name = "acctestpolicyfragment%d" + api_management_workspace_id = azurerm_api_management_workspace.test.id + description = "A test policy fragment" + xml_format = "rawxml" + xml_content = file("testdata/api_management_policy_fragment_test_rawxml.xml") +} +`, r.template(data), data.RandomInteger) +} + +func (r ApiManagementWorkspacePolicyFragmentTestResource) update(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +%s + +resource "azurerm_api_management_workspace_policy_fragment" "test" { + name = "acctestpolicyfragment%d" + api_management_workspace_id = azurerm_api_management_workspace.test.id + description = "Updated policy fragment description" + xml_format = "xml" + xml_content = file("testdata/api_management_policy_fragment_test_xml.xml") +} +`, r.template(data), data.RandomInteger) +} + +func (ApiManagementWorkspacePolicyFragmentTestResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG-%d" + location = "%s" +} + +resource "azurerm_api_management" "test" { + name = "acctestAM-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + + sku_name = "Premium_1" +} + +resource "azurerm_api_management_workspace" "test" { + name = "acctestAMWorkspace-%d" + api_management_id = azurerm_api_management.test.id + display_name = "Test Workspace" + description = "Test workspace for policy fragments" +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} diff --git a/internal/services/apimanagement/client/client.go b/internal/services/apimanagement/client/client.go index 27ba70e04a17..87d56235b5b2 100644 --- a/internal/services/apimanagement/client/client.go +++ b/internal/services/apimanagement/client/client.go @@ -54,6 +54,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apigateway" "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementservice" "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/backend" + policyfragment_v2024_05_01 "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment" "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspace" "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspacepolicy" "github.com/hashicorp/terraform-provider-azurerm/internal/common" @@ -97,6 +98,7 @@ type Client struct { PolicyClient *policy.PolicyClient WorkspacePolicyClient *workspacepolicy.WorkspacePolicyClient PolicyFragmentClient *policyfragment.PolicyFragmentClient + PolicyFragmentClient_v2024_05_01 *policyfragment_v2024_05_01.PolicyFragmentClient ProductApisClient *productapi.ProductApiClient ProductGroupsClient *productgroup.ProductGroupClient ProductPoliciesClient *productpolicy.ProductPolicyClient @@ -335,6 +337,12 @@ func NewClient(o *common.ClientOptions) (*Client, error) { } o.Configure(policyFragmentClient.Client, o.Authorizers.ResourceManager) + policyFragmentClient_v2024_05_01, err := policyfragment_v2024_05_01.NewPolicyFragmentClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building Policy Fragment client: %+v", err) + } + o.Configure(policyFragmentClient_v2024_05_01.Client, o.Authorizers.ResourceManager) + productsClient, err := product.NewProductClientWithBaseURI(o.Environment.ResourceManager) if err != nil { return nil, fmt.Errorf("building Products client: %+v", err) @@ -451,6 +459,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { PolicyClient: policyClient, WorkspacePolicyClient: workspacePolicyClient, PolicyFragmentClient: policyFragmentClient, + PolicyFragmentClient_v2024_05_01: policyFragmentClient_v2024_05_01, ProductApisClient: productApisClient, ProductGroupsClient: productGroupsClient, ProductPoliciesClient: productPoliciesClient, diff --git a/internal/services/apimanagement/registration.go b/internal/services/apimanagement/registration.go index 6e9136b03fc3..8bc0c889015d 100644 --- a/internal/services/apimanagement/registration.go +++ b/internal/services/apimanagement/registration.go @@ -110,5 +110,7 @@ func (r Registration) Resources() []sdk.Resource { ApiManagementWorkspaceResource{}, ApiManagementWorkspacePolicyResource{}, ApiManagementStandaloneGatewayResource{}, + ApiManagementWorkspaceResource{}, + ApiManagementWorkspacePolicyFragmentResource{}, } } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/README.md new file mode 100644 index 000000000000..0294b12cdac5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/README.md @@ -0,0 +1,218 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment` Documentation + +The `policyfragment` SDK allows for interaction with Azure Resource Manager `apimanagement` (API Version `2024-05-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment" +``` + + +### Client Initialization + +```go +client := policyfragment.NewPolicyFragmentClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `PolicyFragmentClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "policyFragmentName") + +payload := policyfragment.PolicyFragmentContract{ + // ... +} + + +if err := client.CreateOrUpdateThenPoll(ctx, id, payload, policyfragment.DefaultCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `PolicyFragmentClient.Delete` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "policyFragmentName") + +read, err := client.Delete(ctx, id, policyfragment.DefaultDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.Get` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "policyFragmentName") + +read, err := client.Get(ctx, id, policyfragment.DefaultGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.GetEntityTag` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "policyFragmentName") + +read, err := client.GetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.ListByService` + +```go +ctx := context.TODO() +id := policyfragment.NewServiceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName") + +// alternatively `client.ListByService(ctx, id, policyfragment.DefaultListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.ListByServiceComplete(ctx, id, policyfragment.DefaultListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PolicyFragmentClient.ListReferences` + +```go +ctx := context.TODO() +id := policyfragment.NewPolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "policyFragmentName") + +// alternatively `client.ListReferences(ctx, id, policyfragment.DefaultListReferencesOperationOptions())` can be used to do batched pagination +items, err := client.ListReferencesComplete(ctx, id, policyfragment.DefaultListReferencesOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentCreateOrUpdate` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "workspaceId", "policyFragmentName") + +payload := policyfragment.PolicyFragmentContract{ + // ... +} + + +if err := client.WorkspacePolicyFragmentCreateOrUpdateThenPoll(ctx, id, payload, policyfragment.DefaultWorkspacePolicyFragmentCreateOrUpdateOperationOptions()); err != nil { + // handle the error +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentDelete` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "workspaceId", "policyFragmentName") + +read, err := client.WorkspacePolicyFragmentDelete(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentDeleteOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentGet` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "workspaceId", "policyFragmentName") + +read, err := client.WorkspacePolicyFragmentGet(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentGetEntityTag` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "workspaceId", "policyFragmentName") + +read, err := client.WorkspacePolicyFragmentGetEntityTag(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentListByService` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspaceID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "workspaceId") + +// alternatively `client.WorkspacePolicyFragmentListByService(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentListByServiceOperationOptions())` can be used to do batched pagination +items, err := client.WorkspacePolicyFragmentListByServiceComplete(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentListByServiceOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `PolicyFragmentClient.WorkspacePolicyFragmentListReferences` + +```go +ctx := context.TODO() +id := policyfragment.NewWorkspacePolicyFragmentID("12345678-1234-9876-4563-123456789012", "example-resource-group", "serviceName", "workspaceId", "policyFragmentName") + +// alternatively `client.WorkspacePolicyFragmentListReferences(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentListReferencesOperationOptions())` can be used to do batched pagination +items, err := client.WorkspacePolicyFragmentListReferencesComplete(ctx, id, policyfragment.DefaultWorkspacePolicyFragmentListReferencesOperationOptions()) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/client.go new file mode 100644 index 000000000000..d14dc4859918 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/client.go @@ -0,0 +1,26 @@ +package policyfragment + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyFragmentClient struct { + Client *resourcemanager.Client +} + +func NewPolicyFragmentClientWithBaseURI(sdkApi sdkEnv.Api) (*PolicyFragmentClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "policyfragment", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating PolicyFragmentClient: %+v", err) + } + + return &PolicyFragmentClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/constants.go new file mode 100644 index 000000000000..60aec2160bc8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/constants.go @@ -0,0 +1,51 @@ +package policyfragment + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyFragmentContentFormat string + +const ( + PolicyFragmentContentFormatRawxml PolicyFragmentContentFormat = "rawxml" + PolicyFragmentContentFormatXml PolicyFragmentContentFormat = "xml" +) + +func PossibleValuesForPolicyFragmentContentFormat() []string { + return []string{ + string(PolicyFragmentContentFormatRawxml), + string(PolicyFragmentContentFormatXml), + } +} + +func (s *PolicyFragmentContentFormat) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parsePolicyFragmentContentFormat(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parsePolicyFragmentContentFormat(input string) (*PolicyFragmentContentFormat, error) { + vals := map[string]PolicyFragmentContentFormat{ + "rawxml": PolicyFragmentContentFormatRawxml, + "xml": PolicyFragmentContentFormatXml, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := PolicyFragmentContentFormat(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment.go new file mode 100644 index 000000000000..5c3e062af198 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_policyfragment.go @@ -0,0 +1,139 @@ +package policyfragment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&PolicyFragmentId{}) +} + +var _ resourceids.ResourceId = &PolicyFragmentId{} + +// PolicyFragmentId is a struct representing the Resource ID for a Policy Fragment +type PolicyFragmentId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + PolicyFragmentName string +} + +// NewPolicyFragmentID returns a new PolicyFragmentId struct +func NewPolicyFragmentID(subscriptionId string, resourceGroupName string, serviceName string, policyFragmentName string) PolicyFragmentId { + return PolicyFragmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + PolicyFragmentName: policyFragmentName, + } +} + +// ParsePolicyFragmentID parses 'input' into a PolicyFragmentId +func ParsePolicyFragmentID(input string) (*PolicyFragmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicyFragmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicyFragmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParsePolicyFragmentIDInsensitively parses 'input' case-insensitively into a PolicyFragmentId +// note: this method should only be used for API response data and not user input +func ParsePolicyFragmentIDInsensitively(input string) (*PolicyFragmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&PolicyFragmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := PolicyFragmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *PolicyFragmentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.PolicyFragmentName, ok = input.Parsed["policyFragmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "policyFragmentName", input) + } + + return nil +} + +// ValidatePolicyFragmentID checks that 'input' can be parsed as a Policy Fragment ID +func ValidatePolicyFragmentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParsePolicyFragmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Policy Fragment ID +func (id PolicyFragmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/policyFragments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.PolicyFragmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Policy Fragment ID +func (id PolicyFragmentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceName"), + resourceids.StaticSegment("staticPolicyFragments", "policyFragments", "policyFragments"), + resourceids.UserSpecifiedSegment("policyFragmentName", "policyFragmentName"), + } +} + +// String returns a human-readable description of this Policy Fragment ID +func (id PolicyFragmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Policy Fragment Name: %q", id.PolicyFragmentName), + } + return fmt.Sprintf("Policy Fragment (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_service.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_service.go new file mode 100644 index 000000000000..7350808ee976 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_service.go @@ -0,0 +1,130 @@ +package policyfragment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&ServiceId{}) +} + +var _ resourceids.ResourceId = &ServiceId{} + +// ServiceId is a struct representing the Resource ID for a Service +type ServiceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string +} + +// NewServiceID returns a new ServiceId struct +func NewServiceID(subscriptionId string, resourceGroupName string, serviceName string) ServiceId { + return ServiceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + } +} + +// ParseServiceID parses 'input' into a ServiceId +func ParseServiceID(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseServiceIDInsensitively parses 'input' case-insensitively into a ServiceId +// note: this method should only be used for API response data and not user input +func ParseServiceIDInsensitively(input string) (*ServiceId, error) { + parser := resourceids.NewParserFromResourceIdType(&ServiceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := ServiceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *ServiceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + return nil +} + +// ValidateServiceID checks that 'input' can be parsed as a Service ID +func ValidateServiceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseServiceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Service ID +func (id ServiceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Service ID +func (id ServiceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceName"), + } +} + +// String returns a human-readable description of this Service ID +func (id ServiceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + } + return fmt.Sprintf("Service (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace.go new file mode 100644 index 000000000000..465b8277f768 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspace.go @@ -0,0 +1,139 @@ +package policyfragment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspaceId{}) +} + +var _ resourceids.ResourceId = &WorkspaceId{} + +// WorkspaceId is a struct representing the Resource ID for a Workspace +type WorkspaceId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string +} + +// NewWorkspaceID returns a new WorkspaceId struct +func NewWorkspaceID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string) WorkspaceId { + return WorkspaceId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + } +} + +// ParseWorkspaceID parses 'input' into a WorkspaceId +func ParseWorkspaceID(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspaceIDInsensitively parses 'input' case-insensitively into a WorkspaceId +// note: this method should only be used for API response data and not user input +func ParseWorkspaceIDInsensitively(input string) (*WorkspaceId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspaceId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspaceId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspaceId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + return nil +} + +// ValidateWorkspaceID checks that 'input' can be parsed as a Workspace ID +func ValidateWorkspaceID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspaceID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace ID +func (id WorkspaceId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace ID +func (id WorkspaceId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceName"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceId"), + } +} + +// String returns a human-readable description of this Workspace ID +func (id WorkspaceId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + } + return fmt.Sprintf("Workspace (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment.go new file mode 100644 index 000000000000..3449e07796e4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/id_workspacepolicyfragment.go @@ -0,0 +1,148 @@ +package policyfragment + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/recaser" + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +func init() { + recaser.RegisterResourceId(&WorkspacePolicyFragmentId{}) +} + +var _ resourceids.ResourceId = &WorkspacePolicyFragmentId{} + +// WorkspacePolicyFragmentId is a struct representing the Resource ID for a Workspace Policy Fragment +type WorkspacePolicyFragmentId struct { + SubscriptionId string + ResourceGroupName string + ServiceName string + WorkspaceId string + PolicyFragmentName string +} + +// NewWorkspacePolicyFragmentID returns a new WorkspacePolicyFragmentId struct +func NewWorkspacePolicyFragmentID(subscriptionId string, resourceGroupName string, serviceName string, workspaceId string, policyFragmentName string) WorkspacePolicyFragmentId { + return WorkspacePolicyFragmentId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ServiceName: serviceName, + WorkspaceId: workspaceId, + PolicyFragmentName: policyFragmentName, + } +} + +// ParseWorkspacePolicyFragmentID parses 'input' into a WorkspacePolicyFragmentId +func ParseWorkspacePolicyFragmentID(input string) (*WorkspacePolicyFragmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspacePolicyFragmentId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspacePolicyFragmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseWorkspacePolicyFragmentIDInsensitively parses 'input' case-insensitively into a WorkspacePolicyFragmentId +// note: this method should only be used for API response data and not user input +func ParseWorkspacePolicyFragmentIDInsensitively(input string) (*WorkspacePolicyFragmentId, error) { + parser := resourceids.NewParserFromResourceIdType(&WorkspacePolicyFragmentId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := WorkspacePolicyFragmentId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *WorkspacePolicyFragmentId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.ServiceName, ok = input.Parsed["serviceName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "serviceName", input) + } + + if id.WorkspaceId, ok = input.Parsed["workspaceId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "workspaceId", input) + } + + if id.PolicyFragmentName, ok = input.Parsed["policyFragmentName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "policyFragmentName", input) + } + + return nil +} + +// ValidateWorkspacePolicyFragmentID checks that 'input' can be parsed as a Workspace Policy Fragment ID +func ValidateWorkspacePolicyFragmentID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseWorkspacePolicyFragmentID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Workspace Policy Fragment ID +func (id WorkspacePolicyFragmentId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ApiManagement/service/%s/workspaces/%s/policyFragments/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ServiceName, id.WorkspaceId, id.PolicyFragmentName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Workspace Policy Fragment ID +func (id WorkspacePolicyFragmentId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftApiManagement", "Microsoft.ApiManagement", "Microsoft.ApiManagement"), + resourceids.StaticSegment("staticService", "service", "service"), + resourceids.UserSpecifiedSegment("serviceName", "serviceName"), + resourceids.StaticSegment("staticWorkspaces", "workspaces", "workspaces"), + resourceids.UserSpecifiedSegment("workspaceId", "workspaceId"), + resourceids.StaticSegment("staticPolicyFragments", "policyFragments", "policyFragments"), + resourceids.UserSpecifiedSegment("policyFragmentName", "policyFragmentName"), + } +} + +// String returns a human-readable description of this Workspace Policy Fragment ID +func (id WorkspacePolicyFragmentId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Service Name: %q", id.ServiceName), + fmt.Sprintf("Workspace: %q", id.WorkspaceId), + fmt.Sprintf("Policy Fragment Name: %q", id.PolicyFragmentName), + } + return fmt.Sprintf("Workspace Policy Fragment (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_createorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_createorupdate.go new file mode 100644 index 000000000000..1b3da31951e0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_createorupdate.go @@ -0,0 +1,104 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PolicyFragmentContract +} + +type CreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCreateOrUpdateOperationOptions() CreateOrUpdateOperationOptions { + return CreateOrUpdateOperationOptions{} +} + +func (o CreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o CreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CreateOrUpdate ... +func (c PolicyFragmentClient) CreateOrUpdate(ctx context.Context, id PolicyFragmentId, input PolicyFragmentContract, options CreateOrUpdateOperationOptions) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// CreateOrUpdateThenPoll performs CreateOrUpdate then polls until it's completed +func (c PolicyFragmentClient) CreateOrUpdateThenPoll(ctx context.Context, id PolicyFragmentId, input PolicyFragmentContract, options CreateOrUpdateOperationOptions) error { + result, err := c.CreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing CreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after CreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_delete.go new file mode 100644 index 000000000000..219af78163c6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_delete.go @@ -0,0 +1,77 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type DeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type DeleteOperationOptions struct { + IfMatch *string +} + +func DefaultDeleteOperationOptions() DeleteOperationOptions { + return DeleteOperationOptions{} +} + +func (o DeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o DeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o DeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// Delete ... +func (c PolicyFragmentClient) Delete(ctx context.Context, id PolicyFragmentId, options DeleteOperationOptions) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_get.go new file mode 100644 index 000000000000..12ac1b4fbf31 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_get.go @@ -0,0 +1,83 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyFragmentContract +} + +type GetOperationOptions struct { + Format *PolicyFragmentContentFormat +} + +func DefaultGetOperationOptions() GetOperationOptions { + return GetOperationOptions{} +} + +func (o GetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o GetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o GetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// Get ... +func (c PolicyFragmentClient) Get(ctx context.Context, id PolicyFragmentId, options GetOperationOptions) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PolicyFragmentContract + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_getentitytag.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_getentitytag.go new file mode 100644 index 000000000000..1d3b811f0e07 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_getentitytag.go @@ -0,0 +1,46 @@ +package policyfragment + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type GetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// GetEntityTag ... +func (c PolicyFragmentClient) GetEntityTag(ctx context.Context, id PolicyFragmentId) (result GetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_listbyservice.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_listbyservice.go new file mode 100644 index 000000000000..c6ab48e11acb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_listbyservice.go @@ -0,0 +1,146 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyFragmentContract +} + +type ListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyFragmentContract +} + +type ListByServiceOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultListByServiceOperationOptions() ListByServiceOperationOptions { + return ListByServiceOperationOptions{} +} + +func (o ListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListByService ... +func (c PolicyFragmentClient) ListByService(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (result ListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &ListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/policyFragments", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PolicyFragmentContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListByServiceComplete retrieves all the results into a single object +func (c PolicyFragmentClient) ListByServiceComplete(ctx context.Context, id ServiceId, options ListByServiceOperationOptions) (ListByServiceCompleteResult, error) { + return c.ListByServiceCompleteMatchingPredicate(ctx, id, options, PolicyFragmentContractOperationPredicate{}) +} + +// ListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyFragmentClient) ListByServiceCompleteMatchingPredicate(ctx context.Context, id ServiceId, options ListByServiceOperationOptions, predicate PolicyFragmentContractOperationPredicate) (result ListByServiceCompleteResult, err error) { + items := make([]PolicyFragmentContract, 0) + + resp, err := c.ListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_listreferences.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_listreferences.go new file mode 100644 index 000000000000..d513c06b276c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_listreferences.go @@ -0,0 +1,138 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListReferencesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type ListReferencesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type ListReferencesOperationOptions struct { + Skip *int64 + Top *int64 +} + +func DefaultListReferencesOperationOptions() ListReferencesOperationOptions { + return ListReferencesOperationOptions{} +} + +func (o ListReferencesOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o ListReferencesOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o ListReferencesOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type ListReferencesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListReferencesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// ListReferences ... +func (c PolicyFragmentClient) ListReferences(ctx context.Context, id PolicyFragmentId, options ListReferencesOperationOptions) (result ListReferencesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Pager: &ListReferencesCustomPager{}, + Path: fmt.Sprintf("%s/listReferences", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListReferencesComplete retrieves all the results into a single object +func (c PolicyFragmentClient) ListReferencesComplete(ctx context.Context, id PolicyFragmentId, options ListReferencesOperationOptions) (ListReferencesCompleteResult, error) { + return c.ListReferencesCompleteMatchingPredicate(ctx, id, options, ResourceOperationPredicate{}) +} + +// ListReferencesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyFragmentClient) ListReferencesCompleteMatchingPredicate(ctx context.Context, id PolicyFragmentId, options ListReferencesOperationOptions, predicate ResourceOperationPredicate) (result ListReferencesCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.ListReferences(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = ListReferencesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentcreateorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentcreateorupdate.go new file mode 100644 index 000000000000..72b4a0c9c6c7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentcreateorupdate.go @@ -0,0 +1,104 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/client/pollers" + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePolicyFragmentCreateOrUpdateOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData + Model *PolicyFragmentContract +} + +type WorkspacePolicyFragmentCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspacePolicyFragmentCreateOrUpdateOperationOptions() WorkspacePolicyFragmentCreateOrUpdateOperationOptions { + return WorkspacePolicyFragmentCreateOrUpdateOperationOptions{} +} + +func (o WorkspacePolicyFragmentCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspacePolicyFragmentCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o WorkspacePolicyFragmentCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspacePolicyFragmentCreateOrUpdate ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentCreateOrUpdate(ctx context.Context, id WorkspacePolicyFragmentId, input PolicyFragmentContract, options WorkspacePolicyFragmentCreateOrUpdateOperationOptions) (result WorkspacePolicyFragmentCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// WorkspacePolicyFragmentCreateOrUpdateThenPoll performs WorkspacePolicyFragmentCreateOrUpdate then polls until it's completed +func (c PolicyFragmentClient) WorkspacePolicyFragmentCreateOrUpdateThenPoll(ctx context.Context, id WorkspacePolicyFragmentId, input PolicyFragmentContract, options WorkspacePolicyFragmentCreateOrUpdateOperationOptions) error { + result, err := c.WorkspacePolicyFragmentCreateOrUpdate(ctx, id, input, options) + if err != nil { + return fmt.Errorf("performing WorkspacePolicyFragmentCreateOrUpdate: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after WorkspacePolicyFragmentCreateOrUpdate: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentdelete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentdelete.go new file mode 100644 index 000000000000..4afe42619067 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentdelete.go @@ -0,0 +1,77 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePolicyFragmentDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +type WorkspacePolicyFragmentDeleteOperationOptions struct { + IfMatch *string +} + +func DefaultWorkspacePolicyFragmentDeleteOperationOptions() WorkspacePolicyFragmentDeleteOperationOptions { + return WorkspacePolicyFragmentDeleteOperationOptions{} +} + +func (o WorkspacePolicyFragmentDeleteOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o WorkspacePolicyFragmentDeleteOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o WorkspacePolicyFragmentDeleteOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// WorkspacePolicyFragmentDelete ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentDelete(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentDeleteOperationOptions) (result WorkspacePolicyFragmentDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentget.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentget.go new file mode 100644 index 000000000000..11e23a111e51 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentget.go @@ -0,0 +1,83 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePolicyFragmentGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *PolicyFragmentContract +} + +type WorkspacePolicyFragmentGetOperationOptions struct { + Format *PolicyFragmentContentFormat +} + +func DefaultWorkspacePolicyFragmentGetOperationOptions() WorkspacePolicyFragmentGetOperationOptions { + return WorkspacePolicyFragmentGetOperationOptions{} +} + +func (o WorkspacePolicyFragmentGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspacePolicyFragmentGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o WorkspacePolicyFragmentGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Format != nil { + out.Append("format", fmt.Sprintf("%v", *o.Format)) + } + return &out +} + +// WorkspacePolicyFragmentGet ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentGet(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentGetOperationOptions) (result WorkspacePolicyFragmentGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var model PolicyFragmentContract + result.Model = &model + if err = resp.Unmarshal(result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentgetentitytag.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentgetentitytag.go new file mode 100644 index 000000000000..c2c987854f8c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentgetentitytag.go @@ -0,0 +1,46 @@ +package policyfragment + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePolicyFragmentGetEntityTagOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// WorkspacePolicyFragmentGetEntityTag ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentGetEntityTag(ctx context.Context, id WorkspacePolicyFragmentId) (result WorkspacePolicyFragmentGetEntityTagOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodHead, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistbyservice.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistbyservice.go new file mode 100644 index 000000000000..d5ef3e26541b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistbyservice.go @@ -0,0 +1,146 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePolicyFragmentListByServiceOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]PolicyFragmentContract +} + +type WorkspacePolicyFragmentListByServiceCompleteResult struct { + LatestHttpResponse *http.Response + Items []PolicyFragmentContract +} + +type WorkspacePolicyFragmentListByServiceOperationOptions struct { + Filter *string + Orderby *string + Skip *int64 + Top *int64 +} + +func DefaultWorkspacePolicyFragmentListByServiceOperationOptions() WorkspacePolicyFragmentListByServiceOperationOptions { + return WorkspacePolicyFragmentListByServiceOperationOptions{} +} + +func (o WorkspacePolicyFragmentListByServiceOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspacePolicyFragmentListByServiceOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o WorkspacePolicyFragmentListByServiceOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Filter != nil { + out.Append("$filter", fmt.Sprintf("%v", *o.Filter)) + } + if o.Orderby != nil { + out.Append("$orderby", fmt.Sprintf("%v", *o.Orderby)) + } + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspacePolicyFragmentListByServiceCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspacePolicyFragmentListByServiceCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspacePolicyFragmentListByService ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentListByService(ctx context.Context, id WorkspaceId, options WorkspacePolicyFragmentListByServiceOperationOptions) (result WorkspacePolicyFragmentListByServiceOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + OptionsObject: options, + Pager: &WorkspacePolicyFragmentListByServiceCustomPager{}, + Path: fmt.Sprintf("%s/policyFragments", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]PolicyFragmentContract `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspacePolicyFragmentListByServiceComplete retrieves all the results into a single object +func (c PolicyFragmentClient) WorkspacePolicyFragmentListByServiceComplete(ctx context.Context, id WorkspaceId, options WorkspacePolicyFragmentListByServiceOperationOptions) (WorkspacePolicyFragmentListByServiceCompleteResult, error) { + return c.WorkspacePolicyFragmentListByServiceCompleteMatchingPredicate(ctx, id, options, PolicyFragmentContractOperationPredicate{}) +} + +// WorkspacePolicyFragmentListByServiceCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyFragmentClient) WorkspacePolicyFragmentListByServiceCompleteMatchingPredicate(ctx context.Context, id WorkspaceId, options WorkspacePolicyFragmentListByServiceOperationOptions, predicate PolicyFragmentContractOperationPredicate) (result WorkspacePolicyFragmentListByServiceCompleteResult, err error) { + items := make([]PolicyFragmentContract, 0) + + resp, err := c.WorkspacePolicyFragmentListByService(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspacePolicyFragmentListByServiceCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistreferences.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistreferences.go new file mode 100644 index 000000000000..9a7b1e52677d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/method_workspacepolicyfragmentlistreferences.go @@ -0,0 +1,138 @@ +package policyfragment + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type WorkspacePolicyFragmentListReferencesOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]Resource +} + +type WorkspacePolicyFragmentListReferencesCompleteResult struct { + LatestHttpResponse *http.Response + Items []Resource +} + +type WorkspacePolicyFragmentListReferencesOperationOptions struct { + Skip *int64 + Top *int64 +} + +func DefaultWorkspacePolicyFragmentListReferencesOperationOptions() WorkspacePolicyFragmentListReferencesOperationOptions { + return WorkspacePolicyFragmentListReferencesOperationOptions{} +} + +func (o WorkspacePolicyFragmentListReferencesOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + + return &out +} + +func (o WorkspacePolicyFragmentListReferencesOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + + return &out +} + +func (o WorkspacePolicyFragmentListReferencesOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + if o.Skip != nil { + out.Append("$skip", fmt.Sprintf("%v", *o.Skip)) + } + if o.Top != nil { + out.Append("$top", fmt.Sprintf("%v", *o.Top)) + } + return &out +} + +type WorkspacePolicyFragmentListReferencesCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *WorkspacePolicyFragmentListReferencesCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// WorkspacePolicyFragmentListReferences ... +func (c PolicyFragmentClient) WorkspacePolicyFragmentListReferences(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentListReferencesOperationOptions) (result WorkspacePolicyFragmentListReferencesOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPost, + OptionsObject: options, + Pager: &WorkspacePolicyFragmentListReferencesCustomPager{}, + Path: fmt.Sprintf("%s/listReferences", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]Resource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// WorkspacePolicyFragmentListReferencesComplete retrieves all the results into a single object +func (c PolicyFragmentClient) WorkspacePolicyFragmentListReferencesComplete(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentListReferencesOperationOptions) (WorkspacePolicyFragmentListReferencesCompleteResult, error) { + return c.WorkspacePolicyFragmentListReferencesCompleteMatchingPredicate(ctx, id, options, ResourceOperationPredicate{}) +} + +// WorkspacePolicyFragmentListReferencesCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c PolicyFragmentClient) WorkspacePolicyFragmentListReferencesCompleteMatchingPredicate(ctx context.Context, id WorkspacePolicyFragmentId, options WorkspacePolicyFragmentListReferencesOperationOptions, predicate ResourceOperationPredicate) (result WorkspacePolicyFragmentListReferencesCompleteResult, err error) { + items := make([]Resource, 0) + + resp, err := c.WorkspacePolicyFragmentListReferences(ctx, id, options) + if err != nil { + result.LatestHttpResponse = resp.HttpResponse + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = WorkspacePolicyFragmentListReferencesCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontract.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontract.go new file mode 100644 index 000000000000..d00e93210c73 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontract.go @@ -0,0 +1,11 @@ +package policyfragment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyFragmentContract struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *PolicyFragmentContractProperties `json:"properties,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontractproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontractproperties.go new file mode 100644 index 000000000000..eaf08d280b9b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_policyfragmentcontractproperties.go @@ -0,0 +1,11 @@ +package policyfragment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyFragmentContractProperties struct { + Description *string `json:"description,omitempty"` + Format *PolicyFragmentContentFormat `json:"format,omitempty"` + ProvisioningState *string `json:"provisioningState,omitempty"` + Value string `json:"value"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_resource.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_resource.go new file mode 100644 index 000000000000..d8c4cfe7c03d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/model_resource.go @@ -0,0 +1,10 @@ +package policyfragment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Resource struct { + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/predicates.go new file mode 100644 index 000000000000..2850f0aee3c2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/predicates.go @@ -0,0 +1,50 @@ +package policyfragment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type PolicyFragmentContractOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p PolicyFragmentContractOperationPredicate) Matches(input PolicyFragmentContract) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} + +type ResourceOperationPredicate struct { + Id *string + Name *string + Type *string +} + +func (p ResourceOperationPredicate) Matches(input Resource) bool { + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/version.go new file mode 100644 index 000000000000..3e145bb0b6d3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment/version.go @@ -0,0 +1,10 @@ +package policyfragment + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2024-05-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/policyfragment/2024-05-01" +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 8c6ed35deb0d..c29c5e232806 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -225,6 +225,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2022-08-01/user github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apigateway github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/apimanagementservice github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/backend +github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/policyfragment github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspace github.com/hashicorp/go-azure-sdk/resource-manager/apimanagement/2024-05-01/workspacepolicy github.com/hashicorp/go-azure-sdk/resource-manager/appconfiguration/2024-05-01/configurationstores diff --git a/website/docs/r/api_management_workspace_policy_fragment.html.markdown b/website/docs/r/api_management_workspace_policy_fragment.html.markdown new file mode 100644 index 000000000000..794bd6ddcfc5 --- /dev/null +++ b/website/docs/r/api_management_workspace_policy_fragment.html.markdown @@ -0,0 +1,91 @@ +--- +subcategory: "API Management" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_api_management_workspace_policy_fragment" +description: |- + Manages an API Management Workspace Policy Fragment. +--- + +# azurerm_api_management_workspace_policy_fragment + +Manages an API Management Workspace Policy Fragment. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_api_management" "example" { + name = "example-apim" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + publisher_name = "pub1" + publisher_email = "pub1@email.com" + + sku_name = "Premium_1" +} + +resource "azurerm_api_management_workspace" "example" { + name = "example-workspace" + api_management_id = azurerm_api_management.example.id + display_name = "Example Workspace" + description = "Example API Management Workspace" +} + +resource "azurerm_api_management_workspace_policy_fragment" "example" { + name = "example-policy-fragment" + api_management_workspace_id = azurerm_api_management_workspace.example.id + xml_format = "xml" + xml_content = file("policy-fragment-1.xml") +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the API Management Workspace Policy Fragment. Changing this forces a new resource to be created. + +* `api_management_workspace_id` - (Required) Specifies the ID of the API Management Workspace. Changing this forces a new resource to be created. + +* `xml_content` - (Required) Specifies the XML content of the API Management Workspace Policy Fragment. + +--- + +* `xml_format` - (Optional) Specifies the XML format of the API Management Workspace Policy Fragment. Possible values are `xml` or `rawxml`. Defaults to `xml`. + +* `description` - (Optional) Specifies the description for of the API Management Workspace Policy Fragment. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the API Management Workspace Policy Fragment. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the API Management Workspace Policy Fragment. +* `read` - (Defaults to 5 minutes) Used when retrieving the API Management Workspace Policy Fragment. +* `update` - (Defaults to 30 minutes) Used when updating the API Management Workspace Policy Fragment. +* `delete` - (Defaults to 30 minutes) Used when deleting the API Management Workspace Policy Fragment. + +## Import + +API Management Workspace Policy Fragments can be imported using the `resource id`, e.g. + +~> **Note:** Due to the behaviour of the API, API Management Workspace Policy Fragments can only be imported as `xml`, but can be updated to the desired format after importing. + +```shell +terraform import azurerm_api_management_workspace_policy_fragment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/instance1/workspaces/workspace1/policyFragments/policyFragment1 +``` + +## API Providers + +This resource uses the following Azure API Providers: + +* `Microsoft.ApiManagement` - 2024-05-01 From d5c9136b6e6e91c33623084c6d8c1b4325a3ce6a Mon Sep 17 00:00:00 2001 From: elena Date: Tue, 30 Sep 2025 14:06:01 +0800 Subject: [PATCH 2/2] fix comments --- ...pi_management_workspace_policy_fragment_resource.go | 10 +++++----- internal/services/apimanagement/registration.go | 1 - ..._management_workspace_policy_fragment.html.markdown | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/services/apimanagement/api_management_workspace_policy_fragment_resource.go b/internal/services/apimanagement/api_management_workspace_policy_fragment_resource.go index 7af197edcb9c..825017a727c3 100644 --- a/internal/services/apimanagement/api_management_workspace_policy_fragment_resource.go +++ b/internal/services/apimanagement/api_management_workspace_policy_fragment_resource.go @@ -54,17 +54,17 @@ func (r ApiManagementWorkspacePolicyFragmentResource) Arguments() map[string]*pl DiffSuppressFunc: XmlWhitespaceDiffSuppress, }, - "xml_format": { + "description": { Type: pluginsdk.TypeString, Optional: true, - Default: string(policyfragment.PolicyFragmentContentFormatXml), - ValidateFunc: validation.StringInSlice(policyfragment.PossibleValuesForPolicyFragmentContentFormat(), false), + ValidateFunc: validation.StringIsNotEmpty, }, - "description": { + "xml_format": { Type: pluginsdk.TypeString, Optional: true, - ValidateFunc: validation.StringIsNotEmpty, + Default: string(policyfragment.PolicyFragmentContentFormatXml), + ValidateFunc: validation.StringInSlice(policyfragment.PossibleValuesForPolicyFragmentContentFormat(), false), }, } } diff --git a/internal/services/apimanagement/registration.go b/internal/services/apimanagement/registration.go index 8bc0c889015d..241bf6df3f61 100644 --- a/internal/services/apimanagement/registration.go +++ b/internal/services/apimanagement/registration.go @@ -110,7 +110,6 @@ func (r Registration) Resources() []sdk.Resource { ApiManagementWorkspaceResource{}, ApiManagementWorkspacePolicyResource{}, ApiManagementStandaloneGatewayResource{}, - ApiManagementWorkspaceResource{}, ApiManagementWorkspacePolicyFragmentResource{}, } } diff --git a/website/docs/r/api_management_workspace_policy_fragment.html.markdown b/website/docs/r/api_management_workspace_policy_fragment.html.markdown index 794bd6ddcfc5..e971621d5c06 100644 --- a/website/docs/r/api_management_workspace_policy_fragment.html.markdown +++ b/website/docs/r/api_management_workspace_policy_fragment.html.markdown @@ -55,9 +55,9 @@ The following arguments are supported: --- -* `xml_format` - (Optional) Specifies the XML format of the API Management Workspace Policy Fragment. Possible values are `xml` or `rawxml`. Defaults to `xml`. +* `description` - (Optional) Specifies the description for the API Management Workspace Policy Fragment. -* `description` - (Optional) Specifies the description for of the API Management Workspace Policy Fragment. +* `xml_format` - (Optional) Specifies the XML format of the API Management Workspace Policy Fragment. Possible values are `xml` or `rawxml`. Defaults to `xml`. ## Attributes Reference