We recommend using Azure Native.
azure.apimanagement.Policy
Explore with Pulumi AI
Manages a API Management service Policy.
NOTE: This resource will, upon creation, overwrite any existing policy in the API Management service, as there is no feasible way to test whether the policy has been modified from the default. Similarly, when this resource is destroyed, the API Management service will revert to its default policy.
Example Usage
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Pulumi;
using Azure = Pulumi.Azure;
return await Deployment.RunAsync(() =>
{
var exampleResourceGroup = new Azure.Core.ResourceGroup("exampleResourceGroup", new()
{
Location = "West Europe",
});
var exampleService = new Azure.ApiManagement.Service("exampleService", new()
{
Location = exampleResourceGroup.Location,
ResourceGroupName = exampleResourceGroup.Name,
PublisherName = "pub1",
PublisherEmail = "pub1@email.com",
SkuName = "Developer_1",
});
var exampleNamedValue = new Azure.ApiManagement.NamedValue("exampleNamedValue", new()
{
ResourceGroupName = exampleResourceGroup.Name,
ApiManagementName = exampleService.Name,
DisplayName = "ExampleProperty",
Value = "Example Value",
});
var examplePolicy = new Azure.ApiManagement.Policy("examplePolicy", new()
{
ApiManagementId = exampleService.Id,
XmlContent = File.ReadAllText("example.xml"),
});
});
package main
import (
"os"
"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/apimanagement"
"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func readFileOrPanic(path string) pulumi.StringPtrInput {
data, err := os.ReadFile(path)
if err != nil {
panic(err.Error())
}
return pulumi.String(string(data))
}
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
exampleResourceGroup, err := core.NewResourceGroup(ctx, "exampleResourceGroup", &core.ResourceGroupArgs{
Location: pulumi.String("West Europe"),
})
if err != nil {
return err
}
exampleService, err := apimanagement.NewService(ctx, "exampleService", &apimanagement.ServiceArgs{
Location: exampleResourceGroup.Location,
ResourceGroupName: exampleResourceGroup.Name,
PublisherName: pulumi.String("pub1"),
PublisherEmail: pulumi.String("pub1@email.com"),
SkuName: pulumi.String("Developer_1"),
})
if err != nil {
return err
}
_, err = apimanagement.NewNamedValue(ctx, "exampleNamedValue", &apimanagement.NamedValueArgs{
ResourceGroupName: exampleResourceGroup.Name,
ApiManagementName: exampleService.Name,
DisplayName: pulumi.String("ExampleProperty"),
Value: pulumi.String("Example Value"),
})
if err != nil {
return err
}
_, err = apimanagement.NewPolicy(ctx, "examplePolicy", &apimanagement.PolicyArgs{
ApiManagementId: exampleService.ID(),
XmlContent: readFileOrPanic("example.xml"),
})
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.core.ResourceGroup;
import com.pulumi.azure.core.ResourceGroupArgs;
import com.pulumi.azure.apimanagement.Service;
import com.pulumi.azure.apimanagement.ServiceArgs;
import com.pulumi.azure.apimanagement.NamedValue;
import com.pulumi.azure.apimanagement.NamedValueArgs;
import com.pulumi.azure.apimanagement.Policy;
import com.pulumi.azure.apimanagement.PolicyArgs;
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) {
var exampleResourceGroup = new ResourceGroup("exampleResourceGroup", ResourceGroupArgs.builder()
.location("West Europe")
.build());
var exampleService = new Service("exampleService", ServiceArgs.builder()
.location(exampleResourceGroup.location())
.resourceGroupName(exampleResourceGroup.name())
.publisherName("pub1")
.publisherEmail("pub1@email.com")
.skuName("Developer_1")
.build());
var exampleNamedValue = new NamedValue("exampleNamedValue", NamedValueArgs.builder()
.resourceGroupName(exampleResourceGroup.name())
.apiManagementName(exampleService.name())
.displayName("ExampleProperty")
.value("Example Value")
.build());
var examplePolicy = new Policy("examplePolicy", PolicyArgs.builder()
.apiManagementId(exampleService.id())
.xmlContent(Files.readString(Paths.get("example.xml")))
.build());
}
}
import pulumi
import pulumi_azure as azure
example_resource_group = azure.core.ResourceGroup("exampleResourceGroup", location="West Europe")
example_service = azure.apimanagement.Service("exampleService",
location=example_resource_group.location,
resource_group_name=example_resource_group.name,
publisher_name="pub1",
publisher_email="pub1@email.com",
sku_name="Developer_1")
example_named_value = azure.apimanagement.NamedValue("exampleNamedValue",
resource_group_name=example_resource_group.name,
api_management_name=example_service.name,
display_name="ExampleProperty",
value="Example Value")
example_policy = azure.apimanagement.Policy("examplePolicy",
api_management_id=example_service.id,
xml_content=(lambda path: open(path).read())("example.xml"))
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
import * as fs from "fs";
const exampleResourceGroup = new azure.core.ResourceGroup("exampleResourceGroup", {location: "West Europe"});
const exampleService = new azure.apimanagement.Service("exampleService", {
location: exampleResourceGroup.location,
resourceGroupName: exampleResourceGroup.name,
publisherName: "pub1",
publisherEmail: "pub1@email.com",
skuName: "Developer_1",
});
const exampleNamedValue = new azure.apimanagement.NamedValue("exampleNamedValue", {
resourceGroupName: exampleResourceGroup.name,
apiManagementName: exampleService.name,
displayName: "ExampleProperty",
value: "Example Value",
});
const examplePolicy = new azure.apimanagement.Policy("examplePolicy", {
apiManagementId: exampleService.id,
xmlContent: fs.readFileSync("example.xml"),
});
resources:
exampleResourceGroup:
type: azure:core:ResourceGroup
properties:
location: West Europe
exampleService:
type: azure:apimanagement:Service
properties:
location: ${exampleResourceGroup.location}
resourceGroupName: ${exampleResourceGroup.name}
publisherName: pub1
publisherEmail: pub1@email.com
skuName: Developer_1
exampleNamedValue:
type: azure:apimanagement:NamedValue
properties:
resourceGroupName: ${exampleResourceGroup.name}
apiManagementName: ${exampleService.name}
displayName: ExampleProperty
value: Example Value
examplePolicy:
type: azure:apimanagement:Policy
properties:
apiManagementId: ${exampleService.id}
xmlContent:
fn::readFile: example.xml
Create Policy Resource
new Policy(name: string, args: PolicyArgs, opts?: CustomResourceOptions);
@overload
def Policy(resource_name: str,
opts: Optional[ResourceOptions] = None,
api_management_id: Optional[str] = None,
xml_content: Optional[str] = None,
xml_link: Optional[str] = None)
@overload
def Policy(resource_name: str,
args: PolicyArgs,
opts: Optional[ResourceOptions] = None)
func NewPolicy(ctx *Context, name string, args PolicyArgs, opts ...ResourceOption) (*Policy, error)
public Policy(string name, PolicyArgs args, CustomResourceOptions? opts = null)
public Policy(String name, PolicyArgs args)
public Policy(String name, PolicyArgs args, CustomResourceOptions options)
type: azure:apimanagement:Policy
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args PolicyArgs
- 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 PolicyArgs
- 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 PolicyArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args PolicyArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args PolicyArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Policy 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 Policy resource accepts the following input properties:
- Api
Management stringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- Xml
Content string The XML Content for this Policy as a string.
- Xml
Link string A link to a Policy XML Document, which must be publicly available.
- Api
Management stringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- Xml
Content string The XML Content for this Policy as a string.
- Xml
Link string A link to a Policy XML Document, which must be publicly available.
- api
Management StringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- xml
Content String The XML Content for this Policy as a string.
- xml
Link String A link to a Policy XML Document, which must be publicly available.
- api
Management stringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- xml
Content string The XML Content for this Policy as a string.
- xml
Link string A link to a Policy XML Document, which must be publicly available.
- api_
management_ strid The ID of the API Management service. Changing this forces a new API Management service Policy 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.
- api
Management StringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- xml
Content String The XML Content for this Policy as a string.
- xml
Link 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 Policy 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 Policy Resource
Get an existing Policy 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?: PolicyState, opts?: CustomResourceOptions): Policy
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
api_management_id: Optional[str] = None,
xml_content: Optional[str] = None,
xml_link: Optional[str] = None) -> Policy
func GetPolicy(ctx *Context, name string, id IDInput, state *PolicyState, opts ...ResourceOption) (*Policy, error)
public static Policy Get(string name, Input<string> id, PolicyState? state, CustomResourceOptions? opts = null)
public static Policy get(String name, Output<String> id, PolicyState 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.
- Api
Management stringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- Xml
Content string The XML Content for this Policy as a string.
- Xml
Link string A link to a Policy XML Document, which must be publicly available.
- Api
Management stringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- Xml
Content string The XML Content for this Policy as a string.
- Xml
Link string A link to a Policy XML Document, which must be publicly available.
- api
Management StringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- xml
Content String The XML Content for this Policy as a string.
- xml
Link String A link to a Policy XML Document, which must be publicly available.
- api
Management stringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- xml
Content string The XML Content for this Policy as a string.
- xml
Link string A link to a Policy XML Document, which must be publicly available.
- api_
management_ strid The ID of the API Management service. Changing this forces a new API Management service Policy 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.
- api
Management StringId The ID of the API Management service. Changing this forces a new API Management service Policy to be created.
- xml
Content String The XML Content for this Policy as a string.
- xml
Link String A link to a Policy XML Document, which must be publicly available.
Import
API Management service Policys can be imported using the resource id
, e.g.
$ pulumi import azure:apimanagement/policy:Policy example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/service1
Package Details
- Repository
- Azure Classic pulumi/pulumi-azure
- License
- Apache-2.0
- Notes
This Pulumi package is based on the
azurerm
Terraform Provider.