1. Packages
  2. Azure Classic
  3. API Docs
  4. apimanagement
  5. ApiPolicy

We recommend using Azure Native.

Azure v6.10.0 published on Tuesday, Nov 19, 2024 by Pulumi

azure.apimanagement.ApiPolicy

Explore with Pulumi AI

azure logo

We recommend using Azure Native.

Azure v6.10.0 published on Tuesday, Nov 19, 2024 by Pulumi

    Manages an API Management API Policy

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as azure from "@pulumi/azure";
    
    const example = azure.apimanagement.getApi({
        name: "my-api",
        apiManagementName: "example-apim",
        resourceGroupName: "search-service",
        revision: "2",
    });
    const exampleApiPolicy = new azure.apimanagement.ApiPolicy("example", {
        apiName: example.then(example => example.name),
        apiManagementName: example.then(example => example.apiManagementName),
        resourceGroupName: example.then(example => example.resourceGroupName),
        xmlContent: `<policies>
      <inbound>
        <find-and-replace from="xyz" to="abc" />
      </inbound>
    </policies>
    `,
    });
    
    import pulumi
    import pulumi_azure as azure
    
    example = 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("example",
        api_name=example.name,
        api_management_name=example.api_management_name,
        resource_group_name=example.resource_group_name,
        xml_content="""<policies>
      <inbound>
        <find-and-replace from="xyz" to="abc" />
      </inbound>
    </policies>
    """)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-azure/sdk/v6/go/azure/apimanagement"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		example, 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, "example", &apimanagement.ApiPolicyArgs{
    			ApiName:           pulumi.String(example.Name),
    			ApiManagementName: pulumi.String(example.ApiManagementName),
    			ResourceGroupName: pulumi.String(example.ResourceGroupName),
    			XmlContent: pulumi.String(`<policies>
      <inbound>
        <find-and-replace from="xyz" to="abc" />
      </inbound>
    </policies>
    `),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Azure = Pulumi.Azure;
    
    return await Deployment.RunAsync(() => 
    {
        var example = Azure.ApiManagement.GetApi.Invoke(new()
        {
            Name = "my-api",
            ApiManagementName = "example-apim",
            ResourceGroupName = "search-service",
            Revision = "2",
        });
    
        var exampleApiPolicy = new Azure.ApiManagement.ApiPolicy("example", new()
        {
            ApiName = example.Apply(getApiResult => getApiResult.Name),
            ApiManagementName = example.Apply(getApiResult => getApiResult.ApiManagementName),
            ResourceGroupName = example.Apply(getApiResult => getApiResult.ResourceGroupName),
            XmlContent = @"<policies>
      <inbound>
        <find-and-replace from=""xyz"" to=""abc"" />
      </inbound>
    </policies>
    ",
        });
    
    });
    
    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 example = ApimanagementFunctions.getApi(GetApiArgs.builder()
                .name("my-api")
                .apiManagementName("example-apim")
                .resourceGroupName("search-service")
                .revision("2")
                .build());
    
            var exampleApiPolicy = new ApiPolicy("exampleApiPolicy", ApiPolicyArgs.builder()
                .apiName(example.applyValue(getApiResult -> getApiResult.name()))
                .apiManagementName(example.applyValue(getApiResult -> getApiResult.apiManagementName()))
                .resourceGroupName(example.applyValue(getApiResult -> getApiResult.resourceGroupName()))
                .xmlContent("""
    <policies>
      <inbound>
        <find-and-replace from="xyz" to="abc" />
      </inbound>
    </policies>
                """)
                .build());
    
        }
    }
    
    resources:
      exampleApiPolicy:
        type: azure:apimanagement:ApiPolicy
        name: example
        properties:
          apiName: ${example.name}
          apiManagementName: ${example.apiManagementName}
          resourceGroupName: ${example.resourceGroupName}
          xmlContent: |
            <policies>
              <inbound>
                <find-and-replace from="xyz" to="abc" />
              </inbound>
            </policies>        
    variables:
      example:
        fn::invoke:
          Function: azure:apimanagement:getApi
          Arguments:
            name: my-api
            apiManagementName: example-apim
            resourceGroupName: search-service
            revision: '2'
    

    Create ApiPolicy Resource

    Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

    Constructor syntax

    new ApiPolicy(name: string, args: ApiPolicyArgs, opts?: CustomResourceOptions);
    @overload
    def ApiPolicy(resource_name: str,
                  args: ApiPolicyArgs,
                  opts: Optional[ResourceOptions] = None)
    
    @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)
    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.
    
    

    Parameters

    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.

    Constructor example

    The following reference example uses placeholder values for all input properties.

    var apiPolicyResource = new Azure.ApiManagement.ApiPolicy("apiPolicyResource", new()
    {
        ApiManagementName = "string",
        ApiName = "string",
        ResourceGroupName = "string",
        XmlContent = "string",
        XmlLink = "string",
    });
    
    example, err := apimanagement.NewApiPolicy(ctx, "apiPolicyResource", &apimanagement.ApiPolicyArgs{
    	ApiManagementName: pulumi.String("string"),
    	ApiName:           pulumi.String("string"),
    	ResourceGroupName: pulumi.String("string"),
    	XmlContent:        pulumi.String("string"),
    	XmlLink:           pulumi.String("string"),
    })
    
    var apiPolicyResource = new ApiPolicy("apiPolicyResource", ApiPolicyArgs.builder()
        .apiManagementName("string")
        .apiName("string")
        .resourceGroupName("string")
        .xmlContent("string")
        .xmlLink("string")
        .build());
    
    api_policy_resource = azure.apimanagement.ApiPolicy("apiPolicyResource",
        api_management_name="string",
        api_name="string",
        resource_group_name="string",
        xml_content="string",
        xml_link="string")
    
    const apiPolicyResource = new azure.apimanagement.ApiPolicy("apiPolicyResource", {
        apiManagementName: "string",
        apiName: "string",
        resourceGroupName: "string",
        xmlContent: "string",
        xmlLink: "string",
    });
    
    type: azure:apimanagement:ApiPolicy
    properties:
        apiManagementName: string
        apiName: string
        resourceGroupName: string
        xmlContent: string
        xmlLink: string
    

    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

    In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

    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
    

    To learn more about importing existing cloud resources, see Importing resources.

    Package Details

    Repository
    Azure Classic pulumi/pulumi-azure
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the azurerm Terraform Provider.
    azure logo

    We recommend using Azure Native.

    Azure v6.10.0 published on Tuesday, Nov 19, 2024 by Pulumi