# TargetGroupIpAddressType

The IP address type of targets registered with a target group.

- Source: [`aws-elasticloadbalancingv2/lib/shared/base-target-group.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/shared/base-target-group.ts#L20)
- Type last changed: v2.172.0 · 7 Dec 2024

## Example

TypeScript:

```ts
declare const vpc: ec2.Vpc;

const ipv4ApplicationTargetGroup = new elbv2.ApplicationTargetGroup(this, 'IPv4ApplicationTargetGroup', {
  vpc,
  port: 80,
  targetType: elbv2.TargetType.INSTANCE,
  ipAddressType: elbv2.TargetGroupIpAddressType.IPV4,
});

const ipv6ApplicationTargetGroup = new elbv2.ApplicationTargetGroup(this, 'Ipv6ApplicationTargetGroup', {
  vpc,
  port: 80,
  targetType: elbv2.TargetType.INSTANCE,
  ipAddressType: elbv2.TargetGroupIpAddressType.IPV6,
});

const ipv4NetworkTargetGroup = new elbv2.NetworkTargetGroup(this, 'IPv4NetworkTargetGroup', {
  vpc,
  port: 80,
  targetType: elbv2.TargetType.INSTANCE,
  ipAddressType: elbv2.TargetGroupIpAddressType.IPV4,
});

const ipv6NetworkTargetGroup = new elbv2.NetworkTargetGroup(this, 'Ipv6NetworkTargetGroup', {
  vpc,
  port: 80,
  targetType: elbv2.TargetType.INSTANCE,
  ipAddressType: elbv2.TargetGroupIpAddressType.IPV6,
});
```

Python:

```python
# vpc: ec2.Vpc

ipv4_application_target_group = elbv2.ApplicationTargetGroup(self, "IPv4ApplicationTargetGroup",
    vpc=vpc,
    port=80,
    target_type=elbv2.TargetType.INSTANCE,
    ip_address_type=elbv2.TargetGroupIpAddressType.IPV4
)

ipv6_application_target_group = elbv2.ApplicationTargetGroup(self, "Ipv6ApplicationTargetGroup",
    vpc=vpc,
    port=80,
    target_type=elbv2.TargetType.INSTANCE,
    ip_address_type=elbv2.TargetGroupIpAddressType.IPV6
)

ipv4_network_target_group = elbv2.NetworkTargetGroup(self, "IPv4NetworkTargetGroup",
    vpc=vpc,
    port=80,
    target_type=elbv2.TargetType.INSTANCE,
    ip_address_type=elbv2.TargetGroupIpAddressType.IPV4
)

ipv6_network_target_group = elbv2.NetworkTargetGroup(self, "Ipv6NetworkTargetGroup",
    vpc=vpc,
    port=80,
    target_type=elbv2.TargetType.INSTANCE,
    ip_address_type=elbv2.TargetGroupIpAddressType.IPV6
)
```

Java:

```java
Vpc vpc;

ApplicationTargetGroup ipv4ApplicationTargetGroup = ApplicationTargetGroup.Builder.create(this, "IPv4ApplicationTargetGroup")
        .vpc(vpc)
        .port(80)
        .targetType(TargetType.INSTANCE)
        .ipAddressType(TargetGroupIpAddressType.IPV4)
        .build();

ApplicationTargetGroup ipv6ApplicationTargetGroup = ApplicationTargetGroup.Builder.create(this, "Ipv6ApplicationTargetGroup")
        .vpc(vpc)
        .port(80)
        .targetType(TargetType.INSTANCE)
        .ipAddressType(TargetGroupIpAddressType.IPV6)
        .build();

NetworkTargetGroup ipv4NetworkTargetGroup = NetworkTargetGroup.Builder.create(this, "IPv4NetworkTargetGroup")
        .vpc(vpc)
        .port(80)
        .targetType(TargetType.INSTANCE)
        .ipAddressType(TargetGroupIpAddressType.IPV4)
        .build();

NetworkTargetGroup ipv6NetworkTargetGroup = NetworkTargetGroup.Builder.create(this, "Ipv6NetworkTargetGroup")
        .vpc(vpc)
        .port(80)
        .targetType(TargetType.INSTANCE)
        .ipAddressType(TargetGroupIpAddressType.IPV6)
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;

var ipv4ApplicationTargetGroup = new ApplicationTargetGroup(this, "IPv4ApplicationTargetGroup", new ApplicationTargetGroupProps {
    Vpc = vpc,
    Port = 80,
    TargetType = TargetType.INSTANCE,
    IpAddressType = TargetGroupIpAddressType.IPV4
});

var ipv6ApplicationTargetGroup = new ApplicationTargetGroup(this, "Ipv6ApplicationTargetGroup", new ApplicationTargetGroupProps {
    Vpc = vpc,
    Port = 80,
    TargetType = TargetType.INSTANCE,
    IpAddressType = TargetGroupIpAddressType.IPV6
});

var ipv4NetworkTargetGroup = new NetworkTargetGroup(this, "IPv4NetworkTargetGroup", new NetworkTargetGroupProps {
    Vpc = vpc,
    Port = 80,
    TargetType = TargetType.INSTANCE,
    IpAddressType = TargetGroupIpAddressType.IPV4
});

var ipv6NetworkTargetGroup = new NetworkTargetGroup(this, "Ipv6NetworkTargetGroup", new NetworkTargetGroupProps {
    Vpc = vpc,
    Port = 80,
    TargetType = TargetType.INSTANCE,
    IpAddressType = TargetGroupIpAddressType.IPV6
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc

ipv4ApplicationTargetGroup := elbv2.NewApplicationTargetGroup(this, jsii.String("IPv4ApplicationTargetGroup"), &ApplicationTargetGroupProps{
	Vpc: Vpc,
	Port: jsii.Number(80),
	TargetType: elbv2.TargetType_INSTANCE,
	IpAddressType: elbv2.TargetGroupIpAddressType_IPV4,
})

ipv6ApplicationTargetGroup := elbv2.NewApplicationTargetGroup(this, jsii.String("Ipv6ApplicationTargetGroup"), &ApplicationTargetGroupProps{
	Vpc: Vpc,
	Port: jsii.Number(80),
	TargetType: elbv2.TargetType_INSTANCE,
	IpAddressType: elbv2.TargetGroupIpAddressType_IPV6,
})

ipv4NetworkTargetGroup := elbv2.NewNetworkTargetGroup(this, jsii.String("IPv4NetworkTargetGroup"), &NetworkTargetGroupProps{
	Vpc: Vpc,
	Port: jsii.Number(80),
	TargetType: elbv2.TargetType_INSTANCE,
	IpAddressType: elbv2.TargetGroupIpAddressType_IPV4,
})

ipv6NetworkTargetGroup := elbv2.NewNetworkTargetGroup(this, jsii.String("Ipv6NetworkTargetGroup"), &NetworkTargetGroupProps{
	Vpc: Vpc,
	Port: jsii.Number(80),
	TargetType: elbv2.TargetType_INSTANCE,
	IpAddressType: elbv2.TargetGroupIpAddressType_IPV6,
})
```

## Members

| Member | Description |
| --- | --- |
| `IPV4` | IPv4 addresses. |
| `IPV6` | IPv6 addresses. |

## Referenced by

- [`BaseTargetGroupProps`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_elasticloadbalancingv2.BaseTargetGroupProps.html).ipAddressType
