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

Add Proximity Placement Group Resources + Support #4020

Merged
merged 21 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 18 commits
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
47 changes: 47 additions & 0 deletions azurerm/data_source_proximity_placement_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package azurerm

import (
"fmt"

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

func dataSourceArmProximityPlacementGroup() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmProximityPlacementGroupRead,
Schema: map[string]*schema.Schema{
"name": {
tobydoescode marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.NoZeroValues,
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),
},
}
}

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

name := d.Get("name").(string)
tobydoescode marked this conversation as resolved.
Show resolved Hide resolved
resGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Proximity Placement Group %q (Resource Group %q) was not found", name, resGroup)
}

return fmt.Errorf("Error making Read request on Proximity Placement Group %q (Resource Group %q): %+v", name, resGroup, err)
}

d.SetId(*resp.ID)
flattenAndSetTags(d, resp.Tags)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add tags.SchemaForDataSource to the resource so this has an effect?

Test ended in panic.

------- Stdout: -------
=== RUN   TestAccDataSourceProximityPlacementGroup_basic
=== PAUSE TestAccDataSourceProximityPlacementGroup_basic
=== CONT  TestAccDataSourceProximityPlacementGroup_basic

------- Stderr: -------
panic: Invalid address to set: []string{"tags"}


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

import (
"fmt"
"testing"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"

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

func TestAccDataSourceProximityPlacementGroup_basic(t *testing.T) {
dataSourceName := "data.azurerm_proximity_placement_group.test"
ri := tf.AccRandTimeInt()
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceProximityPlacementGroup_basic(ri, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "location"),
resource.TestCheckResourceAttrSet(dataSourceName, "name"),
resource.TestCheckResourceAttrSet(dataSourceName, "resource_group_name"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"),
),
},
},
})
}

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

resource "azurerm_proximity_placement_group" "test" {
name = "acctestppg-%[1]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"

tags = {
"foo" = "bar"
}
}

data "azurerm_proximity_placement_group" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
name = "${azurerm_proximity_placement_group.test.name}"
}
`, rInt, location)
}
57 changes: 31 additions & 26 deletions azurerm/internal/services/compute/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import (
)

type Client struct {
AvailabilitySetsClient *compute.AvailabilitySetsClient
DisksClient *compute.DisksClient
GalleriesClient *compute.GalleriesClient
GalleryImagesClient *compute.GalleryImagesClient
GalleryImageVersionsClient *compute.GalleryImageVersionsClient
ImagesClient *compute.ImagesClient
SnapshotsClient *compute.SnapshotsClient
UsageClient *compute.UsageClient
VMExtensionImageClient *compute.VirtualMachineExtensionImagesClient
VMExtensionClient *compute.VirtualMachineExtensionsClient
VMScaleSetClient *compute.VirtualMachineScaleSetsClient
VMClient *compute.VirtualMachinesClient
VMImageClient *compute.VirtualMachineImagesClient
AvailabilitySetsClient *compute.AvailabilitySetsClient
DisksClient *compute.DisksClient
GalleriesClient *compute.GalleriesClient
GalleryImagesClient *compute.GalleryImagesClient
GalleryImageVersionsClient *compute.GalleryImageVersionsClient
ProximityPlacementGroupsClient *compute.ProximityPlacementGroupsClient
ImagesClient *compute.ImagesClient
SnapshotsClient *compute.SnapshotsClient
UsageClient *compute.UsageClient
VMExtensionImageClient *compute.VirtualMachineExtensionImagesClient
VMExtensionClient *compute.VirtualMachineExtensionsClient
VMScaleSetClient *compute.VirtualMachineScaleSetsClient
VMClient *compute.VirtualMachinesClient
VMImageClient *compute.VirtualMachineImagesClient
}

func BuildClient(o *common.ClientOptions) *Client {
Expand All @@ -41,6 +42,9 @@ func BuildClient(o *common.ClientOptions) *Client {
ImagesClient := compute.NewImagesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ImagesClient.Client, o.ResourceManagerAuthorizer)

ProximityPlacementGroupsClient := compute.NewProximityPlacementGroupsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ProximityPlacementGroupsClient.Client, o.ResourceManagerAuthorizer)

SnapshotsClient := compute.NewSnapshotsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&SnapshotsClient.Client, o.ResourceManagerAuthorizer)

Expand All @@ -63,18 +67,19 @@ func BuildClient(o *common.ClientOptions) *Client {
o.ConfigureClient(&VMClient.Client, o.ResourceManagerAuthorizer)

return &Client{
AvailabilitySetsClient: &AvailabilitySetsClient,
DisksClient: &DisksClient,
GalleriesClient: &GalleriesClient,
GalleryImagesClient: &GalleryImagesClient,
GalleryImageVersionsClient: &GalleryImageVersionsClient,
ImagesClient: &ImagesClient,
SnapshotsClient: &SnapshotsClient,
UsageClient: &UsageClient,
VMExtensionImageClient: &VMExtensionImageClient,
VMExtensionClient: &VMExtensionClient,
VMScaleSetClient: &VMScaleSetClient,
VMClient: &VMClient,
VMImageClient: &VMImageClient,
AvailabilitySetsClient: &AvailabilitySetsClient,
DisksClient: &DisksClient,
GalleriesClient: &GalleriesClient,
GalleryImagesClient: &GalleryImagesClient,
GalleryImageVersionsClient: &GalleryImageVersionsClient,
ImagesClient: &ImagesClient,
ProximityPlacementGroupsClient: &ProximityPlacementGroupsClient,
SnapshotsClient: &SnapshotsClient,
UsageClient: &UsageClient,
VMExtensionImageClient: &VMExtensionImageClient,
VMExtensionClient: &VMExtensionClient,
VMScaleSetClient: &VMScaleSetClient,
VMClient: &VMClient,
VMImageClient: &VMImageClient,
}
}
2 changes: 2 additions & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_notification_hub": dataSourceNotificationHub(),
"azurerm_platform_image": dataSourceArmPlatformImage(),
"azurerm_policy_definition": dataSourceArmPolicyDefinition(),
"azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(),
"azurerm_public_ip": dataSourceArmPublicIP(),
"azurerm_public_ips": dataSourceArmPublicIPs(),
"azurerm_recovery_services_vault": dataSourceArmRecoveryServicesVault(),
Expand Down Expand Up @@ -324,6 +325,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_private_dns_zone": resourceArmPrivateDnsZone(),
"azurerm_private_dns_a_record": resourceArmPrivateDnsARecord(),
"azurerm_private_dns_cname_record": resourceArmPrivateDnsCNameRecord(),
"azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(),
"azurerm_public_ip": resourceArmPublicIp(),
"azurerm_public_ip_prefix": resourceArmPublicIpPrefix(),
"azurerm_recovery_services_protected_vm": resourceArmRecoveryServicesProtectedVm(),
Expand Down
24 changes: 24 additions & 0 deletions azurerm/resource_arm_availability_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ func resourceArmAvailabilitySet() *schema.Resource {
ForceNew: true,
},

"proximity_placement_group_id": {
tobydoescode marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Optional: true,
ForceNew: true,
StateFunc: func(id interface{}) string {
return strings.ToLower(id.(string))
},
},

"tags": tags.Schema(),
},
}
Expand Down Expand Up @@ -101,6 +110,15 @@ func resourceArmAvailabilitySetCreateUpdate(d *schema.ResourceData, meta interfa
Tags: tags.Expand(t),
}

if v, ok := d.GetOk("proximity_placement_group_id"); ok {
tobydoescode marked this conversation as resolved.
Show resolved Hide resolved
proximityPlacementGroup := v.(string)
ppg := compute.SubResource{
ID: &proximityPlacementGroup,
}

availSet.AvailabilitySetProperties.ProximityPlacementGroup = &ppg
}

if managed {
n := "Aligned"
availSet.Sku = &compute.Sku{
Expand Down Expand Up @@ -150,6 +168,12 @@ func resourceArmAvailabilitySetRead(d *schema.ResourceData, meta interface{}) er
if props := resp.AvailabilitySetProperties; props != nil {
d.Set("platform_update_domain_count", props.PlatformUpdateDomainCount)
d.Set("platform_fault_domain_count", props.PlatformFaultDomainCount)

if proximityPlacementGroup := props.ProximityPlacementGroup; proximityPlacementGroup != nil {
// Lowercase due to incorrect capitalisation of resource group name in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this have potential issues if there are capitables in other places? we should be more specific with the fix.

Also, has a bug report been files/opened anywhere? if not could we open on on the azure for go sdk and link it here with an addtional comment:
this can be removed when http://link.to.issue has been fixed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment the ID, this is in-line with how availability set ID are handled.

// proximity placement group ID in response from get VM API request
d.Set("proximity_placement_group_id", strings.ToLower(*proximityPlacementGroup.ID))
}
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down
Loading