1. Packages
  2. AWS
  3. API Docs
  4. lb
  5. getHostedZoneId
AWS v6.54.0 published on Friday, Sep 27, 2024 by Pulumi

aws.lb.getHostedZoneId

Explore with Pulumi AI

aws logo
AWS v6.54.0 published on Friday, Sep 27, 2024 by Pulumi

    Use this data source to get the HostedZoneId of the AWS Elastic Load Balancing (ELB) in a given region for the purpose of using in an AWS Route53 Alias. Specify the ELB type (network or application) to return the relevant the associated HostedZoneId. Ref: ELB service endpoints

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as aws from "@pulumi/aws";
    
    const main = aws.lb.getHostedZoneId({});
    const www = new aws.route53.Record("www", {
        zoneId: primary.zoneId,
        name: "example.com",
        type: aws.route53.RecordType.A,
        aliases: [{
            name: mainAwsLb.dnsName,
            zoneId: main.then(main => main.id),
            evaluateTargetHealth: true,
        }],
    });
    
    import pulumi
    import pulumi_aws as aws
    
    main = aws.lb.get_hosted_zone_id()
    www = aws.route53.Record("www",
        zone_id=primary["zoneId"],
        name="example.com",
        type=aws.route53.RecordType.A,
        aliases=[{
            "name": main_aws_lb["dnsName"],
            "zone_id": main.id,
            "evaluate_target_health": True,
        }])
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lb"
    	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/route53"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		main, err := lb.GetHostedZoneId(ctx, nil, nil)
    		if err != nil {
    			return err
    		}
    		_, err = route53.NewRecord(ctx, "www", &route53.RecordArgs{
    			ZoneId: pulumi.Any(primary.ZoneId),
    			Name:   pulumi.String("example.com"),
    			Type:   pulumi.String(route53.RecordTypeA),
    			Aliases: route53.RecordAliasArray{
    				&route53.RecordAliasArgs{
    					Name:                 pulumi.Any(mainAwsLb.DnsName),
    					ZoneId:               pulumi.String(main.Id),
    					EvaluateTargetHealth: pulumi.Bool(true),
    				},
    			},
    		})
    		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 main = Aws.LB.GetHostedZoneId.Invoke();
    
        var www = new Aws.Route53.Record("www", new()
        {
            ZoneId = primary.ZoneId,
            Name = "example.com",
            Type = Aws.Route53.RecordType.A,
            Aliases = new[]
            {
                new Aws.Route53.Inputs.RecordAliasArgs
                {
                    Name = mainAwsLb.DnsName,
                    ZoneId = main.Apply(getHostedZoneIdResult => getHostedZoneIdResult.Id),
                    EvaluateTargetHealth = true,
                },
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.aws.lb.LbFunctions;
    import com.pulumi.aws.lb.inputs.GetHostedZoneIdArgs;
    import com.pulumi.aws.route53.Record;
    import com.pulumi.aws.route53.RecordArgs;
    import com.pulumi.aws.route53.inputs.RecordAliasArgs;
    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 main = LbFunctions.getHostedZoneId();
    
            var www = new Record("www", RecordArgs.builder()
                .zoneId(primary.zoneId())
                .name("example.com")
                .type("A")
                .aliases(RecordAliasArgs.builder()
                    .name(mainAwsLb.dnsName())
                    .zoneId(main.applyValue(getHostedZoneIdResult -> getHostedZoneIdResult.id()))
                    .evaluateTargetHealth(true)
                    .build())
                .build());
    
        }
    }
    
    resources:
      www:
        type: aws:route53:Record
        properties:
          zoneId: ${primary.zoneId}
          name: example.com
          type: A
          aliases:
            - name: ${mainAwsLb.dnsName}
              zoneId: ${main.id}
              evaluateTargetHealth: true
    variables:
      main:
        fn::invoke:
          Function: aws:lb:getHostedZoneId
          Arguments: {}
    

    Using getHostedZoneId

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getHostedZoneId(args: GetHostedZoneIdArgs, opts?: InvokeOptions): Promise<GetHostedZoneIdResult>
    function getHostedZoneIdOutput(args: GetHostedZoneIdOutputArgs, opts?: InvokeOptions): Output<GetHostedZoneIdResult>
    def get_hosted_zone_id(load_balancer_type: Optional[str] = None,
                           region: Optional[str] = None,
                           opts: Optional[InvokeOptions] = None) -> GetHostedZoneIdResult
    def get_hosted_zone_id_output(load_balancer_type: Optional[pulumi.Input[str]] = None,
                           region: Optional[pulumi.Input[str]] = None,
                           opts: Optional[InvokeOptions] = None) -> Output[GetHostedZoneIdResult]
    func GetHostedZoneId(ctx *Context, args *GetHostedZoneIdArgs, opts ...InvokeOption) (*GetHostedZoneIdResult, error)
    func GetHostedZoneIdOutput(ctx *Context, args *GetHostedZoneIdOutputArgs, opts ...InvokeOption) GetHostedZoneIdResultOutput

    > Note: This function is named GetHostedZoneId in the Go SDK.

    public static class GetHostedZoneId 
    {
        public static Task<GetHostedZoneIdResult> InvokeAsync(GetHostedZoneIdArgs args, InvokeOptions? opts = null)
        public static Output<GetHostedZoneIdResult> Invoke(GetHostedZoneIdInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetHostedZoneIdResult> getHostedZoneId(GetHostedZoneIdArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: aws:lb/getHostedZoneId:getHostedZoneId
      arguments:
        # arguments dictionary

    The following arguments are supported:

    LoadBalancerType string
    Type of load balancer to create. Possible values are application or network. The default value is application.
    Region string
    Name of the region whose AWS ELB HostedZoneId is desired. Defaults to the region from the AWS provider configuration.
    LoadBalancerType string
    Type of load balancer to create. Possible values are application or network. The default value is application.
    Region string
    Name of the region whose AWS ELB HostedZoneId is desired. Defaults to the region from the AWS provider configuration.
    loadBalancerType String
    Type of load balancer to create. Possible values are application or network. The default value is application.
    region String
    Name of the region whose AWS ELB HostedZoneId is desired. Defaults to the region from the AWS provider configuration.
    loadBalancerType string
    Type of load balancer to create. Possible values are application or network. The default value is application.
    region string
    Name of the region whose AWS ELB HostedZoneId is desired. Defaults to the region from the AWS provider configuration.
    load_balancer_type str
    Type of load balancer to create. Possible values are application or network. The default value is application.
    region str
    Name of the region whose AWS ELB HostedZoneId is desired. Defaults to the region from the AWS provider configuration.
    loadBalancerType String
    Type of load balancer to create. Possible values are application or network. The default value is application.
    region String
    Name of the region whose AWS ELB HostedZoneId is desired. Defaults to the region from the AWS provider configuration.

    getHostedZoneId Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    LoadBalancerType string
    Region string
    Id string
    The provider-assigned unique ID for this managed resource.
    LoadBalancerType string
    Region string
    id String
    The provider-assigned unique ID for this managed resource.
    loadBalancerType String
    region String
    id string
    The provider-assigned unique ID for this managed resource.
    loadBalancerType string
    region string
    id str
    The provider-assigned unique ID for this managed resource.
    load_balancer_type str
    region str
    id String
    The provider-assigned unique ID for this managed resource.
    loadBalancerType String
    region String

    Package Details

    Repository
    AWS Classic pulumi/pulumi-aws
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the aws Terraform Provider.
    aws logo
    AWS v6.54.0 published on Friday, Sep 27, 2024 by Pulumi