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

We recommend using Azure Native.

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

azure.mssql.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 database.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as azure from "@pulumi/azure";
    
    const exampleResourceGroup = new azure.core.ResourceGroup("example", {
        name: "example-resources",
        location: "West Europe",
    });
    const exampleServer = new azure.mssql.Server("example", {
        name: "example",
        resourceGroupName: exampleResourceGroup.name,
        location: exampleResourceGroup.location,
        version: "12.0",
        administratorLogin: "4dm1n157r470r",
        administratorLoginPassword: "4-v3ry-53cr37-p455w0rd",
    });
    const example = azure.mssql.getDatabaseOutput({
        name: "example-mssql-db",
        serverId: exampleServer.id,
    });
    export const databaseId = example.apply(example => example.id);
    
    import pulumi
    import pulumi_azure as azure
    
    example_resource_group = azure.core.ResourceGroup("example",
        name="example-resources",
        location="West Europe")
    example_server = azure.mssql.Server("example",
        name="example",
        resource_group_name=example_resource_group.name,
        location=example_resource_group.location,
        version="12.0",
        administrator_login="4dm1n157r470r",
        administrator_login_password="4-v3ry-53cr37-p455w0rd")
    example = azure.mssql.get_database_output(name="example-mssql-db",
        server_id=example_server.id)
    pulumi.export("databaseId", example.id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/core"
    	"github.com/pulumi/pulumi-azure/sdk/v5/go/azure/mssql"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		exampleResourceGroup, err := core.NewResourceGroup(ctx, "example", &core.ResourceGroupArgs{
    			Name:     pulumi.String("example-resources"),
    			Location: pulumi.String("West Europe"),
    		})
    		if err != nil {
    			return err
    		}
    		exampleServer, err := mssql.NewServer(ctx, "example", &mssql.ServerArgs{
    			Name:                       pulumi.String("example"),
    			ResourceGroupName:          exampleResourceGroup.Name,
    			Location:                   exampleResourceGroup.Location,
    			Version:                    pulumi.String("12.0"),
    			AdministratorLogin:         pulumi.String("4dm1n157r470r"),
    			AdministratorLoginPassword: pulumi.String("4-v3ry-53cr37-p455w0rd"),
    		})
    		if err != nil {
    			return err
    		}
    		example := mssql.LookupDatabaseOutput(ctx, mssql.GetDatabaseOutputArgs{
    			Name:     pulumi.String("example-mssql-db"),
    			ServerId: exampleServer.ID(),
    		}, nil)
    		ctx.Export("databaseId", example.ApplyT(func(example mssql.GetDatabaseResult) (*string, error) {
    			return &example.Id, nil
    		}).(pulumi.StringPtrOutput))
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Azure = Pulumi.Azure;
    
    return await Deployment.RunAsync(() => 
    {
        var exampleResourceGroup = new Azure.Core.ResourceGroup("example", new()
        {
            Name = "example-resources",
            Location = "West Europe",
        });
    
        var exampleServer = new Azure.MSSql.Server("example", new()
        {
            Name = "example",
            ResourceGroupName = exampleResourceGroup.Name,
            Location = exampleResourceGroup.Location,
            Version = "12.0",
            AdministratorLogin = "4dm1n157r470r",
            AdministratorLoginPassword = "4-v3ry-53cr37-p455w0rd",
        });
    
        var example = Azure.MSSql.GetDatabase.Invoke(new()
        {
            Name = "example-mssql-db",
            ServerId = exampleServer.Id,
        });
    
        return new Dictionary<string, object?>
        {
            ["databaseId"] = 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.core.ResourceGroup;
    import com.pulumi.azure.core.ResourceGroupArgs;
    import com.pulumi.azure.mssql.Server;
    import com.pulumi.azure.mssql.ServerArgs;
    import com.pulumi.azure.mssql.MssqlFunctions;
    import com.pulumi.azure.mssql.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) {
            var exampleResourceGroup = new ResourceGroup("exampleResourceGroup", ResourceGroupArgs.builder()        
                .name("example-resources")
                .location("West Europe")
                .build());
    
            var exampleServer = new Server("exampleServer", ServerArgs.builder()        
                .name("example")
                .resourceGroupName(exampleResourceGroup.name())
                .location(exampleResourceGroup.location())
                .version("12.0")
                .administratorLogin("4dm1n157r470r")
                .administratorLoginPassword("4-v3ry-53cr37-p455w0rd")
                .build());
    
            final var example = MssqlFunctions.getDatabase(GetDatabaseArgs.builder()
                .name("example-mssql-db")
                .serverId(exampleServer.id())
                .build());
    
            ctx.export("databaseId", example.applyValue(getDatabaseResult -> getDatabaseResult).applyValue(example -> example.applyValue(getDatabaseResult -> getDatabaseResult.id())));
        }
    }
    
    resources:
      exampleResourceGroup:
        type: azure:core:ResourceGroup
        name: example
        properties:
          name: example-resources
          location: West Europe
      exampleServer:
        type: azure:mssql:Server
        name: example
        properties:
          name: example
          resourceGroupName: ${exampleResourceGroup.name}
          location: ${exampleResourceGroup.location}
          version: '12.0'
          administratorLogin: 4dm1n157r470r
          administratorLoginPassword: 4-v3ry-53cr37-p455w0rd
    variables:
      example:
        fn::invoke:
          Function: azure:mssql:getDatabase
          Arguments:
            name: example-mssql-db
            serverId: ${exampleServer.id}
    outputs:
      databaseId: ${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,
                     server_id: Optional[str] = None,
                     opts: Optional[InvokeOptions] = None) -> GetDatabaseResult
    def get_database_output(name: Optional[pulumi.Input[str]] = None,
                     server_id: Optional[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:mssql/getDatabase:getDatabase
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Name string
    The name of the MS SQL Database.
    ServerId string
    The id of the MS SQL Server on which to read the database.
    Name string
    The name of the MS SQL Database.
    ServerId string
    The id of the MS SQL Server on which to read the database.
    name String
    The name of the MS SQL Database.
    serverId String
    The id of the MS SQL Server on which to read the database.
    name string
    The name of the MS SQL Database.
    serverId string
    The id of the MS SQL Server on which to read the database.
    name str
    The name of the MS SQL Database.
    server_id str
    The id of the MS SQL Server on which to read the database.
    name String
    The name of the MS SQL Database.
    serverId String
    The id of the MS SQL Server on which to read the database.

    getDatabase Result

    The following output properties are available:

    Collation string
    The collation of the database.
    ElasticPoolId string
    The id of the elastic pool containing this database.
    EnclaveType string
    The type of enclave being used by the database.
    Id string
    The provider-assigned unique ID for this managed resource.
    Identities List<GetDatabaseIdentity>
    A identity block as defined below.
    LicenseType string
    The license type to apply for this database.
    MaxSizeGb int
    The max size of the database in gigabytes.
    Name string
    ReadReplicaCount int
    The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed.
    ReadScale bool
    If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica.
    ServerId string
    SkuName string
    The name of the SKU of the database.
    StorageAccountType string
    The storage account type used to store backups for this database.
    Tags Dictionary<string, string>
    A mapping of tags to assign to the resource.
    TransparentDataEncryptionEnabled bool
    Whether or not Transparent Data Encryption is enabled.
    TransparentDataEncryptionKeyAutomaticRotationEnabled bool
    Whether or not TDE automatically rotates the encryption Key to latest version.
    TransparentDataEncryptionKeyVaultKeyId string
    The Key Vault key URI to be used as the Customer Managed Key(CMK/BYOK) for the Transparent Data Encryption(TDE) layer.
    ZoneRedundant bool
    Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones.
    Collation string
    The collation of the database.
    ElasticPoolId string
    The id of the elastic pool containing this database.
    EnclaveType string
    The type of enclave being used by the database.
    Id string
    The provider-assigned unique ID for this managed resource.
    Identities []GetDatabaseIdentity
    A identity block as defined below.
    LicenseType string
    The license type to apply for this database.
    MaxSizeGb int
    The max size of the database in gigabytes.
    Name string
    ReadReplicaCount int
    The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed.
    ReadScale bool
    If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica.
    ServerId string
    SkuName string
    The name of the SKU of the database.
    StorageAccountType string
    The storage account type used to store backups for this database.
    Tags map[string]string
    A mapping of tags to assign to the resource.
    TransparentDataEncryptionEnabled bool
    Whether or not Transparent Data Encryption is enabled.
    TransparentDataEncryptionKeyAutomaticRotationEnabled bool
    Whether or not TDE automatically rotates the encryption Key to latest version.
    TransparentDataEncryptionKeyVaultKeyId string
    The Key Vault key URI to be used as the Customer Managed Key(CMK/BYOK) for the Transparent Data Encryption(TDE) layer.
    ZoneRedundant bool
    Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones.
    collation String
    The collation of the database.
    elasticPoolId String
    The id of the elastic pool containing this database.
    enclaveType String
    The type of enclave being used by the database.
    id String
    The provider-assigned unique ID for this managed resource.
    identities List<GetDatabaseIdentity>
    A identity block as defined below.
    licenseType String
    The license type to apply for this database.
    maxSizeGb Integer
    The max size of the database in gigabytes.
    name String
    readReplicaCount Integer
    The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed.
    readScale Boolean
    If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica.
    serverId String
    skuName String
    The name of the SKU of the database.
    storageAccountType String
    The storage account type used to store backups for this database.
    tags Map<String,String>
    A mapping of tags to assign to the resource.
    transparentDataEncryptionEnabled Boolean
    Whether or not Transparent Data Encryption is enabled.
    transparentDataEncryptionKeyAutomaticRotationEnabled Boolean
    Whether or not TDE automatically rotates the encryption Key to latest version.
    transparentDataEncryptionKeyVaultKeyId String
    The Key Vault key URI to be used as the Customer Managed Key(CMK/BYOK) for the Transparent Data Encryption(TDE) layer.
    zoneRedundant Boolean
    Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones.
    collation string
    The collation of the database.
    elasticPoolId string
    The id of the elastic pool containing this database.
    enclaveType string
    The type of enclave being used by the database.
    id string
    The provider-assigned unique ID for this managed resource.
    identities GetDatabaseIdentity[]
    A identity block as defined below.
    licenseType string
    The license type to apply for this database.
    maxSizeGb number
    The max size of the database in gigabytes.
    name string
    readReplicaCount number
    The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed.
    readScale boolean
    If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica.
    serverId string
    skuName string
    The name of the SKU of the database.
    storageAccountType string
    The storage account type used to store backups for this database.
    tags {[key: string]: string}
    A mapping of tags to assign to the resource.
    transparentDataEncryptionEnabled boolean
    Whether or not Transparent Data Encryption is enabled.
    transparentDataEncryptionKeyAutomaticRotationEnabled boolean
    Whether or not TDE automatically rotates the encryption Key to latest version.
    transparentDataEncryptionKeyVaultKeyId string
    The Key Vault key URI to be used as the Customer Managed Key(CMK/BYOK) for the Transparent Data Encryption(TDE) layer.
    zoneRedundant boolean
    Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones.
    collation str
    The collation of the database.
    elastic_pool_id str
    The id of the elastic pool containing this database.
    enclave_type str
    The type of enclave being used by the database.
    id str
    The provider-assigned unique ID for this managed resource.
    identities Sequence[GetDatabaseIdentity]
    A identity block as defined below.
    license_type str
    The license type to apply for this database.
    max_size_gb int
    The max size of the database in gigabytes.
    name str
    read_replica_count int
    The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed.
    read_scale bool
    If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica.
    server_id str
    sku_name str
    The name of the SKU of the database.
    storage_account_type str
    The storage account type used to store backups for this database.
    tags Mapping[str, str]
    A mapping of tags to assign to the resource.
    transparent_data_encryption_enabled bool
    Whether or not Transparent Data Encryption is enabled.
    transparent_data_encryption_key_automatic_rotation_enabled bool
    Whether or not TDE automatically rotates the encryption Key to latest version.
    transparent_data_encryption_key_vault_key_id str
    The Key Vault key URI to be used as the Customer Managed Key(CMK/BYOK) for the Transparent Data Encryption(TDE) layer.
    zone_redundant bool
    Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones.
    collation String
    The collation of the database.
    elasticPoolId String
    The id of the elastic pool containing this database.
    enclaveType String
    The type of enclave being used by the database.
    id String
    The provider-assigned unique ID for this managed resource.
    identities List<Property Map>
    A identity block as defined below.
    licenseType String
    The license type to apply for this database.
    maxSizeGb Number
    The max size of the database in gigabytes.
    name String
    readReplicaCount Number
    The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed.
    readScale Boolean
    If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica.
    serverId String
    skuName String
    The name of the SKU of the database.
    storageAccountType String
    The storage account type used to store backups for this database.
    tags Map<String>
    A mapping of tags to assign to the resource.
    transparentDataEncryptionEnabled Boolean
    Whether or not Transparent Data Encryption is enabled.
    transparentDataEncryptionKeyAutomaticRotationEnabled Boolean
    Whether or not TDE automatically rotates the encryption Key to latest version.
    transparentDataEncryptionKeyVaultKeyId String
    The Key Vault key URI to be used as the Customer Managed Key(CMK/BYOK) for the Transparent Data Encryption(TDE) layer.
    zoneRedundant Boolean
    Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones.

    Supporting Types

    GetDatabaseIdentity

    IdentityIds List<string>
    The list of User Assigned Managed Identity IDs assigned to this Microsoft SQL Database.
    Type string
    The type of Managed Service Identity that is configured on this Microsoft SQL Database.
    IdentityIds []string
    The list of User Assigned Managed Identity IDs assigned to this Microsoft SQL Database.
    Type string
    The type of Managed Service Identity that is configured on this Microsoft SQL Database.
    identityIds List<String>
    The list of User Assigned Managed Identity IDs assigned to this Microsoft SQL Database.
    type String
    The type of Managed Service Identity that is configured on this Microsoft SQL Database.
    identityIds string[]
    The list of User Assigned Managed Identity IDs assigned to this Microsoft SQL Database.
    type string
    The type of Managed Service Identity that is configured on this Microsoft SQL Database.
    identity_ids Sequence[str]
    The list of User Assigned Managed Identity IDs assigned to this Microsoft SQL Database.
    type str
    The type of Managed Service Identity that is configured on this Microsoft SQL Database.
    identityIds List<String>
    The list of User Assigned Managed Identity IDs assigned to this Microsoft SQL Database.
    type String
    The type of Managed Service Identity that is configured on this Microsoft SQL Database.

    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