-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Changes from 11 commits
c320621
978be18
b196c7f
3ad7245
e86b1e5
99a9179
cfb7bc0
b2b681e
5abd85a
19c8dfd
d4bd7e4
08695db
8067191
3ffd269
693df4b
d54e001
deec420
5422f4f
cf6a876
44052c7
474375a
a1e79b2
d1ae650
24d5986
1ea5f77
97f86ee
11cb0e2
1870099
a2e93d8
bca2ca5
1f68a54
ae318b6
2526235
94e12d1
627cf84
315128f
d85ba9a
e635720
8301465
d4100c5
d55f495
26d0a88
708d10c
e05fc52
50467d8
00bc22b
8bc37dc
29a07fd
b2dec30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(), | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whats the reasoning behind suppressing case difference here? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
"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(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should use the new There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
} | ||
`, config) | ||
} |
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.