diff --git a/internal/services/mssql/client/client.go b/internal/services/mssql/client/client.go index 3c56dd34da4c9..dde42790c2a37 100644 --- a/internal/services/mssql/client/client.go +++ b/internal/services/mssql/client/client.go @@ -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, diff --git a/internal/services/mssql/mssql_server_dns_alias_resource.go b/internal/services/mssql/mssql_server_dns_alias_resource.go new file mode 100644 index 0000000000000..bb06254ec8284 --- /dev/null +++ b/internal/services/mssql/mssql_server_dns_alias_resource.go @@ -0,0 +1,143 @@ +package mssql + +import ( + "context" + "fmt" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "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" + webValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/web/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]*schema.Schema { + return map[string]*schema.Schema{ + "mssql_server_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.ServerID, + }, + + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: webValidate.AppServiceEnvironmentName, + }, + } +} + +func (m ServerDNSAliasResource) Attributes() map[string]*schema.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 + subscriptionID := metadata.Client.Account.SubscriptionId + id := parse.NewServerDNSAliasID(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 + }, + DiffFunc: nil, + } +} + +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 +} diff --git a/internal/services/mssql/mssql_server_dns_alias_resource_test.go b/internal/services/mssql/mssql_server_dns_alias_resource_test.go new file mode 100644 index 0000000000000..4b9fca0cc52c3 --- /dev/null +++ b/internal/services/mssql/mssql_server_dns_alias_resource_test.go @@ -0,0 +1,107 @@ +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)) +} diff --git a/internal/services/mssql/parse/server_dns_alias.go b/internal/services/mssql/parse/server_dns_alias.go new file mode 100644 index 0000000000000..22ef3f22949df --- /dev/null +++ b/internal/services/mssql/parse/server_dns_alias.go @@ -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 +} diff --git a/internal/services/mssql/parse/server_dns_alias_test.go b/internal/services/mssql/parse/server_dns_alias_test.go new file mode 100644 index 0000000000000..8ef06b27a11e3 --- /dev/null +++ b/internal/services/mssql/parse/server_dns_alias_test.go @@ -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) + } + } +} diff --git a/internal/services/mssql/registration.go b/internal/services/mssql/registration.go index 754964a90a609..e383274fd1fb6 100644 --- a/internal/services/mssql/registration.go +++ b/internal/services/mssql/registration.go @@ -74,5 +74,6 @@ func (r Registration) Resources() []sdk.Resource { MsSqlManagedInstanceActiveDirectoryAdministratorResource{}, MsSqlManagedInstanceFailoverGroupResource{}, MsSqlManagedInstanceResource{}, + ServerDNSAliasResource{}, } } diff --git a/internal/services/mssql/resourceids.go b/internal/services/mssql/resourceids.go index 404478a733c06..6df9becfd4777 100644 --- a/internal/services/mssql/resourceids.go +++ b/internal/services/mssql/resourceids.go @@ -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 diff --git a/internal/services/mssql/validate/server_dns_alias_id.go b/internal/services/mssql/validate/server_dns_alias_id.go new file mode 100644 index 0000000000000..bce1c8224f8c5 --- /dev/null +++ b/internal/services/mssql/validate/server_dns_alias_id.go @@ -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 +} diff --git a/internal/services/mssql/validate/server_dns_alias_id_test.go b/internal/services/mssql/validate/server_dns_alias_id_test.go new file mode 100644 index 0000000000000..e8c3407ea7ed4 --- /dev/null +++ b/internal/services/mssql/validate/server_dns_alias_id_test.go @@ -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) + } + } +} diff --git a/website/docs/r/mssql_server_dns_alias.html.markdown b/website/docs/r/mssql_server_dns_alias.html.markdown new file mode 100644 index 0000000000000..ad62b70d50a75 --- /dev/null +++ b/website/docs/r/mssql_server_dns_alias.html.markdown @@ -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 +```