All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pulumi.azure.apimanagement.kotlin.Subscription.kt Maven / Gradle / Ivy

@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.azure.apimanagement.kotlin

import com.pulumi.core.Output
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.String
import kotlin.Suppress
import kotlin.Unit

/**
 * Builder for [Subscription].
 */
@PulumiTagMarker
public class SubscriptionResourceBuilder internal constructor() {
    public var name: String? = null

    public var args: SubscriptionArgs = SubscriptionArgs()

    public var opts: CustomResourceOptions = CustomResourceOptions()

    /**
     * @param name The _unique_ name of the resulting resource.
     */
    public fun name(`value`: String) {
        this.name = value
    }

    /**
     * @param block The arguments to use to populate this resource's properties.
     */
    public suspend fun args(block: suspend SubscriptionArgsBuilder.() -> Unit) {
        val builder = SubscriptionArgsBuilder()
        block(builder)
        this.args = builder.build()
    }

    /**
     * @param block A bag of options that control this resource's behavior.
     */
    public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
        this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
    }

    internal fun build(): Subscription {
        val builtJavaResource = com.pulumi.azure.apimanagement.Subscription(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return Subscription(builtJavaResource)
    }
}

/**
 * Manages a Subscription within a API Management Service.
 * ## Example Usage
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as azure from "@pulumi/azure";
 * const example = azure.apimanagement.getService({
 *     name: "example-apim",
 *     resourceGroupName: "example-resources",
 * });
 * const exampleGetProduct = Promise.all([example, example]).then(([example, example1]) => azure.apimanagement.getProduct({
 *     productId: "00000000-0000-0000-0000-000000000000",
 *     apiManagementName: example.name,
 *     resourceGroupName: example1.resourceGroupName,
 * }));
 * const exampleGetUser = Promise.all([example, example]).then(([example, example1]) => azure.apimanagement.getUser({
 *     userId: "11111111-1111-1111-1111-111111111111",
 *     apiManagementName: example.name,
 *     resourceGroupName: example1.resourceGroupName,
 * }));
 * const exampleSubscription = new azure.apimanagement.Subscription("example", {
 *     apiManagementName: example.then(example => example.name),
 *     resourceGroupName: example.then(example => example.resourceGroupName),
 *     userId: exampleGetUser.then(exampleGetUser => exampleGetUser.id),
 *     productId: exampleGetProduct.then(exampleGetProduct => exampleGetProduct.id),
 *     displayName: "Parser API",
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_azure as azure
 * example = azure.apimanagement.get_service(name="example-apim",
 *     resource_group_name="example-resources")
 * example_get_product = azure.apimanagement.get_product(product_id="00000000-0000-0000-0000-000000000000",
 *     api_management_name=example.name,
 *     resource_group_name=example.resource_group_name)
 * example_get_user = azure.apimanagement.get_user(user_id="11111111-1111-1111-1111-111111111111",
 *     api_management_name=example.name,
 *     resource_group_name=example.resource_group_name)
 * example_subscription = azure.apimanagement.Subscription("example",
 *     api_management_name=example.name,
 *     resource_group_name=example.resource_group_name,
 *     user_id=example_get_user.id,
 *     product_id=example_get_product.id,
 *     display_name="Parser API")
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Azure = Pulumi.Azure;
 * return await Deployment.RunAsync(() =>
 * {
 *     var example = Azure.ApiManagement.GetService.Invoke(new()
 *     {
 *         Name = "example-apim",
 *         ResourceGroupName = "example-resources",
 *     });
 *     var exampleGetProduct = Azure.ApiManagement.GetProduct.Invoke(new()
 *     {
 *         ProductId = "00000000-0000-0000-0000-000000000000",
 *         ApiManagementName = example.Apply(getServiceResult => getServiceResult.Name),
 *         ResourceGroupName = example.Apply(getServiceResult => getServiceResult.ResourceGroupName),
 *     });
 *     var exampleGetUser = Azure.ApiManagement.GetUser.Invoke(new()
 *     {
 *         UserId = "11111111-1111-1111-1111-111111111111",
 *         ApiManagementName = example.Apply(getServiceResult => getServiceResult.Name),
 *         ResourceGroupName = example.Apply(getServiceResult => getServiceResult.ResourceGroupName),
 *     });
 *     var exampleSubscription = new Azure.ApiManagement.Subscription("example", new()
 *     {
 *         ApiManagementName = example.Apply(getServiceResult => getServiceResult.Name),
 *         ResourceGroupName = example.Apply(getServiceResult => getServiceResult.ResourceGroupName),
 *         UserId = exampleGetUser.Apply(getUserResult => getUserResult.Id),
 *         ProductId = exampleGetProduct.Apply(getProductResult => getProductResult.Id),
 *         DisplayName = "Parser API",
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"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 {
 * 		example, err := apimanagement.LookupService(ctx, &apimanagement.LookupServiceArgs{
 * 			Name:              "example-apim",
 * 			ResourceGroupName: "example-resources",
 * 		}, nil)
 * 		if err != nil {
 * 			return err
 * 		}
 * 		exampleGetProduct, err := apimanagement.LookupProduct(ctx, &apimanagement.LookupProductArgs{
 * 			ProductId:         "00000000-0000-0000-0000-000000000000",
 * 			ApiManagementName: example.Name,
 * 			ResourceGroupName: example.ResourceGroupName,
 * 		}, nil)
 * 		if err != nil {
 * 			return err
 * 		}
 * 		exampleGetUser, err := apimanagement.LookupUser(ctx, &apimanagement.LookupUserArgs{
 * 			UserId:            "11111111-1111-1111-1111-111111111111",
 * 			ApiManagementName: example.Name,
 * 			ResourceGroupName: example.ResourceGroupName,
 * 		}, nil)
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = apimanagement.NewSubscription(ctx, "example", &apimanagement.SubscriptionArgs{
 * 			ApiManagementName: pulumi.String(example.Name),
 * 			ResourceGroupName: pulumi.String(example.ResourceGroupName),
 * 			UserId:            pulumi.String(exampleGetUser.Id),
 * 			ProductId:         pulumi.String(exampleGetProduct.Id),
 * 			DisplayName:       pulumi.String("Parser API"),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		return nil
 * 	})
 * }
 * ```
 * ```java
 * 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.GetServiceArgs;
 * import com.pulumi.azure.apimanagement.inputs.GetProductArgs;
 * import com.pulumi.azure.apimanagement.inputs.GetUserArgs;
 * import com.pulumi.azure.apimanagement.Subscription;
 * import com.pulumi.azure.apimanagement.SubscriptionArgs;
 * 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.getService(GetServiceArgs.builder()
 *             .name("example-apim")
 *             .resourceGroupName("example-resources")
 *             .build());
 *         final var exampleGetProduct = ApimanagementFunctions.getProduct(GetProductArgs.builder()
 *             .productId("00000000-0000-0000-0000-000000000000")
 *             .apiManagementName(example.applyValue(getServiceResult -> getServiceResult.name()))
 *             .resourceGroupName(example.applyValue(getServiceResult -> getServiceResult.resourceGroupName()))
 *             .build());
 *         final var exampleGetUser = ApimanagementFunctions.getUser(GetUserArgs.builder()
 *             .userId("11111111-1111-1111-1111-111111111111")
 *             .apiManagementName(example.applyValue(getServiceResult -> getServiceResult.name()))
 *             .resourceGroupName(example.applyValue(getServiceResult -> getServiceResult.resourceGroupName()))
 *             .build());
 *         var exampleSubscription = new Subscription("exampleSubscription", SubscriptionArgs.builder()
 *             .apiManagementName(example.applyValue(getServiceResult -> getServiceResult.name()))
 *             .resourceGroupName(example.applyValue(getServiceResult -> getServiceResult.resourceGroupName()))
 *             .userId(exampleGetUser.applyValue(getUserResult -> getUserResult.id()))
 *             .productId(exampleGetProduct.applyValue(getProductResult -> getProductResult.id()))
 *             .displayName("Parser API")
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   exampleSubscription:
 *     type: azure:apimanagement:Subscription
 *     name: example
 *     properties:
 *       apiManagementName: ${example.name}
 *       resourceGroupName: ${example.resourceGroupName}
 *       userId: ${exampleGetUser.id}
 *       productId: ${exampleGetProduct.id}
 *       displayName: Parser API
 * variables:
 *   example:
 *     fn::invoke:
 *       Function: azure:apimanagement:getService
 *       Arguments:
 *         name: example-apim
 *         resourceGroupName: example-resources
 *   exampleGetProduct:
 *     fn::invoke:
 *       Function: azure:apimanagement:getProduct
 *       Arguments:
 *         productId: 00000000-0000-0000-0000-000000000000
 *         apiManagementName: ${example.name}
 *         resourceGroupName: ${example.resourceGroupName}
 *   exampleGetUser:
 *     fn::invoke:
 *       Function: azure:apimanagement:getUser
 *       Arguments:
 *         userId: 11111111-1111-1111-1111-111111111111
 *         apiManagementName: ${example.name}
 *         resourceGroupName: ${example.resourceGroupName}
 * ```
 * 
 * ## Import
 * API Management Subscriptions can be imported using the `resource id`, e.g.
 * ```sh
 * $ pulumi import azure:apimanagement/subscription:Subscription example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resources/providers/Microsoft.ApiManagement/service/example-apim/subscriptions/subscription-name
 * ```
 */
public class Subscription internal constructor(
    override val javaResource: com.pulumi.azure.apimanagement.Subscription,
) : KotlinCustomResource(javaResource, SubscriptionMapper) {
    /**
     * Determines whether tracing can be enabled. Defaults to `true`.
     */
    public val allowTracing: Output?
        get() = javaResource.allowTracing().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The ID of the API which should be assigned to this Subscription. Changing this forces a new resource to be created.
     * > **Info:** Only one of `product_id` and `api_id` can be set. If both are missing `/apis` scope is used for the subscription and all apis are accessible.
     */
    public val apiId: Output?
        get() = javaResource.apiId().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The name of the API Management Service where this Subscription should be created. Changing this forces a new resource to be created.
     */
    public val apiManagementName: Output
        get() = javaResource.apiManagementName().applyValue({ args0 -> args0 })

    /**
     * The display name of this Subscription.
     */
    public val displayName: Output
        get() = javaResource.displayName().applyValue({ args0 -> args0 })

    /**
     * The primary subscription key to use for the subscription.
     */
    public val primaryKey: Output
        get() = javaResource.primaryKey().applyValue({ args0 -> args0 })

    /**
     * The ID of the Product which should be assigned to this Subscription. Changing this forces a new resource to be created.
     * > **Info:** Only one of `product_id` and `api_id` can be set. If both are missing `all_apis` scope is used for the subscription.
     */
    public val productId: Output?
        get() = javaResource.productId().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * The name of the Resource Group in which the API Management Service exists. Changing this forces a new resource to be created.
     */
    public val resourceGroupName: Output
        get() = javaResource.resourceGroupName().applyValue({ args0 -> args0 })

    /**
     * The secondary subscription key to use for the subscription.
     */
    public val secondaryKey: Output
        get() = javaResource.secondaryKey().applyValue({ args0 -> args0 })

    /**
     * The state of this Subscription. Possible values are `active`, `cancelled`, `expired`, `rejected`, `submitted` and `suspended`. Defaults to `submitted`.
     */
    public val state: Output?
        get() = javaResource.state().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })

    /**
     * An Identifier which should used as the ID of this Subscription. If not specified a new Subscription ID will be generated. Changing this forces a new resource to be created.
     */
    public val subscriptionId: Output
        get() = javaResource.subscriptionId().applyValue({ args0 -> args0 })

    /**
     * The ID of the User which should be assigned to this Subscription. Changing this forces a new resource to be created.
     */
    public val userId: Output?
        get() = javaResource.userId().applyValue({ args0 -> args0.map({ args0 -> args0 }).orElse(null) })
}

public object SubscriptionMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.azure.apimanagement.Subscription::class == javaResource::class

    override fun map(javaResource: Resource): Subscription = Subscription(
        javaResource as
            com.pulumi.azure.apimanagement.Subscription,
    )
}

/**
 * @see [Subscription].
 * @param name The _unique_ name of the resulting resource.
 * @param block Builder for [Subscription].
 */
public suspend fun subscription(
    name: String,
    block: suspend SubscriptionResourceBuilder.() -> Unit,
): Subscription {
    val builder = SubscriptionResourceBuilder()
    builder.name(name)
    block(builder)
    return builder.build()
}

/**
 * @see [Subscription].
 * @param name The _unique_ name of the resulting resource.
 */
public fun subscription(name: String): Subscription {
    val builder = SubscriptionResourceBuilder()
    builder.name(name)
    return builder.build()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy