Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New resource - azurerm_mssql_server_dns_alias #16861

Merged
merged 4 commits into from
May 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add mssql dns alias resource support, fix #11276
wuxu committed May 20, 2022
commit ecf18cf2ac3a0015a92bd8f15b755d6d4bcf2e34
5 changes: 5 additions & 0 deletions internal/services/mssql/client/client.go
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ type Client struct {
ServerAzureADAdministratorsClient *sql.ServerAzureADAdministratorsClient
ServerAzureADOnlyAuthenticationsClient *sql.ServerAzureADOnlyAuthenticationsClient
ServerConnectionPoliciesClient *sql.ServerConnectionPoliciesClient
ServerDNSAliasClient *sql.ServerDNSAliasesClient
ServerExtendedBlobAuditingPoliciesClient *sql.ExtendedServerBlobAuditingPoliciesClient
ServerKeysClient *sql.ServerKeysClient
ServerSecurityAlertPoliciesClient *sql.ServerSecurityAlertPoliciesClient
@@ -118,6 +119,9 @@ func NewClient(o *common.ClientOptions) *Client {
serverConnectionPoliciesClient := sql.NewServerConnectionPoliciesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&serverConnectionPoliciesClient.Client, o.ResourceManagerAuthorizer)

serverDNSAliasClient := sql.NewServerDNSAliasesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&serverDNSAliasClient.Client, o.ResourceManagerAuthorizer)

serverExtendedBlobAuditingPoliciesClient := sql.NewExtendedServerBlobAuditingPoliciesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&serverExtendedBlobAuditingPoliciesClient.Client, o.ResourceManagerAuthorizer)

@@ -168,6 +172,7 @@ func NewClient(o *common.ClientOptions) *Client {
ServerAzureADAdministratorsClient: &serverAzureADAdministratorsClient,
ServerAzureADOnlyAuthenticationsClient: &serverAzureADOnlyAuthenticationsClient,
ServerConnectionPoliciesClient: &serverConnectionPoliciesClient,
ServerDNSAliasClient: &serverDNSAliasClient,
ServerExtendedBlobAuditingPoliciesClient: &serverExtendedBlobAuditingPoliciesClient,
ServerKeysClient: &serverKeysClient,
ServerSecurityAlertPoliciesClient: &serverSecurityAlertPoliciesClient,
139 changes: 139 additions & 0 deletions internal/services/mssql/mssql_server_dns_alias_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package mssql

import (
"context"
"fmt"
"time"

"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

type ServerDNSAliasModel struct {
MsSQLServerId string `tfschema:"mssql_server_id"`
Name string `tfschema:"name"`
DNSRecord string `tfschema:"dns_record"`
}

type ServerDNSAliasResource struct{}

var _ sdk.Resource = (*ServerDNSAliasResource)(nil)

func (m ServerDNSAliasResource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"mssql_server_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.ServerID,
},

"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.ValidateMsSqlDNSAliasName,
},
}
}

func (m ServerDNSAliasResource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"dns_record": {
Type: pluginsdk.TypeString,
Computed: true,
},
}
}

func (m ServerDNSAliasResource) ModelObject() interface{} {
return &ServerDNSAliasModel{}
}

func (m ServerDNSAliasResource) ResourceType() string {
return "azurerm_mssql_server_dns_alias"
}

func (m ServerDNSAliasResource) Create() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
var alias ServerDNSAliasModel
if err := metadata.Decode(&alias); err != nil {
return err
}
serverID, err := parse.ServerID(alias.MsSQLServerId)
if err != nil {
return err
}
client := metadata.Client.MSSQL.ServerDNSAliasClient
wuxu92 marked this conversation as resolved.
Show resolved Hide resolved
id := parse.NewServerDNSAliasID(serverID.SubscriptionId, serverID.ResourceGroup, serverID.Name, alias.Name)
existing, err := client.Get(ctx, id.ResourceGroup, id.ServerName, id.DnsAliaseName)
if !utils.ResponseWasNotFound(existing.Response) {
if err != nil {
return fmt.Errorf("retreiving %s: %v", id, err)
}
return metadata.ResourceRequiresImport(m.ResourceType(), id)
}
future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.ServerName, id.DnsAliaseName)
if err != nil {
return fmt.Errorf("creating %s: %v", id, err)
}
if err := future.WaitForCompletionRef(ctx, client.Client); err != nil {
return fmt.Errorf("waiting for creation of %s: %v", id, err)
}
metadata.SetID(id)
return nil
wuxu92 marked this conversation as resolved.
Show resolved Hide resolved
},
}
}

func (m ServerDNSAliasResource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 10 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
id, err := parse.ServerDNSAliasID(metadata.ResourceData.Id())
if err != nil {
return err
}
client := metadata.Client.MSSQL.ServerDNSAliasClient
alias, err := client.Get(ctx, id.ResourceGroup, id.ServerName, id.DnsAliaseName)
if err != nil {
return err
}
state := ServerDNSAliasModel{
Name: id.DnsAliaseName,
MsSQLServerId: parse.NewServerID(id.SubscriptionId, id.ResourceGroup, id.ServerName).ID(),
}
if prop := alias.ServerDNSAliasProperties; prop != nil {
state.DNSRecord = utils.NormalizeNilableString(prop.AzureDNSRecord)
}
return metadata.Encode(&state)
},
}
}

func (m ServerDNSAliasResource) Delete() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
id, err := parse.ServerDNSAliasID(metadata.ResourceData.Id())
if err != nil {
return err
}
metadata.Logger.Infof("deleting %s", id)
client := metadata.Client.MSSQL.ServerDNSAliasClient
if _, err = client.Delete(ctx, id.ResourceGroup, id.ServerName, id.DnsAliaseName); err != nil {
return fmt.Errorf("deleting %s: %v", id, err)
}
return nil
},
}
}

func (m ServerDNSAliasResource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return validate.ServerDNSAliasID
}
108 changes: 108 additions & 0 deletions internal/services/mssql/mssql_server_dns_alias_resource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package mssql_test

import (
"context"
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/parse"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

type ServerDNSAliasResource struct{}

func TestAccServerDNSAlias_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_server_dns_alias", "test")
r := ServerDNSAliasResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccServerDNSAlias_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_server_dns_alias", "test")
r := ServerDNSAliasResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.RequiresImportErrorStep(r.requiresImport),
})
}

func (r ServerDNSAliasResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.ServerDNSAliasID(state.ID)
if err != nil {
return nil, err
}

resp, err := client.MSSQL.ServerDNSAliasClient.Get(ctx, id.ResourceGroup, id.ServerName, id.DnsAliaseName)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return utils.Bool(false), nil
}
return nil, fmt.Errorf("retreiving %s: %v", id, err)
}
if utils.ResponseWasNotFound(resp.Response) {
return utils.Bool(false), nil
}
return utils.Bool(true), nil
}

// Configs

func (r ServerDNSAliasResource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-appServerDNSAlias-%[1]d"
location = "%[2]s"
}

resource "azurerm_mssql_server" "sql" {
administrator_login = "umtacc"
administrator_login_password = "random81jdpwd_$#fs"
location = azurerm_resource_group.test.location
name = "acctestrg-sql-sever-%[1]d"
resource_group_name = azurerm_resource_group.test.name
version = "12.0"
}

resource "azurerm_mssql_server_dns_alias" "test" {
mssql_server_id = azurerm_mssql_server.sql.id
name = "acctest-dns-alias-%[1]d"
}
`, data.RandomInteger, data.Locations.Primary)
}

func (r ServerDNSAliasResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`


%s

resource "azurerm_mssql_server_dns_alias" "import" {
name = azurerm_mssql_server_dns_alias.test.name
mssql_server_id = azurerm_mssql_server_dns_alias.test.mssql_server_id
}
`, r.basic(data))
}
75 changes: 75 additions & 0 deletions internal/services/mssql/parse/server_dns_alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"
"strings"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

type ServerDNSAliasId struct {
SubscriptionId string
ResourceGroup string
ServerName string
DnsAliaseName string
}

func NewServerDNSAliasID(subscriptionId, resourceGroup, serverName, dnsAliaseName string) ServerDNSAliasId {
return ServerDNSAliasId{
SubscriptionId: subscriptionId,
ResourceGroup: resourceGroup,
ServerName: serverName,
DnsAliaseName: dnsAliaseName,
}
}

func (id ServerDNSAliasId) String() string {
segments := []string{
fmt.Sprintf("Dns Aliase Name %q", id.DnsAliaseName),
fmt.Sprintf("Server Name %q", id.ServerName),
fmt.Sprintf("Resource Group %q", id.ResourceGroup),
}
segmentsStr := strings.Join(segments, " / ")
return fmt.Sprintf("%s: (%s)", "Server D N S Alias", segmentsStr)
}

func (id ServerDNSAliasId) ID() string {
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Sql/servers/%s/dnsAliases/%s"
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.ServerName, id.DnsAliaseName)
}

// ServerDNSAliasID parses a ServerDNSAlias ID into an ServerDNSAliasId struct
func ServerDNSAliasID(input string) (*ServerDNSAliasId, error) {
id, err := resourceids.ParseAzureResourceID(input)
if err != nil {
return nil, err
}

resourceId := ServerDNSAliasId{
SubscriptionId: id.SubscriptionID,
ResourceGroup: id.ResourceGroup,
}

if resourceId.SubscriptionId == "" {
return nil, fmt.Errorf("ID was missing the 'subscriptions' element")
}

if resourceId.ResourceGroup == "" {
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element")
}

if resourceId.ServerName, err = id.PopSegment("servers"); err != nil {
return nil, err
}
if resourceId.DnsAliaseName, err = id.PopSegment("dnsAliases"); err != nil {
return nil, err
}

if err := id.ValidateNoEmptySegments(input); err != nil {
return nil, err
}

return &resourceId, nil
}
128 changes: 128 additions & 0 deletions internal/services/mssql/parse/server_dns_alias_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package parse

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"testing"

"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids"
)

var _ resourceids.Id = ServerDNSAliasId{}

func TestServerDNSAliasIDFormatter(t *testing.T) {
actual := NewServerDNSAliasID("12345678-1234-9876-4563-123456789012", "group1", "server1", "default").ID()
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/dnsAliases/default"
if actual != expected {
t.Fatalf("Expected %q but got %q", expected, actual)
}
}

func TestServerDNSAliasID(t *testing.T) {
testData := []struct {
Input string
Error bool
Expected *ServerDNSAliasId
}{

{
// empty
Input: "",
Error: true,
},

{
// missing SubscriptionId
Input: "/",
Error: true,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Error: true,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Error: true,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Error: true,
},

{
// missing ServerName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/",
Error: true,
},

{
// missing value for ServerName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/",
Error: true,
},

{
// missing DnsAliaseName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/",
Error: true,
},

{
// missing value for DnsAliaseName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/dnsAliases/",
Error: true,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/dnsAliases/default",
Expected: &ServerDNSAliasId{
SubscriptionId: "12345678-1234-9876-4563-123456789012",
ResourceGroup: "group1",
ServerName: "server1",
DnsAliaseName: "default",
},
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/GROUP1/PROVIDERS/MICROSOFT.SQL/SERVERS/SERVER1/DNSALIASES/DEFAULT",
Error: true,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Testing %q", v.Input)

actual, err := ServerDNSAliasID(v.Input)
if err != nil {
if v.Error {
continue
}

t.Fatalf("Expect a value but got an error: %s", err)
}
if v.Error {
t.Fatal("Expect an error but didn't get one")
}

if actual.SubscriptionId != v.Expected.SubscriptionId {
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId)
}
if actual.ResourceGroup != v.Expected.ResourceGroup {
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup)
}
if actual.ServerName != v.Expected.ServerName {
t.Fatalf("Expected %q but got %q for ServerName", v.Expected.ServerName, actual.ServerName)
}
if actual.DnsAliaseName != v.Expected.DnsAliaseName {
t.Fatalf("Expected %q but got %q for DnsAliaseName", v.Expected.DnsAliaseName, actual.DnsAliaseName)
}
}
}
1 change: 1 addition & 0 deletions internal/services/mssql/registration.go
Original file line number Diff line number Diff line change
@@ -74,5 +74,6 @@ func (r Registration) Resources() []sdk.Resource {
MsSqlManagedInstanceActiveDirectoryAdministratorResource{},
MsSqlManagedInstanceFailoverGroupResource{},
MsSqlManagedInstanceResource{},
ServerDNSAliasResource{},
}
}
1 change: 1 addition & 0 deletions internal/services/mssql/resourceids.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ package mssql
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=OutboundFirewallRule -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/outboundFirewallRules/fqdn1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=RecoverableDatabase -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/recoverabledatabases/database1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Server -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ServerDNSAlias -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/dnsAliases/default
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ServerExtendedAuditingPolicy -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/extendedAuditingSettings/default
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ServerSecurityAlertPolicy -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/securityAlertPolicies/Default
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=ServerVulnerabilityAssessment -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/vulnerabilityAssessments/default
12 changes: 12 additions & 0 deletions internal/services/mssql/validate/mssql.go
Original file line number Diff line number Diff line change
@@ -51,3 +51,15 @@ func ValidateMsSqlJobAgentName(i interface{}, k string) (_ []string, errors []er

return nil, nil
}

// ValidateMsSqlDNSAliasName
// Server DNS Alias name cannot be empty or null. It can only be made
// up of lowercase letters 'a'-'z', the numbers 0-9 and the hyphen. The hyphen
// may not lead or trail in the name.
func ValidateMsSqlDNSAliasName(i interface{}, k string) ([]string, []error) {
if m, regexErrs := validate.RegExHelper(i, k, `^[0-9a-z][-0-9a-z]{0,127}[0-9a-z]$`); !m {
return nil, append(regexErrs, fmt.Errorf("`%q` Server DNS Alias name cannot be empty or null. It can only be made up of lowercase letters 'a'-'z', the numbers 0-9 and the hyphen. The hyphen may not lead or trail in the name.", k))
}

return nil, nil
}
23 changes: 23 additions & 0 deletions internal/services/mssql/validate/server_dns_alias_id.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package validate

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import (
"fmt"

"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/parse"
)

func ServerDNSAliasID(input interface{}, key string) (warnings []string, errors []error) {
v, ok := input.(string)
if !ok {
errors = append(errors, fmt.Errorf("expected %q to be a string", key))
return
}

if _, err := parse.ServerDNSAliasID(v); err != nil {
errors = append(errors, err)
}

return
}
88 changes: 88 additions & 0 deletions internal/services/mssql/validate/server_dns_alias_id_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package validate

// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten

import "testing"

func TestServerDNSAliasID(t *testing.T) {
cases := []struct {
Input string
Valid bool
}{

{
// empty
Input: "",
Valid: false,
},

{
// missing SubscriptionId
Input: "/",
Valid: false,
},

{
// missing value for SubscriptionId
Input: "/subscriptions/",
Valid: false,
},

{
// missing ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/",
Valid: false,
},

{
// missing value for ResourceGroup
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/",
Valid: false,
},

{
// missing ServerName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/",
Valid: false,
},

{
// missing value for ServerName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/",
Valid: false,
},

{
// missing DnsAliaseName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/",
Valid: false,
},

{
// missing value for DnsAliaseName
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/dnsAliases/",
Valid: false,
},

{
// valid
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/dnsAliases/default",
Valid: true,
},

{
// upper-cased
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/GROUP1/PROVIDERS/MICROSOFT.SQL/SERVERS/SERVER1/DNSALIASES/DEFAULT",
Valid: false,
},
}
for _, tc := range cases {
t.Logf("[DEBUG] Testing Value %s", tc.Input)
_, errors := ServerDNSAliasID(tc.Input, "test")
valid := len(errors) == 0

if tc.Valid != valid {
t.Fatalf("Expected %t but got %t", tc.Valid, valid)
}
}
}
70 changes: 70 additions & 0 deletions website/docs/r/mssql_server_dns_alias.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
subcategory: "Database"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_mssql_server_dns_alias"
description: |-
Manages a MS SQL Server DNS Alias.
---

# azurerm_mssql_server_dns_alias

Manages a MS SQL Server DNS Alias.

## Example Usage

```hcl
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}
resource "azurerm_mssql_server" "example" {
name = "example-sqlserver"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
version = "12.0"
administrator_login = "missadministrator"
administrator_login_password = "AdminPassword123!"
}
resource "azurerm_mssql_server_dns_alias" "example" {
name = "example-dns-alias"
mssql_server_id = azurerm_mssql_server.example.id
}
```

## Arguments Reference

The following arguments are supported:

* `mssql_server_id` - (Required) The ID of the mssql server. Changing this forces a new MSSQL Server DNS Alias to be created.

* `name` - (Required) The name which should be used for this MSSQL Server DNS Alias. Changing this forces a new MSSQL Server DNS Alias to be created.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the MSSQL Server DNS Alias.

* `dns_record` - The fully qualified DNS record for alias.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

* `create` - (Defaults to 5 minutes) Used when creating the MSSQL Server DNS Alias.
* `read` - (Defaults to 5 minutes) Used when retrieving the MSSQL Server DNS Alias.
* `delete` - (Defaults to 5 minutes) Used when deleting the MSSQL Server DNS Alias.

## Import

MSSQL Server DNS Aliass can be imported using the `resource id`, e.g.

```shell
terraform import azurerm_mssql_server_dns_alias.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Sql/servers/server1/dnsAliases/default
```