-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resources:
azurerm_dev_test_lab
/ `azurerm_dev_test_virtual_net…
…work` (#1944) * Vendoring v2016-05-15 of the DevTestLabs SDK * New Resource: `azurerm_dev_test_lab` * New Data Source: `azurerm_dev_test_lab` * New Resource: `azurerm_dev_test_virtual_network` * Validation for the DevTestLab name ``` $ acctests azurerm TestValidateDevTestLabName === RUN TestValidateDevTestLabName --- PASS: TestValidateDevTestLabName (0.00s) PASS ok github.com/terraform-providers/terraform-provider-azurerm/azurerm 0.343s ``` * DevTest Virtual Network: adding validation * Making the resource group name case insensitive * Documenting the bug * Adding validation to the data source * Moving the DevTest validation into the azure package
- Loading branch information
1 parent
f0dc327
commit 605042b
Showing
41 changed files
with
18,659 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
"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, | ||
ValidateFunc: azure.ValidateDevTestLabName(), | ||
}, | ||
|
||
"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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package azure | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/helper/validation" | ||
) | ||
|
||
func ValidateDevTestLabName() schema.SchemaValidateFunc { | ||
return validation.StringMatch( | ||
regexp.MustCompile("^[A-Za-z0-9_-]+$"), | ||
"Lab Name can only include alphanumeric characters, underscores, hyphens.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package azure | ||
|
||
import "testing" | ||
|
||
func TestValidateDevTestLabName(t *testing.T) { | ||
validNames := []string{ | ||
"valid-name", | ||
"valid02-name", | ||
"validName1", | ||
"-validname1", | ||
"valid_name", | ||
"double-hyphen--valid", | ||
} | ||
for _, v := range validNames { | ||
_, errors := ValidateDevTestLabName()(v, "example") | ||
if len(errors) != 0 { | ||
t.Fatalf("%q should be a valid Dev Test Lab Name: %q", v, errors) | ||
} | ||
} | ||
|
||
invalidNames := []string{ | ||
"invalid!", | ||
"!@£", | ||
} | ||
for _, v := range invalidNames { | ||
_, errors := ValidateDevTestLabName()(v, "name") | ||
if len(errors) == 0 { | ||
t.Fatalf("%q should be an invalid Dev Test Lab Name", v) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.