Try AWS Native preview for resources not in the classic version.
aws.alb.TargetGroupAttachment
Explore with Pulumi AI
Try AWS Native preview for resources not in the classic version.
Provides the ability to register instances and containers with an Application Load Balancer (ALB) or Network Load Balancer (NLB) target group. For attaching resources with Elastic Load Balancer (ELB), see the aws.elb.Attachment
resource.
Note:
aws.alb.TargetGroupAttachment
is known asaws.lb.TargetGroupAttachment
. The functionality is identical.
Example Usage
Basic Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const testTargetGroup = new aws.lb.TargetGroup("test", {});
const testInstance = new aws.ec2.Instance("test", {});
const test = new aws.lb.TargetGroupAttachment("test", {
targetGroupArn: testTargetGroup.arn,
targetId: testInstance.id,
port: 80,
});
import pulumi
import pulumi_aws as aws
test_target_group = aws.lb.TargetGroup("test")
test_instance = aws.ec2.Instance("test")
test = aws.lb.TargetGroupAttachment("test",
target_group_arn=test_target_group.arn,
target_id=test_instance.id,
port=80)
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/ec2"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lb"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
testTargetGroup, err := lb.NewTargetGroup(ctx, "test", nil)
if err != nil {
return err
}
testInstance, err := ec2.NewInstance(ctx, "test", nil)
if err != nil {
return err
}
_, err = lb.NewTargetGroupAttachment(ctx, "test", &lb.TargetGroupAttachmentArgs{
TargetGroupArn: testTargetGroup.Arn,
TargetId: testInstance.ID(),
Port: pulumi.Int(80),
})
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var testTargetGroup = new Aws.LB.TargetGroup("test");
var testInstance = new Aws.Ec2.Instance("test");
var test = new Aws.LB.TargetGroupAttachment("test", new()
{
TargetGroupArn = testTargetGroup.Arn,
TargetId = testInstance.Id,
Port = 80,
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lb.TargetGroup;
import com.pulumi.aws.ec2.Instance;
import com.pulumi.aws.lb.TargetGroupAttachment;
import com.pulumi.aws.lb.TargetGroupAttachmentArgs;
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 testTargetGroup = new TargetGroup("testTargetGroup");
var testInstance = new Instance("testInstance");
var test = new TargetGroupAttachment("test", TargetGroupAttachmentArgs.builder()
.targetGroupArn(testTargetGroup.arn())
.targetId(testInstance.id())
.port(80)
.build());
}
}
resources:
test:
type: aws:lb:TargetGroupAttachment
properties:
targetGroupArn: ${testTargetGroup.arn}
targetId: ${testInstance.id}
port: 80
testTargetGroup:
type: aws:lb:TargetGroup
name: test
testInstance:
type: aws:ec2:Instance
name: test
Lambda Target
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const test = new aws.lb.TargetGroup("test", {
name: "test",
targetType: "lambda",
});
const testFunction = new aws.lambda.Function("test", {});
const withLb = new aws.lambda.Permission("with_lb", {
statementId: "AllowExecutionFromlb",
action: "lambda:InvokeFunction",
"function": testFunction.name,
principal: "elasticloadbalancing.amazonaws.com",
sourceArn: test.arn,
});
const testTargetGroupAttachment = new aws.lb.TargetGroupAttachment("test", {
targetGroupArn: test.arn,
targetId: testFunction.arn,
}, {
dependsOn: [withLb],
});
import pulumi
import pulumi_aws as aws
test = aws.lb.TargetGroup("test",
name="test",
target_type="lambda")
test_function = aws.lambda_.Function("test")
with_lb = aws.lambda_.Permission("with_lb",
statement_id="AllowExecutionFromlb",
action="lambda:InvokeFunction",
function=test_function.name,
principal="elasticloadbalancing.amazonaws.com",
source_arn=test.arn)
test_target_group_attachment = aws.lb.TargetGroupAttachment("test",
target_group_arn=test.arn,
target_id=test_function.arn,
opts = pulumi.ResourceOptions(depends_on=[with_lb]))
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lambda"
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lb"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
test, err := lb.NewTargetGroup(ctx, "test", &lb.TargetGroupArgs{
Name: pulumi.String("test"),
TargetType: pulumi.String("lambda"),
})
if err != nil {
return err
}
testFunction, err := lambda.NewFunction(ctx, "test", nil)
if err != nil {
return err
}
withLb, err := lambda.NewPermission(ctx, "with_lb", &lambda.PermissionArgs{
StatementId: pulumi.String("AllowExecutionFromlb"),
Action: pulumi.String("lambda:InvokeFunction"),
Function: testFunction.Name,
Principal: pulumi.String("elasticloadbalancing.amazonaws.com"),
SourceArn: test.Arn,
})
if err != nil {
return err
}
_, err = lb.NewTargetGroupAttachment(ctx, "test", &lb.TargetGroupAttachmentArgs{
TargetGroupArn: test.Arn,
TargetId: testFunction.Arn,
}, pulumi.DependsOn([]pulumi.Resource{
withLb,
}))
if err != nil {
return err
}
return nil
})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var test = new Aws.LB.TargetGroup("test", new()
{
Name = "test",
TargetType = "lambda",
});
var testFunction = new Aws.Lambda.Function("test");
var withLb = new Aws.Lambda.Permission("with_lb", new()
{
StatementId = "AllowExecutionFromlb",
Action = "lambda:InvokeFunction",
Function = testFunction.Name,
Principal = "elasticloadbalancing.amazonaws.com",
SourceArn = test.Arn,
});
var testTargetGroupAttachment = new Aws.LB.TargetGroupAttachment("test", new()
{
TargetGroupArn = test.Arn,
TargetId = testFunction.Arn,
}, new CustomResourceOptions
{
DependsOn =
{
withLb,
},
});
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lb.TargetGroup;
import com.pulumi.aws.lb.TargetGroupArgs;
import com.pulumi.aws.lambda.Function;
import com.pulumi.aws.lambda.Permission;
import com.pulumi.aws.lambda.PermissionArgs;
import com.pulumi.aws.lb.TargetGroupAttachment;
import com.pulumi.aws.lb.TargetGroupAttachmentArgs;
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 test = new TargetGroup("test", TargetGroupArgs.builder()
.name("test")
.targetType("lambda")
.build());
var testFunction = new Function("testFunction");
var withLb = new Permission("withLb", PermissionArgs.builder()
.statementId("AllowExecutionFromlb")
.action("lambda:InvokeFunction")
.function(testFunction.name())
.principal("elasticloadbalancing.amazonaws.com")
.sourceArn(test.arn())
.build());
var testTargetGroupAttachment = new TargetGroupAttachment("testTargetGroupAttachment", TargetGroupAttachmentArgs.builder()
.targetGroupArn(test.arn())
.targetId(testFunction.arn())
.build(), CustomResourceOptions.builder()
.dependsOn(withLb)
.build());
}
}
resources:
withLb:
type: aws:lambda:Permission
name: with_lb
properties:
statementId: AllowExecutionFromlb
action: lambda:InvokeFunction
function: ${testFunction.name}
principal: elasticloadbalancing.amazonaws.com
sourceArn: ${test.arn}
test:
type: aws:lb:TargetGroup
properties:
name: test
targetType: lambda
testFunction:
type: aws:lambda:Function
name: test
testTargetGroupAttachment:
type: aws:lb:TargetGroupAttachment
name: test
properties:
targetGroupArn: ${test.arn}
targetId: ${testFunction.arn}
options:
dependson:
- ${withLb}
Registering Multiple Targets
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example: aws.ec2.Instance[] = [];
for (const range = {value: 0}; range.value < 3; range.value++) {
example.push(new aws.ec2.Instance(`example-${range.value}`, {}));
}
const exampleTargetGroup = new aws.lb.TargetGroup("example", {});
const exampleTargetGroupAttachment: aws.lb.TargetGroupAttachment[] = [];
pulumi.all(example.map((v, k) => [k, v]).reduce((__obj, [, ]) => ({ ...__obj, [k]: v }))).apply(rangeBody => {
for (const range of Object.entries(rangeBody).map(([k, v]) => ({key: k, value: v}))) {
exampleTargetGroupAttachment.push(new aws.lb.TargetGroupAttachment(`example-${range.key}`, {
targetGroupArn: exampleTargetGroup.arn,
targetId: range.value.id,
port: 80,
}));
}
});
import pulumi
import pulumi_aws as aws
example = []
for range in [{"value": i} for i in range(0, 3)]:
example.append(aws.ec2.Instance(f"example-{range['value']}"))
example_target_group = aws.lb.TargetGroup("example")
example_target_group_attachment = []
def create_example(range_body):
for range in [{"key": k, "value": v} for [k, v] in enumerate(range_body)]:
example_target_group_attachment.append(aws.lb.TargetGroupAttachment(f"example-{range['key']}",
target_group_arn=example_target_group.arn,
target_id=range["value"],
port=80))
pulumi.Output.all({k: v for k, v in example}).apply(lambda resolved_outputs: create_example(resolved_outputs[0]))
Coming soon!
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new List<Aws.Ec2.Instance>();
for (var rangeIndex = 0; rangeIndex < 3; rangeIndex++)
{
var range = new { Value = rangeIndex };
example.Add(new Aws.Ec2.Instance($"example-{range.Value}", new()
{
}));
}
var exampleTargetGroup = new Aws.LB.TargetGroup("example");
var exampleTargetGroupAttachment = new List<Aws.LB.TargetGroupAttachment>();
foreach (var range in example.Select((value, i) => new { Key = i.ToString(), Value = pair.Value }).Select(pair => new { pair.Key, pair.Value }))
{
exampleTargetGroupAttachment.Add(new Aws.LB.TargetGroupAttachment($"example-{range.Key}", new()
{
TargetGroupArn = exampleTargetGroup.Arn,
TargetId = range.Value.Id,
Port = 80,
}));
}
});
Coming soon!
resources:
example:
type: aws:ec2:Instance
options: {}
exampleTargetGroup:
type: aws:lb:TargetGroup
name: example
exampleTargetGroupAttachment:
type: aws:lb:TargetGroupAttachment
name: example
properties:
targetGroupArn: ${exampleTargetGroup.arn}
targetId: ${range.value.id}
port: 80
options: {}
Create TargetGroupAttachment Resource
Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.
Constructor syntax
new TargetGroupAttachment(name: string, args: TargetGroupAttachmentArgs, opts?: CustomResourceOptions);
@overload
def TargetGroupAttachment(resource_name: str,
args: TargetGroupAttachmentArgs,
opts: Optional[ResourceOptions] = None)
@overload
def TargetGroupAttachment(resource_name: str,
opts: Optional[ResourceOptions] = None,
target_group_arn: Optional[str] = None,
target_id: Optional[str] = None,
availability_zone: Optional[str] = None,
port: Optional[int] = None)
func NewTargetGroupAttachment(ctx *Context, name string, args TargetGroupAttachmentArgs, opts ...ResourceOption) (*TargetGroupAttachment, error)
public TargetGroupAttachment(string name, TargetGroupAttachmentArgs args, CustomResourceOptions? opts = null)
public TargetGroupAttachment(String name, TargetGroupAttachmentArgs args)
public TargetGroupAttachment(String name, TargetGroupAttachmentArgs args, CustomResourceOptions options)
type: aws:alb:TargetGroupAttachment
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.
Parameters
- name string
- The unique name of the resource.
- args TargetGroupAttachmentArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- resource_name str
- The unique name of the resource.
- args TargetGroupAttachmentArgs
- The arguments to resource properties.
- opts ResourceOptions
- Bag of options to control resource's behavior.
- ctx Context
- Context object for the current deployment.
- name string
- The unique name of the resource.
- args TargetGroupAttachmentArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args TargetGroupAttachmentArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args TargetGroupAttachmentArgs
- The arguments to resource properties.
- options CustomResourceOptions
- Bag of options to control resource's behavior.
Constructor example
The following reference example uses placeholder values for all input properties.
var targetGroupAttachmentResource = new Aws.Alb.TargetGroupAttachment("targetGroupAttachmentResource", new()
{
TargetGroupArn = "string",
TargetId = "string",
AvailabilityZone = "string",
Port = 0,
});
example, err := alb.NewTargetGroupAttachment(ctx, "targetGroupAttachmentResource", &alb.TargetGroupAttachmentArgs{
TargetGroupArn: pulumi.String("string"),
TargetId: pulumi.String("string"),
AvailabilityZone: pulumi.String("string"),
Port: pulumi.Int(0),
})
var targetGroupAttachmentResource = new TargetGroupAttachment("targetGroupAttachmentResource", TargetGroupAttachmentArgs.builder()
.targetGroupArn("string")
.targetId("string")
.availabilityZone("string")
.port(0)
.build());
target_group_attachment_resource = aws.alb.TargetGroupAttachment("targetGroupAttachmentResource",
target_group_arn="string",
target_id="string",
availability_zone="string",
port=0)
const targetGroupAttachmentResource = new aws.alb.TargetGroupAttachment("targetGroupAttachmentResource", {
targetGroupArn: "string",
targetId: "string",
availabilityZone: "string",
port: 0,
});
type: aws:alb:TargetGroupAttachment
properties:
availabilityZone: string
port: 0
targetGroupArn: string
targetId: string
TargetGroupAttachment Resource Properties
To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.
Inputs
The TargetGroupAttachment resource accepts the following input properties:
- Target
Group stringArn - The ARN of the target group with which to register targets.
- Target
Id string The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- Availability
Zone string - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - Port int
- The port on which targets receive traffic.
- Target
Group stringArn - The ARN of the target group with which to register targets.
- Target
Id string The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- Availability
Zone string - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - Port int
- The port on which targets receive traffic.
- target
Group StringArn - The ARN of the target group with which to register targets.
- target
Id String The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- availability
Zone String - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - port Integer
- The port on which targets receive traffic.
- target
Group stringArn - The ARN of the target group with which to register targets.
- target
Id string The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- availability
Zone string - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - port number
- The port on which targets receive traffic.
- target_
group_ strarn - The ARN of the target group with which to register targets.
- target_
id str The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- availability_
zone str - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - port int
- The port on which targets receive traffic.
- target
Group StringArn - The ARN of the target group with which to register targets.
- target
Id String The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- availability
Zone String - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - port Number
- The port on which targets receive traffic.
Outputs
All input properties are implicitly available as output properties. Additionally, the TargetGroupAttachment resource produces the following output properties:
- Id string
- The provider-assigned unique ID for this managed resource.
- Id string
- The provider-assigned unique ID for this managed resource.
- id String
- The provider-assigned unique ID for this managed resource.
- id string
- The provider-assigned unique ID for this managed resource.
- id str
- The provider-assigned unique ID for this managed resource.
- id String
- The provider-assigned unique ID for this managed resource.
Look up Existing TargetGroupAttachment Resource
Get an existing TargetGroupAttachment resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.
public static get(name: string, id: Input<ID>, state?: TargetGroupAttachmentState, opts?: CustomResourceOptions): TargetGroupAttachment
@staticmethod
def get(resource_name: str,
id: str,
opts: Optional[ResourceOptions] = None,
availability_zone: Optional[str] = None,
port: Optional[int] = None,
target_group_arn: Optional[str] = None,
target_id: Optional[str] = None) -> TargetGroupAttachment
func GetTargetGroupAttachment(ctx *Context, name string, id IDInput, state *TargetGroupAttachmentState, opts ...ResourceOption) (*TargetGroupAttachment, error)
public static TargetGroupAttachment Get(string name, Input<string> id, TargetGroupAttachmentState? state, CustomResourceOptions? opts = null)
public static TargetGroupAttachment get(String name, Output<String> id, TargetGroupAttachmentState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- resource_name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- name
- The unique name of the resulting resource.
- id
- The unique provider ID of the resource to lookup.
- state
- Any extra arguments used during the lookup.
- opts
- A bag of options that control this resource's behavior.
- Availability
Zone string - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - Port int
- The port on which targets receive traffic.
- Target
Group stringArn - The ARN of the target group with which to register targets.
- Target
Id string The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- Availability
Zone string - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - Port int
- The port on which targets receive traffic.
- Target
Group stringArn - The ARN of the target group with which to register targets.
- Target
Id string The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- availability
Zone String - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - port Integer
- The port on which targets receive traffic.
- target
Group StringArn - The ARN of the target group with which to register targets.
- target
Id String The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- availability
Zone string - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - port number
- The port on which targets receive traffic.
- target
Group stringArn - The ARN of the target group with which to register targets.
- target
Id string The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- availability_
zone str - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - port int
- The port on which targets receive traffic.
- target_
group_ strarn - The ARN of the target group with which to register targets.
- target_
id str The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
- availability
Zone String - The Availability Zone where the IP address of the target is to be registered. If the private IP address is outside of the VPC scope, this value must be set to
all
. - port Number
- The port on which targets receive traffic.
- target
Group StringArn - The ARN of the target group with which to register targets.
- target
Id String The ID of the target. This is the Instance ID for an instance, or the container ID for an ECS container. If the target type is
ip
, specify an IP address. If the target type islambda
, specify the Lambda function ARN. If the target type isalb
, specify the ALB ARN.The following arguments are optional:
Import
You cannot import Target Group Attachments.
To learn more about importing existing cloud resources, see Importing resources.
Package Details
- Repository
- AWS Classic pulumi/pulumi-aws
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the
aws
Terraform Provider.
Try AWS Native preview for resources not in the classic version.