UNPKG

@pulumi/aws

Version:

A Pulumi package for creating and managing Amazon Web Services (AWS) cloud resources.

320 lines • 11.7 kB
"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! *** Object.defineProperty(exports, "__esModule", { value: true }); exports.Association = void 0; const pulumi = require("@pulumi/pulumi"); const utilities = require("../utilities"); /** * Associates an SSM Document to an instance or EC2 tag. * * ## Example Usage * * ### Create an association for a specific instance * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.ssm.Association("example", { * name: exampleAwsSsmDocument.name, * targets: [{ * key: "InstanceIds", * values: [exampleAwsInstance.id], * }], * }); * ``` * * ### Create an association for all managed instances in an AWS account * * To target all managed instances in an AWS account, set the `key` as `"InstanceIds"` with `values` set as `["*"]`. This example also illustrates how to use an Amazon owned SSM document named `AmazonCloudWatch-ManageAgent`. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.ssm.Association("example", { * name: "AmazonCloudWatch-ManageAgent", * targets: [{ * key: "InstanceIds", * values: ["*"], * }], * }); * ``` * * ### Create an association for a specific tag * * This example shows how to target all managed instances that are assigned a tag key of `Environment` and value of `Development`. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.ssm.Association("example", { * name: "AmazonCloudWatch-ManageAgent", * targets: [{ * key: "tag:Environment", * values: ["Development"], * }], * }); * ``` * * ### Create an association with a specific schedule * * This example shows how to schedule an association in various ways. * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * * const example = new aws.ssm.Association("example", { * name: exampleAwsSsmDocument.name, * scheduleExpression: "cron(0 2 ? * SUN *)", * targets: [{ * key: "InstanceIds", * values: [exampleAwsInstance.id], * }], * }); * ``` * * ### Create an association with multiple instances with their instance ids * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * // First EC2 instance * const webServer1 = new aws.ec2.Instance("web_server_1", { * ami: amazonLinux.id, * instanceType: aws.ec2.InstanceType.T3_Micro, * subnetId: _public.id, * vpcSecurityGroupIds: [ec2Sg.id], * iamInstanceProfile: ec2SsmProfile.name, * userData: `#!/bin/bash * yum update -y * yum install -y amazon-ssm-agent * systemctl enable amazon-ssm-agent * systemctl start amazon-ssm-agent * `, * }); * // Second EC2 instance * const webServer2 = new aws.ec2.Instance("web_server_2", { * ami: amazonLinux.id, * instanceType: aws.ec2.InstanceType.T3_Micro, * subnetId: _public.id, * vpcSecurityGroupIds: [ec2Sg.id], * iamInstanceProfile: ec2SsmProfile.name, * userData: `#!/bin/bash * yum update -y * yum install -y amazon-ssm-agent * systemctl enable amazon-ssm-agent * systemctl start amazon-ssm-agent * `, * }); * // Removed EC2 provisioning dependencies for brevity * const systemUpdate = new aws.ssm.Association("system_update", { * name: "AWS-RunShellScript", * targets: [{ * key: "InstanceIds", * values: [ * webServer1.id, * webServer2.id, * ], * }], * scheduleExpression: "cron(0 2 ? * SUN *)", * parameters: { * commands: std.join({ * separator: "\n", * input: [ * "#!/bin/bash", * "echo 'Starting system update on $(hostname)'", * "echo 'Instance ID: $(curl -s http://169.254.169.254/latest/meta-data/instance-id)'", * "yum update -y", * "echo 'System update completed successfully'", * "systemctl status httpd", * "df -h", * "free -m", * ], * }).then(invoke => invoke.result), * workingDirectory: "/tmp", * executionTimeout: "3600", * }, * associationName: "weekly-system-update", * complianceSeverity: "MEDIUM", * maxConcurrency: "1", * maxErrors: "0", * tags: { * Name: "Weekly System Update", * Environment: "demo", * Purpose: "maintenance", * }, * }); * ``` * * ### Create an association with multiple instances with their values matching their tags * * ```typescript * import * as pulumi from "@pulumi/pulumi"; * import * as aws from "@pulumi/aws"; * import * as std from "@pulumi/std"; * * // SSM Association for Webbased Servers * const databaseAssociation = new aws.ssm.Association("database_association", { * name: systemUpdate.name, * targets: [{ * key: "tag:Role", * values: [ * "WebServer", * "Database", * ], * }], * parameters: { * restartServices: "true", * }, * scheduleExpression: "cron(0 3 ? * SUN *)", * }); * // EC2 Instance 1 - Web Server with "ServerType" tag * const webServer = new aws.ec2.Instance("web_server", { * ami: amazonLinux.id, * instanceType: aws.ec2.InstanceType.T3_Micro, * subnetId: _default.id, * vpcSecurityGroupIds: [ec2Sg.id], * iamInstanceProfile: ec2SsmProfile.name, * userData: std.base64encode({ * input: `#!/bin/bash * yum update -y * yum install -y amazon-ssm-agent * systemctl enable amazon-ssm-agent * systemctl start amazon-ssm-agent * * # Install Apache web server * yum install -y httpd * systemctl enable httpd * systemctl start httpd * echo "<h1>Web Server - ${prefix}</h1>" > /var/www/html/index.html * `, * }).then(invoke => invoke.result), * tags: { * Name: `${prefix}-web-server`, * ServerType: "WebServer", * Role: "WebServer", * Environment: environment, * Owner: owner, * }, * }); * // EC2 Instance 2 - Database Server with "Role" tag * const databaseServer = new aws.ec2.Instance("database_server", { * ami: amazonLinux.id, * instanceType: aws.ec2.InstanceType.T3_Micro, * subnetId: _default.id, * vpcSecurityGroupIds: [ec2Sg.id], * iamInstanceProfile: ec2SsmProfile.name, * userData: std.base64encode({ * input: `#!/bin/bash * yum update -y * yum install -y amazon-ssm-agent * systemctl enable amazon-ssm-agent * systemctl start amazon-ssm-agent * * # Install MySQL * yum install -y mysql-server * systemctl enable mysqld * systemctl start mysqld * `, * }).then(invoke => invoke.result), * tags: { * Name: `${prefix}-database-server`, * Role: "Database", * Environment: environment, * Owner: owner, * }, * }); * ``` * * ## Import * * Using `pulumi import`, import SSM associations using the `association_id`. For example: * * ```sh * $ pulumi import aws:ssm/association:Association test-association 10abcdef-0abc-1234-5678-90abcdef123456 * ``` */ class Association extends pulumi.CustomResource { /** * Get an existing Association 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 Association(name, state, { ...opts, id: id }); } /** * Returns true if the given object is an instance of Association. 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'] === Association.__pulumiType; } constructor(name, argsOrState, opts) { let resourceInputs = {}; opts = opts || {}; if (opts.id) { const state = argsOrState; resourceInputs["applyOnlyAtCronInterval"] = state?.applyOnlyAtCronInterval; resourceInputs["arn"] = state?.arn; resourceInputs["associationId"] = state?.associationId; resourceInputs["associationName"] = state?.associationName; resourceInputs["automationTargetParameterName"] = state?.automationTargetParameterName; resourceInputs["complianceSeverity"] = state?.complianceSeverity; resourceInputs["documentVersion"] = state?.documentVersion; resourceInputs["maxConcurrency"] = state?.maxConcurrency; resourceInputs["maxErrors"] = state?.maxErrors; resourceInputs["name"] = state?.name; resourceInputs["outputLocation"] = state?.outputLocation; resourceInputs["parameters"] = state?.parameters; resourceInputs["region"] = state?.region; resourceInputs["scheduleExpression"] = state?.scheduleExpression; resourceInputs["syncCompliance"] = state?.syncCompliance; resourceInputs["tags"] = state?.tags; resourceInputs["tagsAll"] = state?.tagsAll; resourceInputs["targets"] = state?.targets; resourceInputs["waitForSuccessTimeoutSeconds"] = state?.waitForSuccessTimeoutSeconds; } else { const args = argsOrState; resourceInputs["applyOnlyAtCronInterval"] = args?.applyOnlyAtCronInterval; resourceInputs["associationName"] = args?.associationName; resourceInputs["automationTargetParameterName"] = args?.automationTargetParameterName; resourceInputs["complianceSeverity"] = args?.complianceSeverity; resourceInputs["documentVersion"] = args?.documentVersion; resourceInputs["maxConcurrency"] = args?.maxConcurrency; resourceInputs["maxErrors"] = args?.maxErrors; resourceInputs["name"] = args?.name; resourceInputs["outputLocation"] = args?.outputLocation; resourceInputs["parameters"] = args?.parameters; resourceInputs["region"] = args?.region; resourceInputs["scheduleExpression"] = args?.scheduleExpression; resourceInputs["syncCompliance"] = args?.syncCompliance; resourceInputs["tags"] = args?.tags; resourceInputs["targets"] = args?.targets; resourceInputs["waitForSuccessTimeoutSeconds"] = args?.waitForSuccessTimeoutSeconds; resourceInputs["arn"] = undefined /*out*/; resourceInputs["associationId"] = undefined /*out*/; resourceInputs["tagsAll"] = undefined /*out*/; } opts = pulumi.mergeOptions(utilities.resourceOptsDefaults(), opts); super(Association.__pulumiType, name, resourceInputs, opts); } } exports.Association = Association; /** @internal */ Association.__pulumiType = 'aws:ssm/association:Association'; //# sourceMappingURL=association.js.map