1. Packages
  2. Azure Classic
  3. API Docs
  4. sql
  5. getDatabase

We recommend using Azure Native.

Azure Classic v5.72.0 published on Monday, Apr 15, 2024 by Pulumi

azure.sql.getDatabase

Explore with Pulumi AI

azure logo

We recommend using Azure Native.

Azure Classic v5.72.0 published on Monday, Apr 15, 2024 by Pulumi

    Use this data source to access information about an existing SQL Azure Database.

    Note: The azure.sql.Database data source is deprecated in version 3.0 of the AzureRM provider and will be removed in version 4.0. Please use the azure.mssql.Database data source instead.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as azure from "@pulumi/azure";
    
    const example = azure.sql.getDatabase({
        name: "example_db",
        serverName: "example_db_server",
        resourceGroupName: "example-resources",
    });
    export const sqlDatabaseId = example.then(example => example.id);
    
    import pulumi
    import pulumi_azure as azure
    
    example = azure.sql.get_database(name="example_db",
        server_name="example_db_server",
        resource_group_name="example-resources")
    pulumi.export("sqlDatabaseId", example.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/sql"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		example, err := sql.LookupDatabase(ctx, &sql.LookupDatabaseArgs{
    			Name:              "example_db",
    			ServerName:        "example_db_server",
    			ResourceGroupName: "example-resources",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		ctx.Export("sqlDatabaseId", example.Id)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Azure = Pulumi.Azure;
    
    return await Deployment.RunAsync(() => 
    {
        var example = Azure.Sql.GetDatabase.Invoke(new()
        {
            Name = "example_db",
            ServerName = "example_db_server",
            ResourceGroupName = "example-resources",
        });
    
        return new Dictionary<string, object?>
        {
            ["sqlDatabaseId"] = example.Apply(getDatabaseResult => getDatabaseResult.Id),
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.azure.sql.SqlFunctions;
    import com.pulumi.azure.sql.inputs.GetDatabaseArgs;
    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 example = SqlFunctions.getDatabase(GetDatabaseArgs.builder()
                .name("example_db")
                .serverName("example_db_server")
                .resourceGroupName("example-resources")
                .build());
    
            ctx.export("sqlDatabaseId", example.applyValue(getDatabaseResult -> getDatabaseResult.id()));
        }
    }
    
    variables:
      example:
        fn::invoke:
          Function: azure:sql:getDatabase
          Arguments:
            name: example_db
            serverName: example_db_server
            resourceGroupName: example-resources
    outputs:
      sqlDatabaseId: ${example.id}
    

    Using getDatabase

    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 getDatabase(args: GetDatabaseArgs, opts?: InvokeOptions): Promise<GetDatabaseResult>
    function getDatabaseOutput(args: GetDatabaseOutputArgs, opts?: InvokeOptions): Output<GetDatabaseResult>
    def get_database(name: Optional[str] = None,
                     resource_group_name: Optional[str] = None,
                     server_name: Optional[str] = None,
                     tags: Optional[Mapping[str, str]] = None,
                     opts: Optional[InvokeOptions] = None) -> GetDatabaseResult
    def get_database_output(name: Optional[pulumi.Input[str]] = None,
                     resource_group_name: Optional[pulumi.Input[str]] = None,
                     server_name: Optional[pulumi.Input[str]] = None,
                     tags: Optional[pulumi.Input[Mapping[str, pulumi.Input[str]]]] = None,
                     opts: Optional[InvokeOptions] = None) -> Output[GetDatabaseResult]
    func LookupDatabase(ctx *Context, args *LookupDatabaseArgs, opts ...InvokeOption) (*LookupDatabaseResult, error)
    func LookupDatabaseOutput(ctx *Context, args *LookupDatabaseOutputArgs, opts ...InvokeOption) LookupDatabaseResultOutput

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

    public static class GetDatabase 
    {
        public static Task<GetDatabaseResult> InvokeAsync(GetDatabaseArgs args, InvokeOptions? opts = null)
        public static Output<GetDatabaseResult> Invoke(GetDatabaseInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetDatabaseResult> getDatabase(GetDatabaseArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: azure:sql/getDatabase:getDatabase
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Name string
    The name of the SQL Database.
    ResourceGroupName string
    Specifies the name of the Resource Group where the Azure SQL Database exists.
    ServerName string
    The name of the SQL Server.
    Tags Dictionary<string, string>
    A mapping of tags assigned to the resource.
    Name string
    The name of the SQL Database.
    ResourceGroupName string
    Specifies the name of the Resource Group where the Azure SQL Database exists.
    ServerName string
    The name of the SQL Server.
    Tags map[string]string
    A mapping of tags assigned to the resource.
    name String
    The name of the SQL Database.
    resourceGroupName String
    Specifies the name of the Resource Group where the Azure SQL Database exists.
    serverName String
    The name of the SQL Server.
    tags Map<String,String>
    A mapping of tags assigned to the resource.
    name string
    The name of the SQL Database.
    resourceGroupName string
    Specifies the name of the Resource Group where the Azure SQL Database exists.
    serverName string
    The name of the SQL Server.
    tags {[key: string]: string}
    A mapping of tags assigned to the resource.
    name str
    The name of the SQL Database.
    resource_group_name str
    Specifies the name of the Resource Group where the Azure SQL Database exists.
    server_name str
    The name of the SQL Server.
    tags Mapping[str, str]
    A mapping of tags assigned to the resource.
    name String
    The name of the SQL Database.
    resourceGroupName String
    Specifies the name of the Resource Group where the Azure SQL Database exists.
    serverName String
    The name of the SQL Server.
    tags Map<String>
    A mapping of tags assigned to the resource.

    getDatabase Result

    The following output properties are available:

    Collation string
    The name of the collation.
    DefaultSecondaryLocation string
    The default secondary location of the SQL Database.
    Edition string
    The edition of the database.
    ElasticPoolName string
    The name of the elastic database pool the database belongs to.
    FailoverGroupId string
    The ID of the failover group the database belongs to.
    Id string
    The provider-assigned unique ID for this managed resource.
    Location string
    The location of the Resource Group in which the SQL Server exists.
    Name string
    The name of the database.
    ReadScale bool
    Indicate if read-only connections will be redirected to a high-available replica.
    ResourceGroupName string
    The name of the resource group in which the database resides. This will always be the same resource group as the Database Server.
    ServerName string
    The name of the SQL Server on which to create the database.
    Tags Dictionary<string, string>
    A mapping of tags assigned to the resource.
    Collation string
    The name of the collation.
    DefaultSecondaryLocation string
    The default secondary location of the SQL Database.
    Edition string
    The edition of the database.
    ElasticPoolName string
    The name of the elastic database pool the database belongs to.
    FailoverGroupId string
    The ID of the failover group the database belongs to.
    Id string
    The provider-assigned unique ID for this managed resource.
    Location string
    The location of the Resource Group in which the SQL Server exists.
    Name string
    The name of the database.
    ReadScale bool
    Indicate if read-only connections will be redirected to a high-available replica.
    ResourceGroupName string
    The name of the resource group in which the database resides. This will always be the same resource group as the Database Server.
    ServerName string
    The name of the SQL Server on which to create the database.
    Tags map[string]string
    A mapping of tags assigned to the resource.
    collation String
    The name of the collation.
    defaultSecondaryLocation String
    The default secondary location of the SQL Database.
    edition String
    The edition of the database.
    elasticPoolName String
    The name of the elastic database pool the database belongs to.
    failoverGroupId String
    The ID of the failover group the database belongs to.
    id String
    The provider-assigned unique ID for this managed resource.
    location String
    The location of the Resource Group in which the SQL Server exists.
    name String
    The name of the database.
    readScale Boolean
    Indicate if read-only connections will be redirected to a high-available replica.
    resourceGroupName String
    The name of the resource group in which the database resides. This will always be the same resource group as the Database Server.
    serverName String
    The name of the SQL Server on which to create the database.
    tags Map<String,String>
    A mapping of tags assigned to the resource.
    collation string
    The name of the collation.
    defaultSecondaryLocation string
    The default secondary location of the SQL Database.
    edition string
    The edition of the database.
    elasticPoolName string
    The name of the elastic database pool the database belongs to.
    failoverGroupId string
    The ID of the failover group the database belongs to.
    id string
    The provider-assigned unique ID for this managed resource.
    location string
    The location of the Resource Group in which the SQL Server exists.
    name string
    The name of the database.
    readScale boolean
    Indicate if read-only connections will be redirected to a high-available replica.
    resourceGroupName string
    The name of the resource group in which the database resides. This will always be the same resource group as the Database Server.
    serverName string
    The name of the SQL Server on which to create the database.
    tags {[key: string]: string}
    A mapping of tags assigned to the resource.
    collation str
    The name of the collation.
    default_secondary_location str
    The default secondary location of the SQL Database.
    edition str
    The edition of the database.
    elastic_pool_name str
    The name of the elastic database pool the database belongs to.
    failover_group_id str
    The ID of the failover group the database belongs to.
    id str
    The provider-assigned unique ID for this managed resource.
    location str
    The location of the Resource Group in which the SQL Server exists.
    name str
    The name of the database.
    read_scale bool
    Indicate if read-only connections will be redirected to a high-available replica.
    resource_group_name str
    The name of the resource group in which the database resides. This will always be the same resource group as the Database Server.
    server_name str
    The name of the SQL Server on which to create the database.
    tags Mapping[str, str]
    A mapping of tags assigned to the resource.
    collation String
    The name of the collation.
    defaultSecondaryLocation String
    The default secondary location of the SQL Database.
    edition String
    The edition of the database.
    elasticPoolName String
    The name of the elastic database pool the database belongs to.
    failoverGroupId String
    The ID of the failover group the database belongs to.
    id String
    The provider-assigned unique ID for this managed resource.
    location String
    The location of the Resource Group in which the SQL Server exists.
    name String
    The name of the database.
    readScale Boolean
    Indicate if read-only connections will be redirected to a high-available replica.
    resourceGroupName String
    The name of the resource group in which the database resides. This will always be the same resource group as the Database Server.
    serverName String
    The name of the SQL Server on which to create the database.
    tags Map<String>
    A mapping of tags assigned to the resource.

    Package Details

    Repository
    Azure Classic pulumi/pulumi-azure
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the azurerm Terraform Provider.
    azure logo

    We recommend using Azure Native.

    Azure Classic v5.72.0 published on Monday, Apr 15, 2024 by Pulumi