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/Data Source: azurerm_private_link_service, Data Source: azurerm_private_link_service_endpoint_connections and expose in azurerm_lb and azurerm_subnet #4426

Merged
merged 49 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
c320621
Add new resources and data sources
WodansSon Sep 25, 2019
978be18
Manual fixup
WodansSon Sep 25, 2019
b196c7f
TOC tweaks
WodansSon Sep 25, 2019
3ad7245
Examples fix
WodansSon Sep 25, 2019
e86b1e5
[WIP] Current Progress
WodansSon Sep 26, 2019
99a9179
[WIP] Updates to code
WodansSon Sep 26, 2019
cfb7bc0
[WIP] gofmt
WodansSon Sep 26, 2019
b2b681e
[WIP] Final changes
WodansSon Sep 28, 2019
5abd85a
[WIP] Updated Tests and Docs
WodansSon Sep 28, 2019
19c8dfd
[WIP] Updated test cases
WodansSon Oct 1, 2019
d4bd7e4
[WIP] fix test and lint
WodansSon Oct 1, 2019
08695db
[WIP] Update attribute
WodansSon Oct 3, 2019
8067191
[WIP] Progress
WodansSon Oct 4, 2019
3ffd269
[WIP] Progress
WodansSon Oct 5, 2019
693df4b
Updates per PR
WodansSon Oct 8, 2019
d54e001
Gofmt
WodansSon Oct 8, 2019
deec420
Merge branch 'master' of https://github.com/terraform-providers/terra…
WodansSon Oct 8, 2019
5422f4f
Updates for the new terraform-plugin-sdk
WodansSon Oct 9, 2019
cf6a876
Removed leading newline
WodansSon Oct 9, 2019
44052c7
Updates per PR feedback
WodansSon Oct 11, 2019
474375a
A couple other things
WodansSon Oct 11, 2019
a1e79b2
Gofmt validate
WodansSon Oct 11, 2019
d1ae650
Update Subnet documentation
WodansSon Oct 11, 2019
24d5986
Fix schema and removed unused code refactor
WodansSon Oct 23, 2019
1ea5f77
Merge branch 'master' into nr_private-link-service
WodansSon Oct 30, 2019
97f86ee
Fixed conflict
WodansSon Oct 30, 2019
11cb0e2
Added some more validation
WodansSon Nov 1, 2019
1870099
Resource is good now
WodansSon Nov 5, 2019
a2e93d8
Update name all private link endpoint attributes
WodansSon Nov 5, 2019
bca2ca5
New datasource and refactor done
WodansSon Nov 5, 2019
1f68a54
Fix test and lint issues
WodansSon Nov 6, 2019
ae318b6
Updates per PR comments
WodansSon Nov 12, 2019
2526235
Add subbcategory to docs
WodansSon Nov 12, 2019
94e12d1
Updated name of policy enforcement
WodansSon Nov 12, 2019
627cf84
Fix docs and example
WodansSon Nov 12, 2019
315128f
in progress
WodansSon Nov 12, 2019
d85ba9a
Updates per Tom PR comment and test
WodansSon Nov 14, 2019
e635720
Update website/docs/r/subnet.html.markdown
WodansSon Nov 18, 2019
8301465
Update website/docs/d/private_link_service.html.markdown
WodansSon Nov 18, 2019
d4100c5
Merge branch 'master' into nr_private-link-service
WodansSon Nov 18, 2019
d55f495
gofmt provider
WodansSon Nov 18, 2019
26d0a88
Merge branch 'master' of https://github.com/terraform-providers/terra…
WodansSon Nov 19, 2019
708d10c
Add private link service datasource
WodansSon Nov 19, 2019
e05fc52
Updates per PR comments
WodansSon Nov 20, 2019
50467d8
Merge branch 'master' into nr_private-link-service
WodansSon Nov 20, 2019
00bc22b
Updates per PR comments
WodansSon Nov 21, 2019
8bc37dc
Added state wait code
WodansSon Nov 21, 2019
29a07fd
Fix test collision issue
WodansSon Nov 21, 2019
b2dec30
Update data source validation
WodansSon Nov 21, 2019
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
9 changes: 9 additions & 0 deletions azurerm/data_source_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func dataSourceArmLoadBalancer() *schema.Resource {
},

"zones": azure.SchemaZonesComputed(),

"id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -151,6 +156,10 @@ func flattenLoadBalancerDataSourceFrontendIpConfiguration(ipConfigs *[]network.F
ipConfig["name"] = *config.Name
}

if config.ID != nil {
ipConfig["id"] = *config.ID
}

zones := make([]string, 0)
if zs := config.Zones; zs != nil {
zones = *zs
Expand Down
214 changes: 214 additions & 0 deletions azurerm/data_source_private_link_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
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/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmPrivateLinkService() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmPrivateLinkServiceRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validate.NoEmptyStrings,
},

"location": azure.SchemaLocation(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be azure.SchemaLocationForDataSource ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.


"resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whats the reasoning behind suppressing case difference here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Defensive programming, Azure tends to not be very consistent with casing... I removed it and switched it to SchemaResourceGroupNameForDataSource


"auto_approval_subscription_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"visibility_subscription_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"fqdns": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"nat_ip_configuration": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"private_ip_allocation_method": {
Type: schema.TypeString,
Computed: true,
},
"private_ip_address": {
Type: schema.TypeString,
Computed: true,
},
"private_ip_address_version": {
Type: schema.TypeString,
Computed: true,
},
"primary": {
Type: schema.TypeBool,
Computed: true,
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"load_balancer_frontend_ip_configuration_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"private_endpoint_connection": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"private_endpoint": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"location": azure.SchemaLocationForDataSource(),
"tags": tagsForDataSourceSchema(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use the new tags.SchemaForDataSource function

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

},
},
},
"private_link_service_connection_state": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"action_required": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"status": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},

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

"network_interface_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

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

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

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

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

resp, err := client.Get(ctx, resourceGroup, name, "")
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Private Link Service %q (Resource Group %q) was not found", name, resourceGroup)
}
return fmt.Errorf("Error reading Private Link Service %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)
katbyte marked this conversation as resolved.
Show resolved Hide resolved

d.Set("name", resp.Name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azure.NormalizeLocation(*location))
}
if privateLinkServiceProperties := resp.PrivateLinkServiceProperties; privateLinkServiceProperties != nil {
d.Set("alias", privateLinkServiceProperties.Alias)
if err := d.Set("auto_approval", flattenArmPrivateLinkServicePrivateLinkServicePropertiesAutoApproval(privateLinkServiceProperties.AutoApproval)); err != nil {
return fmt.Errorf("Error setting `auto_approval`: %+v", err)
}
d.Set("fqdns", utils.FlattenStringSlice(privateLinkServiceProperties.Fqdns))
if err := d.Set("ip_configurations", flattenArmPrivateLinkServicePrivateLinkServiceIPConfiguration(privateLinkServiceProperties.IPConfigurations)); err != nil {
return fmt.Errorf("Error setting `ip_configurations`: %+v", err)
}
if err := d.Set("load_balancer_frontend_ip_configurations", flattenArmPrivateLinkServiceFrontendIPConfiguration(privateLinkServiceProperties.LoadBalancerFrontendIPConfigurations)); err != nil {
return fmt.Errorf("Error setting `load_balancer_frontend_ip_configurations`: %+v", err)
}
if err := d.Set("network_interfaces", flattenArmPrivateLinkServiceInterface(privateLinkServiceProperties.NetworkInterfaces)); err != nil {
return fmt.Errorf("Error setting `network_interfaces`: %+v", err)
}
if err := d.Set("private_endpoint_connections", flattenArmPrivateLinkServicePrivateEndpointConnection(privateLinkServiceProperties.PrivateEndpointConnections)); err != nil {
return fmt.Errorf("Error setting `private_endpoint_connections`: %+v", err)
}
if err := d.Set("visibility", flattenArmPrivateLinkServicePrivateLinkServicePropertiesVisibility(privateLinkServiceProperties.Visibility)); err != nil {
return fmt.Errorf("Error setting `visibility`: %+v", err)
}
}
d.Set("type", resp.Type)

return tags.FlattenAndSet(d, resp.Tags)
}
46 changes: 46 additions & 0 deletions azurerm/data_source_private_link_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
)

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourcePrivateLinkService_basic(ri, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "fqdns.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "fqdns.0", "testFqdns"),
resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.0.private_ip_address", "10.5.1.17"),
resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.0.private_ip_address_version", "IPv4"),
resource.TestCheckResourceAttr(dataSourceName, "nat_ip_configuration.0.private_ip_allocation_method", "Static"),
resource.TestCheckResourceAttr(dataSourceName, "load_balancer_frontend_ip_configuration_ids.#", "1"),
),
},
},
})
}

func testAccDataSourcePrivateLinkService_basic(rInt int, location string) string {
config := testAccAzureRMPrivateLinkService_basic(rInt, location)
return fmt.Sprintf(`
%s

data "azurerm_private_link_service" "test" {
resource_group_name = azurerm_private_link_service.test.resource_group_name
name = azurerm_private_link_service.test.name
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 reverse the order here? name then resource group? for style & consistency

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed.

}
`, config)
}
11 changes: 11 additions & 0 deletions azurerm/data_source_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func dataSourceArmSubnet() *schema.Resource {
Type: schema.TypeString,
},
},

"private_link_service_network_policies": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -84,6 +89,12 @@ func dataSourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error {
if props := resp.SubnetPropertiesFormat; props != nil {
d.Set("address_prefix", props.AddressPrefix)

if props.PrivateLinkServiceNetworkPolicies != nil {
d.Set("private_link_service_network_policies", props.PrivateLinkServiceNetworkPolicies)
} else {
d.Set("private_link_service_network_policies", "")
}

if props.NetworkSecurityGroup != nil {
d.Set("network_security_group_id", props.NetworkSecurityGroup.ID)
} else {
Expand Down
5 changes: 5 additions & 0 deletions azurerm/internal/services/network/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Client struct {
VirtualWanClient *network.VirtualWansClient
WatcherClient *network.WatchersClient
WebApplicationFirewallPoliciesClient *network.WebApplicationFirewallPoliciesClient
PrivateLinkServiceClient *network.PrivateLinkServicesClient
}

func BuildClient(o *common.ClientOptions) *Client {
Expand Down Expand Up @@ -88,6 +89,9 @@ func BuildClient(o *common.ClientOptions) *Client {
PublicIPPrefixesClient := network.NewPublicIPPrefixesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&PublicIPPrefixesClient.Client, o.ResourceManagerAuthorizer)

PrivateLinkServiceClient := network.NewPrivateLinkServicesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&PrivateLinkServiceClient.Client, o.ResourceManagerAuthorizer)

RoutesClient := network.NewRoutesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&RoutesClient.Client, o.ResourceManagerAuthorizer)

Expand Down Expand Up @@ -146,5 +150,6 @@ func BuildClient(o *common.ClientOptions) *Client {
VirtualWanClient: &VirtualWanClient,
WatcherClient: &WatcherClient,
WebApplicationFirewallPoliciesClient: &WebApplicationFirewallPoliciesClient,
PrivateLinkServiceClient: &PrivateLinkServiceClient,
}
}
2 changes: 2 additions & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_notification_hub": dataSourceNotificationHub(),
"azurerm_platform_image": dataSourceArmPlatformImage(),
"azurerm_policy_definition": dataSourceArmPolicyDefinition(),
"azurerm_private_link_service": dataSourceArmPrivateLinkService(),
"azurerm_proximity_placement_group": dataSourceArmProximityPlacementGroup(),
"azurerm_public_ip": dataSourceArmPublicIP(),
"azurerm_public_ips": dataSourceArmPublicIPs(),
Expand Down Expand Up @@ -361,6 +362,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_private_dns_a_record": resourceArmPrivateDnsARecord(),
"azurerm_private_dns_cname_record": resourceArmPrivateDnsCNameRecord(),
"azurerm_private_dns_zone_virtual_network_link": resourceArmPrivateDnsZoneVirtualNetworkLink(),
"azurerm_private_link_service": resourceArmPrivateLinkService(),
"azurerm_proximity_placement_group": resourceArmProximityPlacementGroup(),
"azurerm_public_ip": resourceArmPublicIp(),
"azurerm_public_ip_prefix": resourceArmPublicIpPrefix(),
Expand Down
9 changes: 9 additions & 0 deletions azurerm/resource_arm_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func resourceArmLoadBalancer() *schema.Resource {
},

"zones": azure.SchemaSingleZone(),

"id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
Expand Down Expand Up @@ -358,6 +363,10 @@ func flattenLoadBalancerFrontendIpConfiguration(ipConfigs *[]network.FrontendIPC
ipConfig["name"] = *config.Name
}

if config.ID != nil {
ipConfig["id"] = *config.ID
}

zones := make([]string, 0)
if zs := config.Zones; zs != nil {
zones = *zs
Expand Down
Loading