diff --git a/internal/services/cognitive/client/client.go b/internal/services/cognitive/client/client.go index 1c3b1b1458df..6a4e456dbeb7 100644 --- a/internal/services/cognitive/client/client.go +++ b/internal/services/cognitive/client/client.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/cognitiveservicesaccounts" "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/deployments" "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raiblocklists" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies" "github.com/hashicorp/terraform-provider-azurerm/internal/common" ) @@ -16,6 +17,7 @@ type Client struct { AccountsClient *cognitiveservicesaccounts.CognitiveServicesAccountsClient DeploymentsClient *deployments.DeploymentsClient RaiBlocklistsClient *raiblocklists.RaiBlocklistsClient + RaiPoliciesClient *raipolicies.RaiPoliciesClient } func NewClient(o *common.ClientOptions) (*Client, error) { @@ -31,6 +33,12 @@ func NewClient(o *common.ClientOptions) (*Client, error) { } o.Configure(deploymentsClient.Client, o.Authorizers.ResourceManager) + raiPoliciesClient, err := raipolicies.NewRaiPoliciesClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building Rai Policies client: %+v", err) + } + o.Configure(raiPoliciesClient.Client, o.Authorizers.ResourceManager) + raiBlobklistsClient, err := raiblocklists.NewRaiBlocklistsClientWithBaseURI(o.Environment.ResourceManager) if err != nil { return nil, fmt.Errorf("building Rai Blocklists client: %+v", err) @@ -41,5 +49,6 @@ func NewClient(o *common.ClientOptions) (*Client, error) { AccountsClient: accountsClient, DeploymentsClient: deploymentsClient, RaiBlocklistsClient: raiBlobklistsClient, + RaiPoliciesClient: raiPoliciesClient, }, nil } diff --git a/internal/services/cognitive/cognitive_account_rai_policy_resource.go b/internal/services/cognitive/cognitive_account_rai_policy_resource.go new file mode 100644 index 000000000000..a6a90cc736d5 --- /dev/null +++ b/internal/services/cognitive/cognitive_account_rai_policy_resource.go @@ -0,0 +1,338 @@ +package cognitive + +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/cognitive/2024-10-01/raipolicies" + "github.com/hashicorp/terraform-provider-azurerm/internal/locks" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" +) + +var _ sdk.ResourceWithUpdate = &CognitiveAccountRaiPolicyResource{} + +type CognitiveAccountRaiPolicyResource struct{} + +type AccountRaiPolicyContentFilter struct { + Name string `tfschema:"name"` + FilterEnabled bool `tfschema:"filter_enabled"` + BlockEnabled bool `tfschema:"block_enabled"` + SeverityThreshold string `tfschema:"severity_threshold"` + Source string `tfschema:"source"` +} + +type AccountRaiPolicyCustomBlock struct { + Id string `tfschema:"rai_blocklist_id"` + BlockEnabled bool `tfschema:"block_enabled"` + Source string `tfschema:"source"` +} + +type AccountRaiPolicyResourceModel struct { + Name string `tfschema:"name"` + AccountId string `tfschema:"cognitive_account_id"` + BasePolicyName string `tfschema:"base_policy_name"` + ContentFilter []AccountRaiPolicyContentFilter `tfschema:"content_filter"` + Mode string `tfschema:"mode"` + Tags map[string]string `tfschema:"tags"` +} + +func (r CognitiveAccountRaiPolicyResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "cognitive_account_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: raipolicies.ValidateAccountID, + }, + + "base_policy_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "content_filter": { + Type: pluginsdk.TypeList, + Required: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "filter_enabled": { + Type: pluginsdk.TypeBool, + Required: true, + }, + "block_enabled": { + Type: pluginsdk.TypeBool, + Required: true, + }, + "severity_threshold": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(raipolicies.PossibleValuesForContentLevel(), false), + }, + "source": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: validation.StringInSlice(raipolicies.PossibleValuesForRaiPolicyContentSource(), false), + }, + }, + }, + }, + + "mode": { + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice(raipolicies.PossibleValuesForRaiPolicyMode(), false), + }, + + "tags": commonschema.Tags(), + } +} + +func (r CognitiveAccountRaiPolicyResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (r CognitiveAccountRaiPolicyResource) ModelObject() interface{} { + return &AccountRaiPolicyResourceModel{} +} + +func (r CognitiveAccountRaiPolicyResource) ResourceType() string { + return "azurerm_cognitive_account_rai_policy" +} + +func (r CognitiveAccountRaiPolicyResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Cognitive.RaiPoliciesClient + subscriptionId := metadata.Client.Account.SubscriptionId + + var model AccountRaiPolicyResourceModel + if err := metadata.Decode(&model); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + cognitiveAccountId, err := raipolicies.ParseAccountID(model.AccountId) + if err != nil { + return err + } + + id := raipolicies.NewRaiPolicyID(subscriptionId, cognitiveAccountId.ResourceGroupName, cognitiveAccountId.AccountName, model.Name) + existing, err := client.Get(ctx, id) + if err != nil { + if !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) + } + + locks.ByID(cognitiveAccountId.ID()) + defer locks.UnlockByID(cognitiveAccountId.ID()) + + raiPolicy := raipolicies.RaiPolicy{ + Name: pointer.To(model.Name), + Properties: &raipolicies.RaiPolicyProperties{ + BasePolicyName: pointer.To(model.BasePolicyName), + ContentFilters: expandRaiPolicyContentFilters(model.ContentFilter), + }, + Tags: pointer.To(model.Tags), + } + + if model.Mode != "" { + raiPolicy.Properties.Mode = pointer.To(raipolicies.RaiPolicyMode(model.Mode)) + } + + if _, err := client.CreateOrUpdate(ctx, id, raiPolicy); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + + return nil + }, + } +} + +func (r CognitiveAccountRaiPolicyResource) Read() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Cognitive.RaiPoliciesClient + + id, err := raipolicies.ParseRaiPolicyID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + cognitiveAccountId := raipolicies.NewAccountID(id.SubscriptionId, id.ResourceGroupName, id.AccountName) + + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return metadata.MarkAsGone(id) + } + return fmt.Errorf("retrieving %s: %+v", id, err) + } + + state := AccountRaiPolicyResourceModel{ + Name: id.RaiPolicyName, + AccountId: cognitiveAccountId.ID(), + } + + if model := resp.Model; model != nil { + state.Tags = pointer.From(model.Tags) + + if props := model.Properties; props != nil { + state.BasePolicyName = pointer.From(props.BasePolicyName) + state.ContentFilter = flattenRaiPolicyContentFilters(props.ContentFilters) + state.Mode = string(pointer.From(props.Mode)) + } + } + + return metadata.Encode(&state) + }, + } +} + +func (r CognitiveAccountRaiPolicyResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Cognitive.RaiPoliciesClient + + id, err := raipolicies.ParseRaiPolicyID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + var model AccountRaiPolicyResourceModel + if err := metadata.Decode(&model); err != nil { + return err + } + + existing, err := client.Get(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + if existing.Model == nil { + return fmt.Errorf("retrieving %s: `model` was nil", id) + } + + if existing.Model.Properties == nil { + return fmt.Errorf("retrieving %s: `properties` was nil", id) + } + + cognitiveAccountId := raipolicies.NewAccountID(id.SubscriptionId, id.ResourceGroupName, id.AccountName) + + locks.ByID(cognitiveAccountId.ID()) + defer locks.UnlockByID(cognitiveAccountId.ID()) + + payload := existing.Model + + if metadata.ResourceData.HasChange("content_filter") { + payload.Properties.ContentFilters = expandRaiPolicyContentFilters(model.ContentFilter) + } + + if metadata.ResourceData.HasChange("mode") { + payload.Properties.Mode = pointer.To(raipolicies.RaiPolicyMode(model.Mode)) + } + + if metadata.ResourceData.HasChange("tags") { + payload.Tags = pointer.To(model.Tags) + } + + if _, err := client.CreateOrUpdate(ctx, *id, *payload); err != nil { + return fmt.Errorf("updating %s: %+v", id, err) + } + + return nil + }, + } +} + +func (r CognitiveAccountRaiPolicyResource) Delete() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 30 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.Cognitive.RaiPoliciesClient + + id, err := raipolicies.ParseRaiPolicyID(metadata.ResourceData.Id()) + if err != nil { + return err + } + + cognitiveAccountId := raipolicies.NewAccountID(id.SubscriptionId, id.ResourceGroupName, id.AccountName) + + locks.ByID(cognitiveAccountId.ID()) + defer locks.UnlockByID(cognitiveAccountId.ID()) + + if err := client.DeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + return nil + }, + } +} + +func (r CognitiveAccountRaiPolicyResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return raipolicies.ValidateRaiPolicyID +} + +func expandRaiPolicyContentFilters(filters []AccountRaiPolicyContentFilter) *[]raipolicies.RaiPolicyContentFilter { + if filters == nil { + return nil + } + + contentFilters := make([]raipolicies.RaiPolicyContentFilter, 0, len(filters)) + for _, filter := range filters { + contentFilters = append(contentFilters, raipolicies.RaiPolicyContentFilter{ + Name: pointer.To(filter.Name), + Enabled: pointer.To(filter.FilterEnabled), + Blocking: pointer.To(filter.BlockEnabled), + SeverityThreshold: pointer.To(raipolicies.ContentLevel(filter.SeverityThreshold)), + Source: pointer.To(raipolicies.RaiPolicyContentSource(filter.Source)), + }) + } + return &contentFilters +} + +func flattenRaiPolicyContentFilters(filters *[]raipolicies.RaiPolicyContentFilter) []AccountRaiPolicyContentFilter { + contentFilters := make([]AccountRaiPolicyContentFilter, 0) + if filters == nil { + return contentFilters + } + + for _, filter := range *filters { + contentFilters = append(contentFilters, AccountRaiPolicyContentFilter{ + Name: pointer.From(filter.Name), + FilterEnabled: pointer.From(filter.Enabled), + BlockEnabled: pointer.From(filter.Blocking), + SeverityThreshold: string(pointer.From(filter.SeverityThreshold)), + Source: string(pointer.From(filter.Source)), + }) + } + return contentFilters +} diff --git a/internal/services/cognitive/cognitive_account_rai_policy_resource_test.go b/internal/services/cognitive/cognitive_account_rai_policy_resource_test.go new file mode 100644 index 000000000000..7084e8d5cc78 --- /dev/null +++ b/internal/services/cognitive/cognitive_account_rai_policy_resource_test.go @@ -0,0 +1,187 @@ +package cognitive_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies" + "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 RaiPolicyTestResource struct{} + +func TestCognitiveAccountRaiPolicy_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cognitive_account_rai_policy", "test") + r := RaiPolicyTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestCognitiveAccountRaiPolicy_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cognitive_account_rai_policy", "test") + r := RaiPolicyTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + { + Config: r.requiresImport(data), + ExpectError: acceptance.RequiresImportError("azurerm_cognitive_account_rai_policy"), + }, + }) +} + +func TestCognitiveAccountRaiPolicy_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_cognitive_account_rai_policy", "test") + r := RaiPolicyTestResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + 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), + check.That(data.ResourceName).Key("mode").HasValue("Asynchronous_filter"), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r RaiPolicyTestResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := raipolicies.ParseRaiPolicyID(state.ID) + if err != nil { + return nil, err + } + + resp, err := client.Cognitive.RaiPoliciesClient.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("retrieving %s: %+v", *id, err) + } + + return pointer.To(resp.Model != nil), nil +} + +func (r RaiPolicyTestResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-cognitive-%d" + location = "%s" +} + +resource "azurerm_cognitive_account" "test" { + name = "acctestcogacc-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + kind = "OpenAI" + sku_name = "S0" +} + +resource "azurerm_cognitive_account_rai_policy" "test" { + name = "acctestraip-%s" + cognitive_account_id = azurerm_cognitive_account.test.id + base_policy_name = "Microsoft.Default" + content_filter { + name = "Hate" + filter_enabled = true + block_enabled = true + severity_threshold = "High" + source = "Prompt" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString) +} + +func (r RaiPolicyTestResource) complete(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-cognitive-%d" + location = "%s" +} + +resource "azurerm_cognitive_account" "test" { + name = "acctestcogacc-%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + kind = "OpenAI" + sku_name = "S0" +} + +resource "azurerm_cognitive_account_rai_policy" "test" { + name = "acctestraip-%s" + cognitive_account_id = azurerm_cognitive_account.test.id + base_policy_name = "Microsoft.Default" + + content_filter { + name = "Hate" + filter_enabled = true + block_enabled = true + severity_threshold = "High" + source = "Prompt" + } + + mode = "Asynchronous_filter" + tags = { + Environment = "Test" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomString) +} + +func (r RaiPolicyTestResource) requiresImport(data acceptance.TestData) string { + template := r.basic(data) + return fmt.Sprintf(` +%s + +resource "azurerm_cognitive_account_rai_policy" "import" { + name = azurerm_cognitive_account_rai_policy.test.name + cognitive_account_id = azurerm_cognitive_account.test.id + base_policy_name = azurerm_cognitive_account_rai_policy.test.base_policy_name + content_filter { + name = "Hate" + filter_enabled = true + block_enabled = true + severity_threshold = "High" + source = "Prompt" + } +} +`, template) +} diff --git a/internal/services/cognitive/registration.go b/internal/services/cognitive/registration.go index 7cb998a3fb02..ada7e6429a65 100644 --- a/internal/services/cognitive/registration.go +++ b/internal/services/cognitive/registration.go @@ -55,6 +55,7 @@ func (r Registration) DataSources() []sdk.DataSource { func (r Registration) Resources() []sdk.Resource { return []sdk.Resource{ AzureAIServicesResource{}, + CognitiveAccountRaiPolicyResource{}, CognitiveDeploymentResource{}, CognitiveRaiBlocklistResource{}, } diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/README.md new file mode 100644 index 000000000000..3202b2c9afa4 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/README.md @@ -0,0 +1,86 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies` Documentation + +The `raipolicies` SDK allows for interaction with Azure Resource Manager `cognitive` (API Version `2024-10-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/cognitive/2024-10-01/raipolicies" +``` + + +### Client Initialization + +```go +client := raipolicies.NewRaiPoliciesClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `RaiPoliciesClient.CreateOrUpdate` + +```go +ctx := context.TODO() +id := raipolicies.NewRaiPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountName", "raiPolicyName") + +payload := raipolicies.RaiPolicy{ + // ... +} + + +read, err := client.CreateOrUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RaiPoliciesClient.Delete` + +```go +ctx := context.TODO() +id := raipolicies.NewRaiPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountName", "raiPolicyName") + +if err := client.DeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `RaiPoliciesClient.Get` + +```go +ctx := context.TODO() +id := raipolicies.NewRaiPolicyID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountName", "raiPolicyName") + +read, err := client.Get(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `RaiPoliciesClient.List` + +```go +ctx := context.TODO() +id := raipolicies.NewAccountID("12345678-1234-9876-4563-123456789012", "example-resource-group", "accountName") + +// alternatively `client.List(ctx, id)` can be used to do batched pagination +items, err := client.ListComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/client.go new file mode 100644 index 000000000000..7503f70f6570 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/client.go @@ -0,0 +1,26 @@ +package raipolicies + +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 RaiPoliciesClient struct { + Client *resourcemanager.Client +} + +func NewRaiPoliciesClientWithBaseURI(sdkApi sdkEnv.Api) (*RaiPoliciesClient, error) { + client, err := resourcemanager.NewClient(sdkApi, "raipolicies", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating RaiPoliciesClient: %+v", err) + } + + return &RaiPoliciesClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/constants.go new file mode 100644 index 000000000000..528ea7cc654e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/constants.go @@ -0,0 +1,183 @@ +package raipolicies + +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 ContentLevel string + +const ( + ContentLevelHigh ContentLevel = "High" + ContentLevelLow ContentLevel = "Low" + ContentLevelMedium ContentLevel = "Medium" +) + +func PossibleValuesForContentLevel() []string { + return []string{ + string(ContentLevelHigh), + string(ContentLevelLow), + string(ContentLevelMedium), + } +} + +func (s *ContentLevel) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseContentLevel(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseContentLevel(input string) (*ContentLevel, error) { + vals := map[string]ContentLevel{ + "high": ContentLevelHigh, + "low": ContentLevelLow, + "medium": ContentLevelMedium, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ContentLevel(input) + return &out, nil +} + +type RaiPolicyContentSource string + +const ( + RaiPolicyContentSourceCompletion RaiPolicyContentSource = "Completion" + RaiPolicyContentSourcePrompt RaiPolicyContentSource = "Prompt" +) + +func PossibleValuesForRaiPolicyContentSource() []string { + return []string{ + string(RaiPolicyContentSourceCompletion), + string(RaiPolicyContentSourcePrompt), + } +} + +func (s *RaiPolicyContentSource) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRaiPolicyContentSource(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRaiPolicyContentSource(input string) (*RaiPolicyContentSource, error) { + vals := map[string]RaiPolicyContentSource{ + "completion": RaiPolicyContentSourceCompletion, + "prompt": RaiPolicyContentSourcePrompt, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RaiPolicyContentSource(input) + return &out, nil +} + +type RaiPolicyMode string + +const ( + RaiPolicyModeAsynchronousFilter RaiPolicyMode = "Asynchronous_filter" + RaiPolicyModeBlocking RaiPolicyMode = "Blocking" + RaiPolicyModeDefault RaiPolicyMode = "Default" + RaiPolicyModeDeferred RaiPolicyMode = "Deferred" +) + +func PossibleValuesForRaiPolicyMode() []string { + return []string{ + string(RaiPolicyModeAsynchronousFilter), + string(RaiPolicyModeBlocking), + string(RaiPolicyModeDefault), + string(RaiPolicyModeDeferred), + } +} + +func (s *RaiPolicyMode) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRaiPolicyMode(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRaiPolicyMode(input string) (*RaiPolicyMode, error) { + vals := map[string]RaiPolicyMode{ + "asynchronous_filter": RaiPolicyModeAsynchronousFilter, + "blocking": RaiPolicyModeBlocking, + "default": RaiPolicyModeDefault, + "deferred": RaiPolicyModeDeferred, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RaiPolicyMode(input) + return &out, nil +} + +type RaiPolicyType string + +const ( + RaiPolicyTypeSystemManaged RaiPolicyType = "SystemManaged" + RaiPolicyTypeUserManaged RaiPolicyType = "UserManaged" +) + +func PossibleValuesForRaiPolicyType() []string { + return []string{ + string(RaiPolicyTypeSystemManaged), + string(RaiPolicyTypeUserManaged), + } +} + +func (s *RaiPolicyType) UnmarshalJSON(bytes []byte) error { + var decoded string + if err := json.Unmarshal(bytes, &decoded); err != nil { + return fmt.Errorf("unmarshaling: %+v", err) + } + out, err := parseRaiPolicyType(decoded) + if err != nil { + return fmt.Errorf("parsing %q: %+v", decoded, err) + } + *s = *out + return nil +} + +func parseRaiPolicyType(input string) (*RaiPolicyType, error) { + vals := map[string]RaiPolicyType{ + "systemmanaged": RaiPolicyTypeSystemManaged, + "usermanaged": RaiPolicyTypeUserManaged, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := RaiPolicyType(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/id_account.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/id_account.go new file mode 100644 index 000000000000..460748c4e41d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/id_account.go @@ -0,0 +1,130 @@ +package raipolicies + +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(&AccountId{}) +} + +var _ resourceids.ResourceId = &AccountId{} + +// AccountId is a struct representing the Resource ID for a Account +type AccountId struct { + SubscriptionId string + ResourceGroupName string + AccountName string +} + +// NewAccountID returns a new AccountId struct +func NewAccountID(subscriptionId string, resourceGroupName string, accountName string) AccountId { + return AccountId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + } +} + +// ParseAccountID parses 'input' into a AccountId +func ParseAccountID(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseAccountIDInsensitively parses 'input' case-insensitively into a AccountId +// note: this method should only be used for API response data and not user input +func ParseAccountIDInsensitively(input string) (*AccountId, error) { + parser := resourceids.NewParserFromResourceIdType(&AccountId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := AccountId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *AccountId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + return nil +} + +// ValidateAccountID checks that 'input' can be parsed as a Account ID +func ValidateAccountID(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 := ParseAccountID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Account ID +func (id AccountId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Account ID +func (id AccountId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountName"), + } +} + +// String returns a human-readable description of this Account ID +func (id AccountId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + } + return fmt.Sprintf("Account (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/id_raipolicy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/id_raipolicy.go new file mode 100644 index 000000000000..9447722fe0d8 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/id_raipolicy.go @@ -0,0 +1,139 @@ +package raipolicies + +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(&RaiPolicyId{}) +} + +var _ resourceids.ResourceId = &RaiPolicyId{} + +// RaiPolicyId is a struct representing the Resource ID for a Rai Policy +type RaiPolicyId struct { + SubscriptionId string + ResourceGroupName string + AccountName string + RaiPolicyName string +} + +// NewRaiPolicyID returns a new RaiPolicyId struct +func NewRaiPolicyID(subscriptionId string, resourceGroupName string, accountName string, raiPolicyName string) RaiPolicyId { + return RaiPolicyId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + AccountName: accountName, + RaiPolicyName: raiPolicyName, + } +} + +// ParseRaiPolicyID parses 'input' into a RaiPolicyId +func ParseRaiPolicyID(input string) (*RaiPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&RaiPolicyId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RaiPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseRaiPolicyIDInsensitively parses 'input' case-insensitively into a RaiPolicyId +// note: this method should only be used for API response data and not user input +func ParseRaiPolicyIDInsensitively(input string) (*RaiPolicyId, error) { + parser := resourceids.NewParserFromResourceIdType(&RaiPolicyId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := RaiPolicyId{} + if err = id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *RaiPolicyId) 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.AccountName, ok = input.Parsed["accountName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "accountName", input) + } + + if id.RaiPolicyName, ok = input.Parsed["raiPolicyName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "raiPolicyName", input) + } + + return nil +} + +// ValidateRaiPolicyID checks that 'input' can be parsed as a Rai Policy ID +func ValidateRaiPolicyID(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 := ParseRaiPolicyID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Rai Policy ID +func (id RaiPolicyId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.CognitiveServices/accounts/%s/raiPolicies/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.AccountName, id.RaiPolicyName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Rai Policy ID +func (id RaiPolicyId) 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("staticMicrosoftCognitiveServices", "Microsoft.CognitiveServices", "Microsoft.CognitiveServices"), + resourceids.StaticSegment("staticAccounts", "accounts", "accounts"), + resourceids.UserSpecifiedSegment("accountName", "accountName"), + resourceids.StaticSegment("staticRaiPolicies", "raiPolicies", "raiPolicies"), + resourceids.UserSpecifiedSegment("raiPolicyName", "raiPolicyName"), + } +} + +// String returns a human-readable description of this Rai Policy ID +func (id RaiPolicyId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Account Name: %q", id.AccountName), + fmt.Sprintf("Rai Policy Name: %q", id.RaiPolicyName), + } + return fmt.Sprintf("Rai Policy (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_createorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_createorupdate.go new file mode 100644 index 000000000000..f462d012d822 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_createorupdate.go @@ -0,0 +1,58 @@ +package raipolicies + +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 CreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RaiPolicy +} + +// CreateOrUpdate ... +func (c RaiPoliciesClient) CreateOrUpdate(ctx context.Context, id RaiPolicyId, input RaiPolicy) (result CreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusCreated, + http.StatusOK, + }, + HttpMethod: http.MethodPut, + 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 + } + + var model RaiPolicy + 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/cognitive/2024-10-01/raipolicies/method_delete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_delete.go new file mode 100644 index 000000000000..fdb2a53c9321 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_delete.go @@ -0,0 +1,70 @@ +package raipolicies + +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 DeleteOperationResponse struct { + Poller pollers.Poller + HttpResponse *http.Response + OData *odata.OData +} + +// Delete ... +func (c RaiPoliciesClient) Delete(ctx context.Context, id RaiPolicyId) (result DeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusAccepted, + http.StatusNoContent, + }, + HttpMethod: http.MethodDelete, + 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 + } + + result.Poller, err = resourcemanager.PollerFromResponse(resp, c.Client) + if err != nil { + return + } + + return +} + +// DeleteThenPoll performs Delete then polls until it's completed +func (c RaiPoliciesClient) DeleteThenPoll(ctx context.Context, id RaiPolicyId) error { + result, err := c.Delete(ctx, id) + if err != nil { + return fmt.Errorf("performing Delete: %+v", err) + } + + if err := result.Poller.PollUntilDone(ctx); err != nil { + return fmt.Errorf("polling after Delete: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_get.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_get.go new file mode 100644 index 000000000000..3770891a82fb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_get.go @@ -0,0 +1,53 @@ +package raipolicies + +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 GetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *RaiPolicy +} + +// Get ... +func (c RaiPoliciesClient) Get(ctx context.Context, id RaiPolicyId) (result GetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + 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 RaiPolicy + 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/cognitive/2024-10-01/raipolicies/method_list.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_list.go new file mode 100644 index 000000000000..932a5025f0eb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/method_list.go @@ -0,0 +1,105 @@ +package raipolicies + +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 ListOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]RaiPolicy +} + +type ListCompleteResult struct { + LatestHttpResponse *http.Response + Items []RaiPolicy +} + +type ListCustomPager struct { + NextLink *odata.Link `json:"nextLink"` +} + +func (p *ListCustomPager) NextPageLink() *odata.Link { + defer func() { + p.NextLink = nil + }() + + return p.NextLink +} + +// List ... +func (c RaiPoliciesClient) List(ctx context.Context, id AccountId) (result ListOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Pager: &ListCustomPager{}, + Path: fmt.Sprintf("%s/raiPolicies", 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 *[]RaiPolicy `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// ListComplete retrieves all the results into a single object +func (c RaiPoliciesClient) ListComplete(ctx context.Context, id AccountId) (ListCompleteResult, error) { + return c.ListCompleteMatchingPredicate(ctx, id, RaiPolicyOperationPredicate{}) +} + +// ListCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c RaiPoliciesClient) ListCompleteMatchingPredicate(ctx context.Context, id AccountId, predicate RaiPolicyOperationPredicate) (result ListCompleteResult, err error) { + items := make([]RaiPolicy, 0) + + resp, err := c.List(ctx, id) + 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 = ListCompleteResult{ + LatestHttpResponse: resp.HttpResponse, + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_customblocklistconfig.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_customblocklistconfig.go new file mode 100644 index 000000000000..0fe7b2a6641b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_customblocklistconfig.go @@ -0,0 +1,10 @@ +package raipolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CustomBlocklistConfig struct { + Blocking *bool `json:"blocking,omitempty"` + BlocklistName *string `json:"blocklistName,omitempty"` + Source *RaiPolicyContentSource `json:"source,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_raipolicy.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_raipolicy.go new file mode 100644 index 000000000000..b373a9fdc22c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_raipolicy.go @@ -0,0 +1,18 @@ +package raipolicies + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiPolicy struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties *RaiPolicyProperties `json:"properties,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_raipolicycontentfilter.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_raipolicycontentfilter.go new file mode 100644 index 000000000000..d5984e730bab --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_raipolicycontentfilter.go @@ -0,0 +1,12 @@ +package raipolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiPolicyContentFilter struct { + Blocking *bool `json:"blocking,omitempty"` + Enabled *bool `json:"enabled,omitempty"` + Name *string `json:"name,omitempty"` + SeverityThreshold *ContentLevel `json:"severityThreshold,omitempty"` + Source *RaiPolicyContentSource `json:"source,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_raipolicyproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_raipolicyproperties.go new file mode 100644 index 000000000000..31f7dbcb3bae --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/model_raipolicyproperties.go @@ -0,0 +1,12 @@ +package raipolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiPolicyProperties struct { + BasePolicyName *string `json:"basePolicyName,omitempty"` + ContentFilters *[]RaiPolicyContentFilter `json:"contentFilters,omitempty"` + CustomBlocklists *[]CustomBlocklistConfig `json:"customBlocklists,omitempty"` + Mode *RaiPolicyMode `json:"mode,omitempty"` + Type *RaiPolicyType `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/predicates.go new file mode 100644 index 000000000000..4f56bb41f17f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/predicates.go @@ -0,0 +1,32 @@ +package raipolicies + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type RaiPolicyOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p RaiPolicyOperationPredicate) Matches(input RaiPolicy) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + 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/cognitive/2024-10-01/raipolicies/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/version.go new file mode 100644 index 000000000000..777f0458d62e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies/version.go @@ -0,0 +1,10 @@ +package raipolicies + +// 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-10-01" + +func userAgent() string { + return "hashicorp/go-azure-sdk/raipolicies/2024-10-01" +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 434e92d526e9..afb2afb33328 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -321,6 +321,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/codesigning/2024-09-30-previe github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/cognitiveservicesaccounts github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/deployments github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raiblocklists +github.com/hashicorp/go-azure-sdk/resource-manager/cognitive/2024-10-01/raipolicies github.com/hashicorp/go-azure-sdk/resource-manager/communication/2023-03-31/communicationservices github.com/hashicorp/go-azure-sdk/resource-manager/communication/2023-03-31/domains github.com/hashicorp/go-azure-sdk/resource-manager/communication/2023-03-31/emailservices diff --git a/website/docs/r/cognitive_account_rai_policy.html.markdown b/website/docs/r/cognitive_account_rai_policy.html.markdown new file mode 100644 index 000000000000..4ac442848758 --- /dev/null +++ b/website/docs/r/cognitive_account_rai_policy.html.markdown @@ -0,0 +1,101 @@ +--- +subcategory: "Cognitive Services" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_cognitive_account_rai_policy" +description: |- + Manages a Cognitive Services Account RAI Policy. +--- + +# azurerm_cognitive_account + +Manages a Cognitive Services Account RAI Policy. + +## Example Usage + +```hcl +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "East US" +} + +resource "azurerm_cognitive_account" "example" { + name = "example-account" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + kind = "OpenAI" + sku_name = "S0" +} + +resource "azurerm_cognitive_account_rai_policy" "example" { + name = "example-rai-policy" + cognitive_account_id = azurerm_cognitive_account.example.id + base_policy_name = "Microsoft.Default" + content_filter { + name = "Hate" + filter_enabled = true + block_enabled = true + severity_threshold = "High" + source = "Prompt" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) The name of the Cognitive Service Account RAI Policy. Changing this forces a new resource to be created. + +* `cognitive_account_id` - (Required) The ID of the Cognitive Service Account to which this RAI Policy should be associated. Changing this forces a new resource to be created. + +* `base_policy_name` - (Required) The name of the base policy to use for this RAI Policy. Changing this forces a new resource to be created. + +* `content_filter` - (Required) A `content_filter` block as defined below. + +* `mode` - (Optional) The mode of the RAI Policy. Possible values are `Default`, `Deferred`, `Blocking` or `Asynchronous_filter`. + +* `tags` - (Optional) A mapping of tags to assign to the resource. + +--- + +A `content_filter` block supports the following: + +* `name` - (Required) The name of the content filter. + +* `filter_enabled` - (Required) Whether the filter is enabled. Possible values are `true` or `false`. + +* `block_enabled` - (Required) Whether the filter should block content. Possible values are `true` or `false`. + +* `severity_threshold` - (Required) The severity threshold for the filter. Possible values are `Low`, `Medium` or `High`. + +* `source` - (Required) Content source to apply the content filter. Possible values are `Prompt` or `Completion`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Cognitive Service Account RAI Policy. + +## 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 Cognitive Service Account RAI Policy. + +* `update` - (Defaults to 30 minutes) Used when updating the Cognitive Service Account RAI Policy. + +* `read` - (Defaults to 5 minutes) Used when retrieving the Cognitive Service Account RAI Policy. + +* `delete` - (Defaults to 30 minutes) Used when deleting the Cognitive Service Account RAI Policy. + +## Import + +Cognitive Service Account RAI Policies can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_cognitive_account_rai_policy.policy1 /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.CognitiveServices/accounts/account1/raiPolicies/policy1 +```