We recommend using Azure Native.
azure.mssql.getDatabase
Explore with Pulumi AI
Use this data source to access information about an existing SQL database.
Example Usage
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Azure = Pulumi.Azure;
return await Deployment.RunAsync(() =>
{
var exampleResourceGroup = new Azure.Core.ResourceGroup("exampleResourceGroup", new()
{
Location = "West Europe",
});
var exampleServer = new Azure.MSSql.Server("exampleServer", new()
{
ResourceGroupName = exampleResourceGroup.Name,
Location = exampleResourceGroup.Location,
Version = "12.0",
AdministratorLogin = "4dm1n157r470r",
AdministratorLoginPassword = "4-v3ry-53cr37-p455w0rd",
});
var exampleDatabase = Azure.MSSql.GetDatabase.Invoke(new()
{
Name = "example-mssql-db",
ServerId = exampleServer.Id,
});
return new Dictionary<string, object?>
{
["databaseId"] = exampleDatabase.Apply(getDatabaseResult => getDatabaseResult.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, "exampleResourceGroup", &core.ResourceGroupArgs{
Location: pulumi.String("West Europe"),
})
if err != nil {
return err
}
exampleServer, err := mssql.NewServer(ctx, "exampleServer", &mssql.ServerArgs{
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
}
exampleDatabase := mssql.LookupDatabaseOutput(ctx, mssql.GetDatabaseOutputArgs{
Name: pulumi.String("example-mssql-db"),
ServerId: exampleServer.ID(),
}, nil)
ctx.Export("databaseId", exampleDatabase.ApplyT(func(exampleDatabase mssql.GetDatabaseResult) (*string, error) {
return &exampleDatabase.Id, nil
}).(pulumi.StringPtrOutput))
return nil
})
}
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()
.location("West Europe")
.build());
var exampleServer = new Server("exampleServer", ServerArgs.builder()
.resourceGroupName(exampleResourceGroup.name())
.location(exampleResourceGroup.location())
.version("12.0")
.administratorLogin("4dm1n157r470r")
.administratorLoginPassword("4-v3ry-53cr37-p455w0rd")
.build());
final var exampleDatabase = MssqlFunctions.getDatabase(GetDatabaseArgs.builder()
.name("example-mssql-db")
.serverId(exampleServer.id())
.build());
ctx.export("databaseId", exampleDatabase.applyValue(getDatabaseResult -> getDatabaseResult).applyValue(exampleDatabase -> exampleDatabase.applyValue(getDatabaseResult -> getDatabaseResult.id())));
}
}
import pulumi
import pulumi_azure as azure
example_resource_group = azure.core.ResourceGroup("exampleResourceGroup", location="West Europe")
example_server = azure.mssql.Server("exampleServer",
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_database = azure.mssql.get_database_output(name="example-mssql-db",
server_id=example_server.id)
pulumi.export("databaseId", example_database.id)
import * as pulumi from "@pulumi/pulumi";
import * as azure from "@pulumi/azure";
const exampleResourceGroup = new azure.core.ResourceGroup("exampleResourceGroup", {location: "West Europe"});
const exampleServer = new azure.mssql.Server("exampleServer", {
resourceGroupName: exampleResourceGroup.name,
location: exampleResourceGroup.location,
version: "12.0",
administratorLogin: "4dm1n157r470r",
administratorLoginPassword: "4-v3ry-53cr37-p455w0rd",
});
const exampleDatabase = azure.mssql.getDatabaseOutput({
name: "example-mssql-db",
serverId: exampleServer.id,
});
export const databaseId = exampleDatabase.apply(exampleDatabase => exampleDatabase.id);
resources:
exampleResourceGroup:
type: azure:core:ResourceGroup
properties:
location: West Europe
exampleServer:
type: azure:mssql:Server
properties:
resourceGroupName: ${exampleResourceGroup.name}
location: ${exampleResourceGroup.location}
version: '12.0'
administratorLogin: 4dm1n157r470r
administratorLoginPassword: 4-v3ry-53cr37-p455w0rd
variables:
exampleDatabase:
fn::invoke:
Function: azure:mssql:getDatabase
Arguments:
name: example-mssql-db
serverId: ${exampleServer.id}
outputs:
databaseId: ${exampleDatabase.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:
getDatabase Result
The following output properties are available:
- Collation string
The collation of the database.
- Elastic
Pool stringId The id of the elastic pool containing this database.
- Id string
The provider-assigned unique ID for this managed resource.
- License
Type string The license type to apply for this database.
- Max
Size intGb The max size of the database in gigabytes.
- Name string
- Read
Replica intCount 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 string - Sku
Name string The name of the SKU of the database.
- Storage
Account stringType The storage account type used to store backups for this database.
- Dictionary<string, string>
A mapping of tags to assign to the resource.
- 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.
- Elastic
Pool stringId The id of the elastic pool containing this database.
- Id string
The provider-assigned unique ID for this managed resource.
- License
Type string The license type to apply for this database.
- Max
Size intGb The max size of the database in gigabytes.
- Name string
- Read
Replica intCount 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 string - Sku
Name string The name of the SKU of the database.
- Storage
Account stringType The storage account type used to store backups for this database.
- map[string]string
A mapping of tags to assign to the resource.
- 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.
- elastic
Pool StringId The id of the elastic pool containing this database.
- id String
The provider-assigned unique ID for this managed resource.
- license
Type String The license type to apply for this database.
- max
Size IntegerGb The max size of the database in gigabytes.
- name String
- read
Replica IntegerCount The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed.
- read
Scale Boolean If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica.
- server
Id String - sku
Name String The name of the SKU of the database.
- storage
Account StringType The storage account type used to store backups for this database.
- Map<String,String>
A mapping of tags to assign to the resource.
- zone
Redundant 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.
- elastic
Pool stringId The id of the elastic pool containing this database.
- id string
The provider-assigned unique ID for this managed resource.
- license
Type string The license type to apply for this database.
- max
Size numberGb The max size of the database in gigabytes.
- name string
- read
Replica numberCount The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed.
- read
Scale boolean If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica.
- server
Id string - sku
Name string The name of the SKU of the database.
- storage
Account stringType The storage account type used to store backups for this database.
- {[key: string]: string}
A mapping of tags to assign to the resource.
- zone
Redundant 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_ strid The id of the elastic pool containing this database.
- id str
The provider-assigned unique ID for this managed resource.
- license_
type str The license type to apply for this database.
- max_
size_ intgb The max size of the database in gigabytes.
- name str
- read_
replica_ intcount 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_ strtype The storage account type used to store backups for this database.
- Mapping[str, str]
A mapping of tags to assign to the resource.
- 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.
- elastic
Pool StringId The id of the elastic pool containing this database.
- id String
The provider-assigned unique ID for this managed resource.
- license
Type String The license type to apply for this database.
- max
Size NumberGb The max size of the database in gigabytes.
- name String
- read
Replica NumberCount The number of readonly secondary replicas associated with the database to which readonly application intent connections may be routed.
- read
Scale Boolean If enabled, connections that have application intent set to readonly in their connection string may be routed to a readonly secondary replica.
- server
Id String - sku
Name String The name of the SKU of the database.
- storage
Account StringType The storage account type used to store backups for this database.
- Map<String>
A mapping of tags to assign to the resource.
- zone
Redundant Boolean Whether or not this database is zone redundant, which means the replicas of this database will be spread across multiple availability zones.
Package Details
- Repository
- Azure Classic pulumi/pulumi-azure
- License
- Apache-2.0
- Notes
This Pulumi package is based on the
azurerm
Terraform Provider.