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_virtual_machine #5263

Merged
merged 42 commits into from
Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
af04ac2
add resource sqlvl
Dec 18, 2019
9ca6190
update resource & test
Dec 19, 2019
70e06ea
update
Dec 25, 2019
ac9afda
test case pass two
Dec 26, 2019
f0a4d33
Merge branch 'master' of https://github.com/terraform-providers/terra…
Dec 27, 2019
70167f7
code adjustment
Dec 27, 2019
604bc0e
add timeout
Dec 27, 2019
6064f67
first review
Jan 9, 2020
21ef1ce
ci fmt
Jan 9, 2020
2ebccfa
first review 2
Jan 9, 2020
42d1b95
merge master
Jan 9, 2020
c105f0e
with flatten function
Jan 10, 2020
c40729d
update
Jan 14, 2020
99f5203
Merge branch 'master' of https://github.com/terraform-providers/terra…
Jan 14, 2020
85fed51
vendor reset
Jan 14, 2020
b1c7f0e
remove sidebarcurrent
Jan 15, 2020
4880229
add require import
Jan 15, 2020
6b33b22
adjust website docs
Jan 15, 2020
85f49ba
three pass
Jan 20, 2020
14911de
update
Jan 21, 2020
bd0cd61
Merge branch 'master' of https://github.com/terraform-providers/terra…
Jan 21, 2020
5bc60d7
update CI
Jan 22, 2020
ee91134
remove provider in test
Jan 22, 2020
f79da42
remove spaces
Jan 22, 2020
8bf24c6
custom parse
Feb 10, 2020
15b3eb2
Merge branch 'master' of https://github.com/terraform-providers/terra…
Mar 3, 2020
ad37a97
pending test for nsg in nic
Mar 3, 2020
f718dcd
Merge branch 'master' of https://github.com/terraform-providers/terra…
Mar 5, 2020
a1a186f
update
Mar 5, 2020
56ea2b0
Merge branch 'master' of https://github.com/terraform-providers/terra…
Mar 5, 2020
c89b563
fmt
Mar 5, 2020
652d817
fmt
Mar 6, 2020
ba251f7
kt's 2nd review
Mar 24, 2020
915d147
merge upstream
Mar 24, 2020
b2dcbb7
update
Mar 26, 2020
8d00863
merge master
katbyte Mar 27, 2020
910fee4
cleanup client name
katbyte Mar 27, 2020
19b6020
sql image update
Mar 27, 2020
397c0c8
merge kt's commit's
Mar 27, 2020
afb84ec
clear sql vm group
Mar 27, 2020
461bd3d
remove test for group id
katbyte Mar 27, 2020
bb0ec21
make fmt
katbyte Mar 27, 2020
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
3 changes: 3 additions & 0 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
monitor "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor/client"
msi "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/msi/client"
mssql "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mssql/client"
mssqlvm "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mssqlvm/client"
mysql "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mysql/client"
netapp "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp/client"
network "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/client"
Expand Down Expand Up @@ -110,6 +111,7 @@ type Client struct {
Monitor *monitor.Client
MSI *msi.Client
MSSQL *mssql.Client
MSSQLVM *mssqlvm.Client
MySQL *mysql.Client
NetApp *netapp.Client
Network *network.Client
Expand Down Expand Up @@ -202,6 +204,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Subscription = subscription.NewClient(o)
client.TrafficManager = trafficManager.NewClient(o)
client.Web = web.NewClient(o)
client.MSSQLVM = mssqlvm.NewClient(o)
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved

return nil
}
1 change: 1 addition & 0 deletions azurerm/internal/provider/required_resource_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func RequiredResourceProviders() map[string]struct{} {
"Microsoft.Maps": {},
"Microsoft.MarketplaceOrdering": {},
"Microsoft.Media": {},
"Microsoft.MsSql": {},
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved
"Microsoft.Network": {},
"Microsoft.NotificationHubs": {},
"Microsoft.OperationalInsights": {},
Expand Down
2 changes: 2 additions & 0 deletions azurerm/internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/monitor"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/msi"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mssql"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mssqlvm"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mysql"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network"
Expand Down Expand Up @@ -103,6 +104,7 @@ func SupportedServices() []common.ServiceRegistration {
monitor.Registration{},
msi.Registration{},
mssql.Registration{},
mssqlvm.Registration{},
mysql.Registration{},
netapp.Registration{},
network.Registration{},
Expand Down
19 changes: 19 additions & 0 deletions azurerm/internal/services/mssqlvm/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package client
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved

import (
"github.com/Azure/azure-sdk-for-go/services/preview/sqlvirtualmachine/mgmt/2017-03-01-preview/sqlvirtualmachine"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
SQLVirtualMachinesClient *sqlvirtualmachine.SQLVirtualMachinesClient
}

func NewClient(o *common.ClientOptions) *Client {
SQLVirtualMachinesClient := sqlvirtualmachine.NewSQLVirtualMachinesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&SQLVirtualMachinesClient.Client, o.ResourceManagerAuthorizer)

return &Client{
SQLVirtualMachinesClient: &SQLVirtualMachinesClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package mssqlvm

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmMsSqlVirtualMachine() *schema.Resource {
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved
return &schema.Resource{
Read: dataSourceArmMsSqlVirtualMachineRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"location": {
Type: schema.TypeString,
Computed: true,
},

"resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(),

"name": {
Type: schema.TypeString,
Required: true,
},
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved

"virtual_machine_resource_id": {
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Computed: true,
},

"sql_server_license_type": {
Type: schema.TypeString,
Computed: true,
},

"sql_image_sku": {
Type: schema.TypeString,
Computed: true,
},

"tags": tags.Schema(),
},
}
}

func dataSourceArmMsSqlVirtualMachineRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).MSSQLVM.SQLVirtualMachinesClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

resourceGroupName := d.Get("resource_group_name").(string)
name := d.Get("name").(string)

resp, err := client.Get(ctx, resourceGroupName, name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Sql Virtual Machine (Sql Virtual Machine Name %q / Resource Group %q) was not found", name, resourceGroupName)
}
return fmt.Errorf("Error reading Sql Virtual Machine (Sql Virtual Machine Name %q / Resource Group %q): %+v", name, resourceGroupName, err)
}

d.SetId(*resp.ID)

d.Set("resource_group", resourceGroupName)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
if properties := resp.Properties; properties != nil {
d.Set("sql_image_sku", string(properties.SQLImageSku))
d.Set("sql_server_license_type", string(properties.SQLServerLicenseType))
d.Set("virtual_machine_resource_id", properties.VirtualMachineResourceID)
}
d.Set("name", name)
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved
d.Set("id", resp.ID)
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved

return tags.FlattenAndSet(d, resp.Tags)
}
26 changes: 26 additions & 0 deletions azurerm/internal/services/mssqlvm/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package mssqlvm
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

type Registration struct{}

// Name is the name of this Service
func (r Registration) Name() string {
return "Microsoft SQL VM / SQL Azure"
yupwei68 marked this conversation as resolved.
Show resolved Hide resolved
}

// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_mssql_virtual_machine": dataSourceArmMsSqlVirtualMachine(),
}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{
"azurerm_mssql_virtual_machine": resourceArmMsSqlVirtualMachine(),
}
}
Loading