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 Resources: azurerm_dev_test_lab / azurerm_dev_test_virtual_network #1944

Merged
merged 10 commits into from
Sep 20, 2018
16 changes: 16 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
analyticsAccount "github.com/Azure/azure-sdk-for-go/services/datalake/analytics/mgmt/2016-11-01/account"
"github.com/Azure/azure-sdk-for-go/services/datalake/store/2016-11-01/filesystem"
storeAccount "github.com/Azure/azure-sdk-for-go/services/datalake/store/mgmt/2016-11-01/account"
"github.com/Azure/azure-sdk-for-go/services/devtestlabs/mgmt/2016-05-15/dtl"
"github.com/Azure/azure-sdk-for-go/services/eventgrid/mgmt/2018-01-01/eventgrid"
"github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub"
"github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac"
Expand Down Expand Up @@ -136,6 +137,10 @@ type ArmClient struct {
// Devices
iothubResourceClient devices.IotHubResourceClient

// DevTestLabs
devTestLabsClient dtl.LabsClient
devTestVirtualNetworksClient dtl.VirtualNetworksClient

// Databases
mysqlConfigurationsClient mysql.ConfigurationsClient
mysqlDatabasesClient mysql.DatabasesClient
Expand Down Expand Up @@ -428,6 +433,7 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) {
client.registerDatabases(endpoint, c.SubscriptionID, auth, sender)
client.registerDataLakeStoreClients(endpoint, c.SubscriptionID, auth, sender)
client.registerDeviceClients(endpoint, c.SubscriptionID, auth, sender)
client.registerDevTestClients(endpoint, c.SubscriptionID, auth)
client.registerDNSClients(endpoint, c.SubscriptionID, auth, sender)
client.registerEventGridClients(endpoint, c.SubscriptionID, auth, sender)
client.registerEventHubClients(endpoint, c.SubscriptionID, auth, sender)
Expand Down Expand Up @@ -690,6 +696,16 @@ func (c *ArmClient) registerDeviceClients(endpoint, subscriptionId string, auth
c.iothubResourceClient = iotClient
}

func (c *ArmClient) registerDevTestClients(endpoint, subscriptionId string, auth autorest.Authorizer) {
labsClient := dtl.NewLabsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&labsClient.Client, auth)
c.devTestLabsClient = labsClient

devTestVirtualNetworksClient := dtl.NewVirtualNetworksClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&devTestVirtualNetworksClient.Client, auth)
c.devTestVirtualNetworksClient = devTestVirtualNetworksClient
}

func (c *ArmClient) registerDNSClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
dn := dns.NewRecordSetsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&dn.Client, auth)
Expand Down
103 changes: 103 additions & 0 deletions azurerm/data_source_dev_test_lab.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package azurerm

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmDevTestLab() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmDevTestLabRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved

"location": locationForDataSourceSchema(),

"resource_group_name": resourceGroupNameForDataSourceSchema(),

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

"tags": tagsForDataSourceSchema(),

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

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

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

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

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

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

func dataSourceArmDevTestLabRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).devTestLabsClient
ctx := meta.(*ArmClient).StopContext

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

read, err := client.Get(ctx, resourceGroup, name, "")
if err != nil {
if utils.ResponseWasNotFound(read.Response) {
return fmt.Errorf("DevTest Lab %q was not found in Resource Group %q", name, resourceGroup)
}

return fmt.Errorf("Error making Read request on DevTest Lab %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*read.ID)

d.Set("name", read.Name)
d.Set("resource_group_name", resourceGroup)
if location := read.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}

if props := read.LabProperties; props != nil {
d.Set("storage_type", string(props.LabStorageType))

// Computed fields
d.Set("artifacts_storage_account_id", props.ArtifactsStorageAccount)
d.Set("default_storage_account_id", props.DefaultStorageAccount)
d.Set("default_premium_storage_account_id", props.DefaultPremiumStorageAccount)
d.Set("key_vault_id", props.VaultName)
d.Set("premium_data_disk_storage_account_id", props.PremiumDataDiskStorageAccount)
d.Set("unique_identifier", props.UniqueIdentifier)
}

flattenAndSetTags(d, read.Tags)

return nil
}
95 changes: 95 additions & 0 deletions azurerm/data_source_dev_test_lab_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceAzureRMDevTestLab_basic(t *testing.T) {
dataSourceName := "data.azurerm_dev_test_lab.test"
rInt := acctest.RandInt()
location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceDevTestLab_basic(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "storage_type", "Premium"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"),
),
},
},
})
}

func TestAccDataSourceAzureRMDevTestLab_complete(t *testing.T) {
dataSourceName := "data.azurerm_dev_test_lab.test"
rInt := acctest.RandInt()
location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceDevTestLab_complete(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "storage_type", "Standard"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName, "tags.Hello", "World"),
),
},
},
})
}

func testAccDataSourceDevTestLab_basic(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_dev_test_lab" "test" {
name = "acctestdtl%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}

data "azurerm_dev_test_lab" "test" {
name = "${azurerm_dev_test_lab.test.name}"
resource_group_name = "${azurerm_dev_test_lab.test.resource_group_name}"
}
`, rInt, location, rInt)
}

func testAccDataSourceDevTestLab_complete(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_dev_test_lab" "test" {
name = "acctestdtl%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_type = "Standard"

tags {
"Hello" = "World"
}
}

data "azurerm_dev_test_lab" "test" {
name = "${azurerm_dev_test_lab.test.name}"
resource_group_name = "${azurerm_dev_test_lab.test.resource_group_name}"
}
`, rInt, location, rInt)
}
8 changes: 6 additions & 2 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_cosmosdb_account": dataSourceArmCosmosDBAccount(),
"azurerm_container_registry": dataSourceArmContainerRegistry(),
"azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(),
"azurerm_dev_test_lab": dataSourceArmDevTestLab(),
"azurerm_dns_zone": dataSourceArmDnsZone(),
"azurerm_eventhub_namespace": dataSourceEventHubNamespace(),
"azurerm_image": dataSourceArmImage(),
Expand Down Expand Up @@ -141,8 +142,6 @@ func Provider() terraform.ResourceProvider {
"azurerm_automation_schedule": resourceArmAutomationSchedule(),
"azurerm_autoscale_setting": resourceArmAutoScaleSetting(),
"azurerm_availability_set": resourceArmAvailabilitySet(),
"azurerm_firewall": resourceArmFirewall(),
"azurerm_firewall_network_rule_collection": resourceArmFirewallNetworkRuleCollection(),
"azurerm_cdn_endpoint": resourceArmCdnEndpoint(),
"azurerm_cdn_profile": resourceArmCdnProfile(),
"azurerm_container_registry": resourceArmContainerRegistry(),
Expand All @@ -154,6 +153,8 @@ func Provider() terraform.ResourceProvider {
"azurerm_data_lake_store": resourceArmDataLakeStore(),
"azurerm_data_lake_store_file": resourceArmDataLakeStoreFile(),
"azurerm_data_lake_store_firewall_rule": resourceArmDataLakeStoreFirewallRule(),
"azurerm_dev_test_lab": resourceArmDevTestLab(),
"azurerm_dev_test_virtual_network": resourceArmDevTestVirtualNetwork(),
"azurerm_dns_a_record": resourceArmDnsARecord(),
"azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(),
"azurerm_dns_caa_record": resourceArmDnsCaaRecord(),
Expand All @@ -173,6 +174,8 @@ func Provider() terraform.ResourceProvider {
"azurerm_express_route_circuit": resourceArmExpressRouteCircuit(),
"azurerm_express_route_circuit_authorization": resourceArmExpressRouteCircuitAuthorization(),
"azurerm_express_route_circuit_peering": resourceArmExpressRouteCircuitPeering(),
"azurerm_firewall": resourceArmFirewall(),
"azurerm_firewall_network_rule_collection": resourceArmFirewallNetworkRuleCollection(),
"azurerm_function_app": resourceArmFunctionApp(),
"azurerm_image": resourceArmImage(),
"azurerm_iothub": resourceArmIotHub(),
Expand Down Expand Up @@ -381,6 +384,7 @@ func determineAzureResourceProvidersToRegister(providerList []resources.Provider
"Microsoft.DBforMySQL": {},
"Microsoft.DBforPostgreSQL": {},
"Microsoft.Devices": {},
"Microsoft.DevTestLab": {},
"Microsoft.DocumentDB": {},
"Microsoft.EventGrid": {},
"Microsoft.EventHub": {},
Expand Down
Loading