@pulumi/aws
Version:
A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.
369 lines • 18.5 kB
JavaScript
;
// *** WARNING: this file was generated by pulumi-language-nodejs. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
Object.defineProperty(exports, "__esModule", { value: true });
exports.Instance = void 0;
const pulumi = require("@pulumi/pulumi");
const utilities = require("../utilities");
/**
* Provides an EC2 instance resource. This allows instances to be created, updated, and deleted.
*
* ## Example Usage
*
* ### Basic example using AMI lookup
*
* Using a data source
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const ubuntu = aws.ec2.getAmi({
* mostRecent: true,
* filters: [
* {
* name: "name",
* values: ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"],
* },
* {
* name: "virtualization-type",
* values: ["hvm"],
* },
* ],
* owners: ["099720109477"],
* });
* const web = new aws.ec2.Instance("web", {
* ami: ubuntu.then(ubuntu => ubuntu.id),
* instanceType: aws.ec2.InstanceType.T3_Micro,
* tags: {
* Name: "HelloWorld",
* },
* });
* ```
*
* Using AWS Systems Manager Parameter Store
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const web = new aws.ec2.Instance("web", {
* ami: "resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64",
* instanceType: aws.ec2.InstanceType.T3_Micro,
* tags: {
* Name: "HelloWorld",
* },
* });
* ```
*
* ### Spot instance example
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const _this = aws.ec2.getAmi({
* mostRecent: true,
* owners: ["amazon"],
* filters: [
* {
* name: "architecture",
* values: ["arm64"],
* },
* {
* name: "name",
* values: ["al2023-ami-2023*"],
* },
* ],
* });
* const thisInstance = new aws.ec2.Instance("this", {
* ami: _this.then(_this => _this.id),
* instanceMarketOptions: {
* marketType: "spot",
* spotOptions: {
* maxPrice: "0.0031",
* },
* },
* instanceType: aws.ec2.InstanceType.T4g_Nano,
* tags: {
* Name: "test-spot",
* },
* });
* ```
*
* ### Network and credit specification example
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const myVpc = new aws.ec2.Vpc("my_vpc", {
* cidrBlock: "172.16.0.0/16",
* tags: {
* Name: "tf-example",
* },
* });
* const mySubnet = new aws.ec2.Subnet("my_subnet", {
* vpcId: myVpc.id,
* cidrBlock: "172.16.10.0/24",
* availabilityZone: "us-west-2a",
* tags: {
* Name: "tf-example",
* },
* });
* const foo = new aws.ec2.NetworkInterface("foo", {
* subnetId: mySubnet.id,
* privateIps: ["172.16.10.100"],
* tags: {
* Name: "primary_network_interface",
* },
* });
* const fooInstance = new aws.ec2.Instance("foo", {
* ami: "ami-005e54dee72cc1d00",
* instanceType: aws.ec2.InstanceType.T2_Micro,
* networkInterfaces: [{
* networkInterfaceId: foo.id,
* deviceIndex: 0,
* }],
* creditSpecification: {
* cpuCredits: "unlimited",
* },
* });
* ```
*
* ### CPU options example
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const example = new aws.ec2.Vpc("example", {
* cidrBlock: "172.16.0.0/16",
* tags: {
* Name: "tf-example",
* },
* });
* const exampleSubnet = new aws.ec2.Subnet("example", {
* vpcId: example.id,
* cidrBlock: "172.16.10.0/24",
* availabilityZone: "us-east-2a",
* tags: {
* Name: "tf-example",
* },
* });
* const amzn_linux_2023_ami = aws.ec2.getAmi({
* mostRecent: true,
* owners: ["amazon"],
* filters: [{
* name: "name",
* values: ["al2023-ami-2023.*-x86_64"],
* }],
* });
* const exampleInstance = new aws.ec2.Instance("example", {
* ami: amzn_linux_2023_ami.then(amzn_linux_2023_ami => amzn_linux_2023_ami.id),
* instanceType: aws.ec2.InstanceType.C6a_2XLarge,
* subnetId: exampleSubnet.id,
* cpuOptions: {
* coreCount: 2,
* threadsPerCore: 2,
* },
* tags: {
* Name: "tf-example",
* },
* });
* ```
*
* ### Host resource group or License Manager registered AMI example
*
* A host resource group is a collection of Dedicated Hosts that you can manage as a single entity. As you launch instances, License Manager allocates the hosts and launches instances on them based on the settings that you configured. You can add existing Dedicated Hosts to a host resource group and take advantage of automated host management through License Manager.
*
* > **NOTE:** A dedicated host is automatically associated with a License Manager host resource group if **Allocate hosts automatically** is enabled. Otherwise, use the `hostResourceGroupArn` argument to explicitly associate the instance with the host resource group.
*
* ```typescript
* import * as pulumi from "@pulumi/pulumi";
* import * as aws from "@pulumi/aws";
*
* const _this = new aws.ec2.Instance("this", {
* ami: "ami-0dcc1e21636832c5d",
* instanceType: aws.ec2.InstanceType.M5_Large,
* hostResourceGroupArn: "arn:aws:resource-groups:us-west-2:123456789012:group/win-testhost",
* tenancy: "host",
* });
* ```
*
* ## Tag Guide
*
* These are the five types of tags you might encounter relative to an `aws.ec2.Instance`:
*
* 1. **Instance tags**: Applied to instances but not to `ebsBlockDevice` and `rootBlockDevice` volumes.
* 2. **Default tags**: Applied to the instance and to `ebsBlockDevice` and `rootBlockDevice` volumes.
* 3. **Volume tags**: Applied during creation to `ebsBlockDevice` and `rootBlockDevice` volumes.
* 4. **Root block device tags**: Applied only to the `rootBlockDevice` volume. These conflict with `volumeTags`.
* 5. **EBS block device tags**: Applied only to the specific `ebsBlockDevice` volume you configure them for and cannot be updated. These conflict with `volumeTags`.
*
* Do not use `volumeTags` if you plan to manage block device tags outside the `aws.ec2.Instance` configuration, such as using `tags` in an `aws.ebs.Volume` resource attached via `aws.ec2.VolumeAttachment`. Doing so will result in resource cycling and inconsistent behavior.
*
* ## Import
*
* Using `pulumi import`, import instances using the `id`. For example:
*
* ```sh
* $ pulumi import aws:ec2/instance:Instance web i-12345678
* ```
*/
class Instance extends pulumi.CustomResource {
/**
* Get an existing Instance 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 Instance(name, state, Object.assign(Object.assign({}, opts), { id: id }));
}
/**
* Returns true if the given object is an instance of Instance. 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'] === Instance.__pulumiType;
}
constructor(name, argsOrState, opts) {
let resourceInputs = {};
opts = opts || {};
if (opts.id) {
const state = argsOrState;
resourceInputs["ami"] = state ? state.ami : undefined;
resourceInputs["arn"] = state ? state.arn : undefined;
resourceInputs["associatePublicIpAddress"] = state ? state.associatePublicIpAddress : undefined;
resourceInputs["availabilityZone"] = state ? state.availabilityZone : undefined;
resourceInputs["capacityReservationSpecification"] = state ? state.capacityReservationSpecification : undefined;
resourceInputs["cpuOptions"] = state ? state.cpuOptions : undefined;
resourceInputs["creditSpecification"] = state ? state.creditSpecification : undefined;
resourceInputs["disableApiStop"] = state ? state.disableApiStop : undefined;
resourceInputs["disableApiTermination"] = state ? state.disableApiTermination : undefined;
resourceInputs["ebsBlockDevices"] = state ? state.ebsBlockDevices : undefined;
resourceInputs["ebsOptimized"] = state ? state.ebsOptimized : undefined;
resourceInputs["enablePrimaryIpv6"] = state ? state.enablePrimaryIpv6 : undefined;
resourceInputs["enclaveOptions"] = state ? state.enclaveOptions : undefined;
resourceInputs["ephemeralBlockDevices"] = state ? state.ephemeralBlockDevices : undefined;
resourceInputs["forceDestroy"] = state ? state.forceDestroy : undefined;
resourceInputs["getPasswordData"] = state ? state.getPasswordData : undefined;
resourceInputs["hibernation"] = state ? state.hibernation : undefined;
resourceInputs["hostId"] = state ? state.hostId : undefined;
resourceInputs["hostResourceGroupArn"] = state ? state.hostResourceGroupArn : undefined;
resourceInputs["iamInstanceProfile"] = state ? state.iamInstanceProfile : undefined;
resourceInputs["instanceInitiatedShutdownBehavior"] = state ? state.instanceInitiatedShutdownBehavior : undefined;
resourceInputs["instanceLifecycle"] = state ? state.instanceLifecycle : undefined;
resourceInputs["instanceMarketOptions"] = state ? state.instanceMarketOptions : undefined;
resourceInputs["instanceState"] = state ? state.instanceState : undefined;
resourceInputs["instanceType"] = state ? state.instanceType : undefined;
resourceInputs["ipv6AddressCount"] = state ? state.ipv6AddressCount : undefined;
resourceInputs["ipv6Addresses"] = state ? state.ipv6Addresses : undefined;
resourceInputs["keyName"] = state ? state.keyName : undefined;
resourceInputs["launchTemplate"] = state ? state.launchTemplate : undefined;
resourceInputs["maintenanceOptions"] = state ? state.maintenanceOptions : undefined;
resourceInputs["metadataOptions"] = state ? state.metadataOptions : undefined;
resourceInputs["monitoring"] = state ? state.monitoring : undefined;
resourceInputs["networkInterfaces"] = state ? state.networkInterfaces : undefined;
resourceInputs["outpostArn"] = state ? state.outpostArn : undefined;
resourceInputs["passwordData"] = state ? state.passwordData : undefined;
resourceInputs["placementGroup"] = state ? state.placementGroup : undefined;
resourceInputs["placementPartitionNumber"] = state ? state.placementPartitionNumber : undefined;
resourceInputs["primaryNetworkInterfaceId"] = state ? state.primaryNetworkInterfaceId : undefined;
resourceInputs["privateDns"] = state ? state.privateDns : undefined;
resourceInputs["privateDnsNameOptions"] = state ? state.privateDnsNameOptions : undefined;
resourceInputs["privateIp"] = state ? state.privateIp : undefined;
resourceInputs["publicDns"] = state ? state.publicDns : undefined;
resourceInputs["publicIp"] = state ? state.publicIp : undefined;
resourceInputs["region"] = state ? state.region : undefined;
resourceInputs["rootBlockDevice"] = state ? state.rootBlockDevice : undefined;
resourceInputs["secondaryPrivateIps"] = state ? state.secondaryPrivateIps : undefined;
resourceInputs["securityGroups"] = state ? state.securityGroups : undefined;
resourceInputs["sourceDestCheck"] = state ? state.sourceDestCheck : undefined;
resourceInputs["spotInstanceRequestId"] = state ? state.spotInstanceRequestId : undefined;
resourceInputs["subnetId"] = state ? state.subnetId : undefined;
resourceInputs["tags"] = state ? state.tags : undefined;
resourceInputs["tagsAll"] = state ? state.tagsAll : undefined;
resourceInputs["tenancy"] = state ? state.tenancy : undefined;
resourceInputs["userData"] = state ? state.userData : undefined;
resourceInputs["userDataBase64"] = state ? state.userDataBase64 : undefined;
resourceInputs["userDataReplaceOnChange"] = state ? state.userDataReplaceOnChange : undefined;
resourceInputs["volumeTags"] = state ? state.volumeTags : undefined;
resourceInputs["vpcSecurityGroupIds"] = state ? state.vpcSecurityGroupIds : undefined;
}
else {
const args = argsOrState;
resourceInputs["ami"] = args ? args.ami : undefined;
resourceInputs["associatePublicIpAddress"] = args ? args.associatePublicIpAddress : undefined;
resourceInputs["availabilityZone"] = args ? args.availabilityZone : undefined;
resourceInputs["capacityReservationSpecification"] = args ? args.capacityReservationSpecification : undefined;
resourceInputs["cpuOptions"] = args ? args.cpuOptions : undefined;
resourceInputs["creditSpecification"] = args ? args.creditSpecification : undefined;
resourceInputs["disableApiStop"] = args ? args.disableApiStop : undefined;
resourceInputs["disableApiTermination"] = args ? args.disableApiTermination : undefined;
resourceInputs["ebsBlockDevices"] = args ? args.ebsBlockDevices : undefined;
resourceInputs["ebsOptimized"] = args ? args.ebsOptimized : undefined;
resourceInputs["enablePrimaryIpv6"] = args ? args.enablePrimaryIpv6 : undefined;
resourceInputs["enclaveOptions"] = args ? args.enclaveOptions : undefined;
resourceInputs["ephemeralBlockDevices"] = args ? args.ephemeralBlockDevices : undefined;
resourceInputs["forceDestroy"] = args ? args.forceDestroy : undefined;
resourceInputs["getPasswordData"] = args ? args.getPasswordData : undefined;
resourceInputs["hibernation"] = args ? args.hibernation : undefined;
resourceInputs["hostId"] = args ? args.hostId : undefined;
resourceInputs["hostResourceGroupArn"] = args ? args.hostResourceGroupArn : undefined;
resourceInputs["iamInstanceProfile"] = args ? args.iamInstanceProfile : undefined;
resourceInputs["instanceInitiatedShutdownBehavior"] = args ? args.instanceInitiatedShutdownBehavior : undefined;
resourceInputs["instanceMarketOptions"] = args ? args.instanceMarketOptions : undefined;
resourceInputs["instanceType"] = args ? args.instanceType : undefined;
resourceInputs["ipv6AddressCount"] = args ? args.ipv6AddressCount : undefined;
resourceInputs["ipv6Addresses"] = args ? args.ipv6Addresses : undefined;
resourceInputs["keyName"] = args ? args.keyName : undefined;
resourceInputs["launchTemplate"] = args ? args.launchTemplate : undefined;
resourceInputs["maintenanceOptions"] = args ? args.maintenanceOptions : undefined;
resourceInputs["metadataOptions"] = args ? args.metadataOptions : undefined;
resourceInputs["monitoring"] = args ? args.monitoring : undefined;
resourceInputs["networkInterfaces"] = args ? args.networkInterfaces : undefined;
resourceInputs["placementGroup"] = args ? args.placementGroup : undefined;
resourceInputs["placementPartitionNumber"] = args ? args.placementPartitionNumber : undefined;
resourceInputs["privateDnsNameOptions"] = args ? args.privateDnsNameOptions : undefined;
resourceInputs["privateIp"] = args ? args.privateIp : undefined;
resourceInputs["region"] = args ? args.region : undefined;
resourceInputs["rootBlockDevice"] = args ? args.rootBlockDevice : undefined;
resourceInputs["secondaryPrivateIps"] = args ? args.secondaryPrivateIps : undefined;
resourceInputs["securityGroups"] = args ? args.securityGroups : undefined;
resourceInputs["sourceDestCheck"] = args ? args.sourceDestCheck : undefined;
resourceInputs["subnetId"] = args ? args.subnetId : undefined;
resourceInputs["tags"] = args ? args.tags : undefined;
resourceInputs["tenancy"] = args ? args.tenancy : undefined;
resourceInputs["userData"] = args ? args.userData : undefined;
resourceInputs["userDataBase64"] = args ? args.userDataBase64 : undefined;
resourceInputs["userDataReplaceOnChange"] = args ? args.userDataReplaceOnChange : undefined;
resourceInputs["volumeTags"] = args ? args.volumeTags : undefined;
resourceInputs["vpcSecurityGroupIds"] = args ? args.vpcSecurityGroupIds : undefined;
resourceInputs["arn"] = undefined /*out*/;
resourceInputs["instanceLifecycle"] = undefined /*out*/;
resourceInputs["instanceState"] = undefined /*out*/;
resourceInputs["outpostArn"] = undefined /*out*/;
resourceInputs["passwordData"] = undefined /*out*/;
resourceInputs["primaryNetworkInterfaceId"] = undefined /*out*/;
resourceInputs["privateDns"] = undefined /*out*/;
resourceInputs["publicDns"] = undefined /*out*/;
resourceInputs["publicIp"] = undefined /*out*/;
resourceInputs["spotInstanceRequestId"] = undefined /*out*/;
resourceInputs["tagsAll"] = undefined /*out*/;
}
opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts);
super(Instance.__pulumiType, name, resourceInputs, opts);
}
}
exports.Instance = Instance;
/** @internal */
Instance.__pulumiType = 'aws:ec2/instance:Instance';
//# sourceMappingURL=instance.js.map