Azure Classic

v5.25.0 published on Thursday, Nov 24, 2022 by Pulumi

ApiPolicy

Manages an API Management API Policy

Example Usage

using System.Collections.Generic;
using Pulumi;
using Azure = Pulumi.Azure;

return await Deployment.RunAsync(() => 
{
    var exampleApi = Azure.ApiManagement.GetApi.Invoke(new()
    {
        Name = "my-api",
        ApiManagementName = "example-apim",
        ResourceGroupName = "search-service",
        Revision = "2",
    });

    var exampleApiPolicy = new Azure.ApiManagement.ApiPolicy("exampleApiPolicy", new()
    {
        ApiName = exampleApi.Apply(getApiResult => getApiResult.Name),
        ApiManagementName = exampleApi.Apply(getApiResult => getApiResult.ApiManagementName),
        ResourceGroupName = exampleApi.Apply(getApiResult => getApiResult.ResourceGroupName),
        XmlContent = @"<policies>
  <inbound>
    <find-and-replace from=""xyz"" to=""abc"" />
  </inbound>
</policies>
",
    });

});
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/apimanagement"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		exampleApi, err := apimanagement.LookupApi(ctx, &apimanagement.LookupApiArgs{
			Name:              "my-api",
			ApiManagementName: "example-apim",
			ResourceGroupName: "search-service",
			Revision:          "2",
		}, nil)
		if err != nil {
			return err
		}
		_, err = apimanagement.NewApiPolicy(ctx, "exampleApiPolicy", &apimanagement.ApiPolicyArgs{
			ApiName:           pulumi.String(exampleApi.Name),
			ApiManagementName: pulumi.String(exampleApi.ApiManagementName),
			ResourceGroupName: pulumi.String(exampleApi.ResourceGroupName),
			XmlContent:        pulumi.String(fmt.Sprintf("<policies>\n  <inbound>\n    <find-and-replace from=\"xyz\" to=\"abc\" />\n  </inbound>\n</policies>\n")),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.azure.apimanagement.ApimanagementFunctions;
import com.pulumi.azure.apimanagement.inputs.GetApiArgs;
import com.pulumi.azure.apimanagement.ApiPolicy;
import com.pulumi.azure.apimanagement.ApiPolicyArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        final var exampleApi = ApimanagementFunctions.getApi(GetApiArgs.builder()
            .name("my-api")
            .apiManagementName("example-apim")
            .resourceGroupName("search-service")
            .revision("2")
            .build());

        var exampleApiPolicy = new ApiPolicy("exampleApiPolicy", ApiPolicyArgs.builder()        
            .apiName(exampleApi.applyValue(getApiResult -> getApiResult.name()))
            .apiManagementName(exampleApi.applyValue(getApiResult -> getApiResult.apiManagementName()))
            .resourceGroupName(exampleApi.applyValue(getApiResult -> getApiResult.resourceGroupName()))
            .xmlContent("""
<policies>
  <inbound>
    <find-and-replace from="xyz" to="abc" />
  </inbound>
</policies>
            """)
            .build());

    }
}
import pulumi
import pulumi_azure as azure

example_api = azure.apimanagement.get_api(name="my-api",
    api_management_name="example-apim",
    resource_group_name="search-service",
    revision="2")
example_api_policy = azure.apimanagement.ApiPolicy("exampleApiPolicy",
    api_name=example_api.name,
    api_management_name=example_api.api_management_name,
    resource_group_name=example_api.resource_group_name,
    xml_content="""<policies>
  <inbound>
    <find-and-replace from="xyz" to="abc" />
  </inbound>
</policies>
""")
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";

const exampleApi = azure.apimanagement.getApi({
    name: "my-api",
    apiManagementName: "example-apim",
    resourceGroupName: "search-service",
    revision: "2",
});
const exampleApiPolicy = new azure.apimanagement.ApiPolicy("exampleApiPolicy", {
    apiName: exampleApi.then(exampleApi => exampleApi.name),
    apiManagementName: exampleApi.then(exampleApi => exampleApi.apiManagementName),
    resourceGroupName: exampleApi.then(exampleApi => exampleApi.resourceGroupName),
    xmlContent: `<policies>
  <inbound>
    <find-and-replace from="xyz" to="abc" />
  </inbound>
</policies>
`,
});
resources:
  exampleApiPolicy:
    type: azure:apimanagement:ApiPolicy
    properties:
      apiName: ${exampleApi.name}
      apiManagementName: ${exampleApi.apiManagementName}
      resourceGroupName: ${exampleApi.resourceGroupName}
      xmlContent: |
        <policies>
          <inbound>
            <find-and-replace from="xyz" to="abc" />
          </inbound>
        </policies>        
variables:
  exampleApi:
    Fn::Invoke:
      Function: azure:apimanagement:getApi
      Arguments:
        name: my-api
        apiManagementName: example-apim
        resourceGroupName: search-service
        revision: 2

Create ApiPolicy Resource

new ApiPolicy(name: string, args: ApiPolicyArgs, opts?: CustomResourceOptions);
@overload
def ApiPolicy(resource_name: str,
              opts: Optional[ResourceOptions] = None,
              api_management_name: Optional[str] = None,
              api_name: Optional[str] = None,
              resource_group_name: Optional[str] = None,
              xml_content: Optional[str] = None,
              xml_link: Optional[str] = None)
@overload
def ApiPolicy(resource_name: str,
              args: ApiPolicyArgs,
              opts: Optional[ResourceOptions] = None)
func NewApiPolicy(ctx *Context, name string, args ApiPolicyArgs, opts ...ResourceOption) (*ApiPolicy, error)
public ApiPolicy(string name, ApiPolicyArgs args, CustomResourceOptions? opts = null)
public ApiPolicy(String name, ApiPolicyArgs args)
public ApiPolicy(String name, ApiPolicyArgs args, CustomResourceOptions options)
type: azure:apimanagement:ApiPolicy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args ApiPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args ApiPolicyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args ApiPolicyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args ApiPolicyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args ApiPolicyArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

ApiPolicy Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The ApiPolicy resource accepts the following input properties:

ApiManagementName string

The name of the API Management Service. Changing this forces a new resource to be created.

ApiName string

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

ResourceGroupName string

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

XmlContent string

The XML Content for this Policy as a string.

XmlLink string

A link to a Policy XML Document, which must be publicly available.

ApiManagementName string

The name of the API Management Service. Changing this forces a new resource to be created.

ApiName string

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

ResourceGroupName string

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

XmlContent string

The XML Content for this Policy as a string.

XmlLink string

A link to a Policy XML Document, which must be publicly available.

apiManagementName String

The name of the API Management Service. Changing this forces a new resource to be created.

apiName String

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

resourceGroupName String

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

xmlContent String

The XML Content for this Policy as a string.

xmlLink String

A link to a Policy XML Document, which must be publicly available.

apiManagementName string

The name of the API Management Service. Changing this forces a new resource to be created.

apiName string

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

resourceGroupName string

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

xmlContent string

The XML Content for this Policy as a string.

xmlLink string

A link to a Policy XML Document, which must be publicly available.

api_management_name str

The name of the API Management Service. Changing this forces a new resource to be created.

api_name str

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

resource_group_name str

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

xml_content str

The XML Content for this Policy as a string.

xml_link str

A link to a Policy XML Document, which must be publicly available.

apiManagementName String

The name of the API Management Service. Changing this forces a new resource to be created.

apiName String

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

resourceGroupName String

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

xmlContent String

The XML Content for this Policy as a string.

xmlLink String

A link to a Policy XML Document, which must be publicly available.

Outputs

All input properties are implicitly available as output properties. Additionally, the ApiPolicy resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Id string

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

id string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up Existing ApiPolicy Resource

Get an existing ApiPolicy resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: ApiPolicyState, opts?: CustomResourceOptions): ApiPolicy
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        api_management_name: Optional[str] = None,
        api_name: Optional[str] = None,
        resource_group_name: Optional[str] = None,
        xml_content: Optional[str] = None,
        xml_link: Optional[str] = None) -> ApiPolicy
func GetApiPolicy(ctx *Context, name string, id IDInput, state *ApiPolicyState, opts ...ResourceOption) (*ApiPolicy, error)
public static ApiPolicy Get(string name, Input<string> id, ApiPolicyState? state, CustomResourceOptions? opts = null)
public static ApiPolicy get(String name, Output<String> id, ApiPolicyState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
ApiManagementName string

The name of the API Management Service. Changing this forces a new resource to be created.

ApiName string

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

ResourceGroupName string

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

XmlContent string

The XML Content for this Policy as a string.

XmlLink string

A link to a Policy XML Document, which must be publicly available.

ApiManagementName string

The name of the API Management Service. Changing this forces a new resource to be created.

ApiName string

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

ResourceGroupName string

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

XmlContent string

The XML Content for this Policy as a string.

XmlLink string

A link to a Policy XML Document, which must be publicly available.

apiManagementName String

The name of the API Management Service. Changing this forces a new resource to be created.

apiName String

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

resourceGroupName String

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

xmlContent String

The XML Content for this Policy as a string.

xmlLink String

A link to a Policy XML Document, which must be publicly available.

apiManagementName string

The name of the API Management Service. Changing this forces a new resource to be created.

apiName string

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

resourceGroupName string

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

xmlContent string

The XML Content for this Policy as a string.

xmlLink string

A link to a Policy XML Document, which must be publicly available.

api_management_name str

The name of the API Management Service. Changing this forces a new resource to be created.

api_name str

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

resource_group_name str

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

xml_content str

The XML Content for this Policy as a string.

xml_link str

A link to a Policy XML Document, which must be publicly available.

apiManagementName String

The name of the API Management Service. Changing this forces a new resource to be created.

apiName String

The ID of the API Management API within the API Management Service. Changing this forces a new resource to be created.

resourceGroupName String

The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.

xmlContent String

The XML Content for this Policy as a string.

xmlLink String

A link to a Policy XML Document, which must be publicly available.

Import

API Management API Policy can be imported using the resource id, e.g.

 $ pulumi import azure:apimanagement/apiPolicy:ApiPolicy example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/service1/apis/exampleId/policies/policy

Package Details

Repository
https://github.com/pulumi/pulumi-azure
License
Apache-2.0
Notes

This Pulumi package is based on the azurerm Terraform Provider.