"use strict";
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Subscription = void 0;
const pulumi = __importStar(require("@pulumi/pulumi"));
const utilities = __importStar(require("../utilities"));
/**
 * Manages an Alias for a Subscription - which adds an Alias to an existing Subscription, allowing it to be managed in the provider - or create a new Subscription with a new Alias.
 *
 * > **NOTE:** Destroying a Subscription controlled by this resource will place the Subscription into a cancelled state. It is possible to re-activate a subscription within 90-days of cancellation, after which time the Subscription is irrevocably deleted, and the Subscription ID cannot be re-used. For further information see [here](https://docs.microsoft.com/azure/cost-management-billing/manage/cancel-azure-subscription#what-happens-after-subscription-cancellation). Users can optionally delete a Subscription once 72 hours have passed, however, this functionality is not suitable for this provider. A `Deleted` subscription cannot be reactivated.
 *
 * > **NOTE:** It is not possible to destroy (cancel) a subscription if it contains resources. If resources are present that are not managed by the provider then these will need to be removed before the Subscription can be destroyed.
 *
 * > **Note:** This resource will automatically attempt to cancel a subscription when it is deleted. This behavior can be disabled in the provider `features` block by setting the `preventCancellationOnDestroy` field to `true` within the `subscription` block.
 *
 * > **NOTE:** Azure supports Multiple Aliases per Subscription, however, to reliably manage this resource in Terraform only a single Alias is supported.
 *
 * > **NOTE:** Subscription Aliases have their own RBAC scope, separate from the underlying Subscription. If an Alias already exists and the Service Principal lacks read/write permissions on that Alias, you may encounter a `401 Unauthorized` error. To resolve this, the Alias creator or a Global Administrator must assign the `Owner` role on the Alias scope to the Service Principal. Global Administrators may need to [elevate access](https://learn.microsoft.com/en-us/azure/role-based-access-control/elevate-access-global-admin) to gain visibility over all subscriptions before performing the role assignment.
 *
 * > **NOTE:** When using this resource across tenants the `clientId` and `tenantId` of the `provider` config block should be for the home tenant details for the SPN / User or a permissions error will likely be encountered. See [the official documentation](https://learn.microsoft.com/en-us/azure/cost-management-billing/manage/programmatically-create-subscription) for more details.
 *
 * ## Example Usage
 *
 * ### Creating A New Alias And Subscription For An Enrollment Account
 *
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as azure from "@pulumi/azure";
 *
 * const example = azure.billing.getEnrollmentAccountScope({
 *     billingAccountName: "1234567890",
 *     enrollmentAccountName: "0123456",
 * });
 * const exampleSubscription = new azure.core.Subscription("example", {
 *     subscriptionName: "My Example EA Subscription",
 *     billingScopeId: example.then(example => example.id),
 * });
 * ```
 *
 * ### Creating A New Alias And Subscription For A Microsoft Customer Account
 *
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as azure from "@pulumi/azure";
 *
 * const example = azure.billing.getMcaAccountScope({
 *     billingAccountName: "e879cf0f-2b4d-5431-109a-f72fc9868693:024cabf4-7321-4cf9-be59-df0c77ca51de_2019-05-31",
 *     billingProfileName: "PE2Q-NOIT-BG7-TGB",
 *     invoiceSectionName: "MTT4-OBS7-PJA-TGB",
 * });
 * const exampleSubscription = new azure.core.Subscription("example", {
 *     subscriptionName: "My Example MCA Subscription",
 *     billingScopeId: example.then(example => example.id),
 * });
 * ```
 *
 * ### Creating A New Alias And Subscription For A Microsoft Partner Account
 *
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as azure from "@pulumi/azure";
 *
 * const example = azure.billing.getMpaAccountScope({
 *     billingAccountName: "e879cf0f-2b4d-5431-109a-f72fc9868693:024cabf4-7321-4cf9-be59-df0c77ca51de_2019-05-31",
 *     customerName: "2281f543-7321-4cf9-1e23-edb4Oc31a31c",
 * });
 * const exampleSubscription = new azure.core.Subscription("example", {
 *     subscriptionName: "My Example MPA Subscription",
 *     billingScopeId: example.then(example => example.id),
 * });
 * ```
 *
 * ### Adding An Alias To An Existing Subscription
 *
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as azure from "@pulumi/azure";
 *
 * const example = new azure.core.Subscription("example", {
 *     alias: "examplesub",
 *     subscriptionName: "My Example Subscription",
 *     subscriptionId: "12345678-12234-5678-9012-123456789012",
 * });
 * ```
 *
 * ## API Providers
 *
 * <!-- This section is generated, changes will be overwritten -->
 * This resource uses the following Azure API Providers:
 *
 * * `Microsoft.Resources` - 2023-07-01
 *
 * ## Import
 *
 * Subscriptions can be imported using the `resource id`, e.g.
 *
 * ```sh
 * $ pulumi import azure:core/subscription:Subscription example "/providers/Microsoft.Subscription/aliases/subscription1"
 * ```
 *
 * !> **Note:** When importing a Subscription that was not created programmatically, either via this resource or using the Alias API, it will have no Alias ID to import via `pulumi import`. In this scenario, the `subscriptionId` property can be completed and the resource will assume control of the existing subscription by creating an Alias. See the `adding an Alias to an existing Subscription` above. An alias is required to correctly manage Subscription resources due to Azure Subscription API design.
 */
class Subscription extends pulumi.CustomResource {
    /**
     * Get an existing Subscription resource's state with the given name, ID, and optional extra
     * properties used to qualify the lookup.
     *
     * @param name The _unique_ name of the resulting resource.
     * @param id The _unique_ provider ID of the resource to lookup.
     * @param state Any extra arguments used during the lookup.
     * @param opts Optional settings to control the behavior of the CustomResource.
     */
    static get(name, id, state, opts) {
        return new Subscription(name, state, { ...opts, id: id });
    }
    /** @internal */
    static __pulumiType = 'azure:core/subscription:Subscription';
    /**
     * Returns true if the given object is an instance of Subscription.  This is designed to work even
     * when multiple copies of the Pulumi SDK have been loaded into the same process.
     */
    static isInstance(obj) {
        if (obj === undefined || obj === null) {
            return false;
        }
        return obj['__pulumiType'] === Subscription.__pulumiType;
    }
    constructor(name, argsOrState, opts) {
        let resourceInputs = {};
        opts = opts || {};
        if (opts.id) {
            const state = argsOrState;
            resourceInputs["alias"] = state?.alias;
            resourceInputs["billingScopeId"] = state?.billingScopeId;
            resourceInputs["subscriptionId"] = state?.subscriptionId;
            resourceInputs["subscriptionName"] = state?.subscriptionName;
            resourceInputs["tags"] = state?.tags;
            resourceInputs["tenantId"] = state?.tenantId;
            resourceInputs["workload"] = state?.workload;
        }
        else {
            const args = argsOrState;
            if (args?.subscriptionName === undefined && !opts.urn) {
                throw new Error("Missing required property 'subscriptionName'");
            }
            resourceInputs["alias"] = args?.alias;
            resourceInputs["billingScopeId"] = args?.billingScopeId;
            resourceInputs["subscriptionId"] = args?.subscriptionId;
            resourceInputs["subscriptionName"] = args?.subscriptionName;
            resourceInputs["tags"] = args?.tags;
            resourceInputs["workload"] = args?.workload;
            resourceInputs["tenantId"] = undefined /*out*/;
        }
        opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
        super(Subscription.__pulumiType, name, resourceInputs, opts);
    }
}
exports.Subscription = Subscription;
//# sourceMappingURL=subscription.js.map