ComputeEnvironment

class ComputeEnvironment : KotlinCustomResource

Creates a AWS Batch compute environment. Compute environments contain the Amazon ECS container instances that are used to run containerized batch jobs. For information about AWS Batch, see What is AWS Batch? . For information about compute environment, see Compute Environments .

Note: To prevent a race condition during environment deletion, make sure to set depends_on to the related aws.iam.RolePolicyAttachment; otherwise, the policy may be destroyed too soon and the compute environment will then get stuck in the DELETING state, see Troubleshooting AWS Batch .

Example Usage

EC2 Type

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.iam.IamFunctions;
import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
import com.pulumi.aws.iam.Role;
import com.pulumi.aws.iam.RoleArgs;
import com.pulumi.aws.iam.RolePolicyAttachment;
import com.pulumi.aws.iam.RolePolicyAttachmentArgs;
import com.pulumi.aws.iam.InstanceProfile;
import com.pulumi.aws.iam.InstanceProfileArgs;
import com.pulumi.aws.ec2.SecurityGroup;
import com.pulumi.aws.ec2.SecurityGroupArgs;
import com.pulumi.aws.ec2.inputs.SecurityGroupEgressArgs;
import com.pulumi.aws.ec2.Vpc;
import com.pulumi.aws.ec2.VpcArgs;
import com.pulumi.aws.ec2.Subnet;
import com.pulumi.aws.ec2.SubnetArgs;
import com.pulumi.aws.batch.ComputeEnvironment;
import com.pulumi.aws.batch.ComputeEnvironmentArgs;
import com.pulumi.aws.batch.inputs.ComputeEnvironmentComputeResourcesArgs;
import com.pulumi.resources.CustomResourceOptions;
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 ec2AssumeRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.effect("Allow")
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("Service")
.identifiers("ec2.amazonaws.com")
.build())
.actions("sts:AssumeRole")
.build())
.build());
var ecsInstanceRoleRole = new Role("ecsInstanceRoleRole", RoleArgs.builder()
.assumeRolePolicy(ec2AssumeRole.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json()))
.build());
var ecsInstanceRoleRolePolicyAttachment = new RolePolicyAttachment("ecsInstanceRoleRolePolicyAttachment", RolePolicyAttachmentArgs.builder()
.role(ecsInstanceRoleRole.name())
.policyArn("arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role")
.build());
var ecsInstanceRoleInstanceProfile = new InstanceProfile("ecsInstanceRoleInstanceProfile", InstanceProfileArgs.builder()
.role(ecsInstanceRoleRole.name())
.build());
final var batchAssumeRole = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
.statements(GetPolicyDocumentStatementArgs.builder()
.effect("Allow")
.principals(GetPolicyDocumentStatementPrincipalArgs.builder()
.type("Service")
.identifiers("batch.amazonaws.com")
.build())
.actions("sts:AssumeRole")
.build())
.build());
var awsBatchServiceRoleRole = new Role("awsBatchServiceRoleRole", RoleArgs.builder()
.assumeRolePolicy(batchAssumeRole.applyValue(getPolicyDocumentResult -> getPolicyDocumentResult.json()))
.build());
var awsBatchServiceRoleRolePolicyAttachment = new RolePolicyAttachment("awsBatchServiceRoleRolePolicyAttachment", RolePolicyAttachmentArgs.builder()
.role(awsBatchServiceRoleRole.name())
.policyArn("arn:aws:iam::aws:policy/service-role/AWSBatchServiceRole")
.build());
var sampleSecurityGroup = new SecurityGroup("sampleSecurityGroup", SecurityGroupArgs.builder()
.egress(SecurityGroupEgressArgs.builder()
.fromPort(0)
.toPort(0)
.protocol("-1")
.cidrBlocks("0.0.0.0/0")
.build())
.build());
var sampleVpc = new Vpc("sampleVpc", VpcArgs.builder()
.cidrBlock("10.1.0.0/16")
.build());
var sampleSubnet = new Subnet("sampleSubnet", SubnetArgs.builder()
.vpcId(sampleVpc.id())
.cidrBlock("10.1.1.0/24")
.build());
var sampleComputeEnvironment = new ComputeEnvironment("sampleComputeEnvironment", ComputeEnvironmentArgs.builder()
.computeEnvironmentName("sample")
.computeResources(ComputeEnvironmentComputeResourcesArgs.builder()
.instanceRole(ecsInstanceRoleInstanceProfile.arn())
.instanceTypes("c4.large")
.maxVcpus(16)
.minVcpus(0)
.securityGroupIds(sampleSecurityGroup.id())
.subnets(sampleSubnet.id())
.type("EC2")
.build())
.serviceRole(awsBatchServiceRoleRole.arn())
.type("MANAGED")
.build(), CustomResourceOptions.builder()
.dependsOn(awsBatchServiceRoleRolePolicyAttachment)
.build());
}
}

Fargate Type

package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.batch.ComputeEnvironment;
import com.pulumi.aws.batch.ComputeEnvironmentArgs;
import com.pulumi.aws.batch.inputs.ComputeEnvironmentComputeResourcesArgs;
import com.pulumi.resources.CustomResourceOptions;
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 sample = new ComputeEnvironment("sample", ComputeEnvironmentArgs.builder()
.computeEnvironmentName("sample")
.computeResources(ComputeEnvironmentComputeResourcesArgs.builder()
.maxVcpus(16)
.securityGroupIds(aws_security_group.sample().id())
.subnets(aws_subnet.sample().id())
.type("FARGATE")
.build())
.serviceRole(aws_iam_role.aws_batch_service_role().arn())
.type("MANAGED")
.build(), CustomResourceOptions.builder()
.dependsOn(aws_iam_role_policy_attachment.aws_batch_service_role())
.build());
}
}

Import

AWS Batch compute can be imported using the compute_environment_name, e.g.,

$ pulumi import aws:batch/computeEnvironment:ComputeEnvironment sample sample

1http://docs.aws.amazon.com/batch/latest/userguide/what-is-batch.html 2http://docs.aws.amazon.com/batch/latest/userguide/compute_environments.html 3http://docs.aws.amazon.com/batch/latest/userguide/troubleshooting.html

Properties

Link copied to clipboard
val arn: Output<String>

The Amazon Resource Name (ARN) of the compute environment.

Link copied to clipboard

The name for your compute environment. Up to 128 letters (uppercase and lowercase), numbers, and underscores are allowed. If omitted, the provider will assign a random, unique name.

Link copied to clipboard

Creates a unique compute environment name beginning with the specified prefix. Conflicts with compute_environment_name.

Link copied to clipboard

Details of the compute resources managed by the compute environment. This parameter is required for managed compute environments. See details below.

Link copied to clipboard
val ecsClusterArn: Output<String>

The Amazon Resource Name (ARN) of the underlying Amazon ECS cluster used by the compute environment.

Link copied to clipboard

Details for the Amazon EKS cluster that supports the compute environment. See details below.

Link copied to clipboard
val id: Output<String>
Link copied to clipboard
val pulumiChildResources: Set<KotlinResource>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val serviceRole: Output<String>

The full Amazon Resource Name (ARN) of the IAM role that allows AWS Batch to make calls to other AWS services on your behalf.

Link copied to clipboard
val state: Output<String>?

The state of the compute environment. If the state is ENABLED, then the compute environment accepts jobs from a queue and can scale out automatically based on queues. Valid items are ENABLED or DISABLED. Defaults to ENABLED.

Link copied to clipboard
val status: Output<String>

The current status of the compute environment (for example, CREATING or VALID).

Link copied to clipboard
val statusReason: Output<String>

A short, human-readable string to provide additional details about the current status of the compute environment.

Link copied to clipboard
val tags: Output<Map<String, String>>?

Key-value map of resource tags. If configured with a provider default_tags configuration block present, tags with matching keys will overwrite those defined at the provider-level.

Link copied to clipboard
val tagsAll: Output<Map<String, String>>

A map of tags assigned to the resource, including those inherited from the provider default_tags configuration block.

Link copied to clipboard
val type: Output<String>

The type of the compute environment. Valid items are MANAGED or UNMANAGED.

Link copied to clipboard
val urn: Output<String>