-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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: azurerm_private_link_endpoint
New Data Source: azurerm_private_link_endpoint_connection
and expose attibute in azurerm_subnet
#4493
Changes from 14 commits
64bb60e
d445539
cf252b9
266fa1b
3840307
7ce24b8
71133ca
f965560
87cb012
3a4b263
fe67c8f
bd69625
5ee333d
57ce715
52fa425
61624f4
d5e8155
07452f5
b24ac15
0d8dcd9
39eef7d
69bb2c0
f0f071d
e9300b9
a676a2f
255957d
06990fc
227ebc9
e0fde44
c0a3c8e
4ba6e4e
817ca0f
33e7fdd
e73e10e
b209b87
bb8a136
ae82096
7ab6a68
261c704
541694f
6d6a38f
d818bc6
017b56c
a8e0eac
527a2f1
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,81 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/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 dataSourceArmPrivateLinkEndpoint() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmPrivateLinkEndpointRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validate.NoEmptyStrings, | ||
}, | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"network_interface_ids": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
|
||
"subnet_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tags.SchemaDataSource(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmPrivateLinkEndpointRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*ArmClient).Network.PrivateEndpointClient | ||
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 Endpoint %q (Resource Group %q) was not found", name, resourceGroup) | ||
} | ||
return fmt.Errorf("Error reading Private Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
if resp.ID == nil || *resp.ID == "" { | ||
return fmt.Errorf("API returns a nil/empty id on Private Link Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
d.SetId(*resp.ID) | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("resource_group_name", resourceGroup) | ||
if location := resp.Location; location != nil { | ||
d.Set("location", azure.NormalizeLocation(*location)) | ||
} | ||
if props := resp.PrivateEndpointProperties; props != nil { | ||
if err := d.Set("network_interfaces", flattenArmPrivateLinkEndpointInterface(props.NetworkInterfaces)); err != nil { | ||
return fmt.Errorf("Error setting `network_interfaces`: %+v", err) | ||
} | ||
if subnet := props.Subnet; subnet != nil { | ||
d.Set("subnet_id", subnet.ID) | ||
} | ||
} | ||
|
||
return tags.FlattenAndSet(d, resp.Tags) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" | ||
) | ||
|
||
func TestAccDataSourceAzureRMPrivateEndpoint_basic(t *testing.T) { | ||
dataSourceName := "data.azurerm_private_link_endpoint.test" | ||
ri := tf.AccRandTimeInt() | ||
location := testLocation() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourcePrivateEndpoint_basic(ri, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "subnet_id"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func TestAccDataSourceAzureRMPrivateEndpoint_complete(t *testing.T) { | ||
dataSourceName := "data.azurerm_private_link_endpoint.test" | ||
ri := tf.AccRandTimeInt() | ||
location := testLocation() | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourcePrivateEndpoint_complete(ri, location), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(dataSourceName, "subnet_id"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), | ||
resource.TestCheckResourceAttr(dataSourceName, "tags.env", "test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourcePrivateEndpoint_basic(rInt int, location string) string { | ||
config := testAccAzureRMPrivateEndpoint_basic(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
data "azurerm_private_link_endpoint" "test" { | ||
resource_group_name = "${azurerm_private_link_endpoint.test.resource_group_name}" | ||
name = "${azurerm_private_link_endpoint.test.name}" | ||
} | ||
`, config) | ||
} | ||
|
||
func testAccDataSourcePrivateEndpoint_complete(rInt int, location string) string { | ||
config := testAccAzureRMPrivateEndpoint_complete(rInt, location) | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
data "azurerm_private_link_endpoint" "test" { | ||
resource_group_name = "${azurerm_private_link_endpoint.test.resource_group_name}" | ||
name = "${azurerm_private_link_endpoint.test.name}" | ||
} | ||
`, config) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,27 @@ func NoEmptyStrings(i interface{}, k string) ([]string, []error) { | |
|
||
return nil, nil | ||
} | ||
|
||
// PrivateLinkEnpointRequestMessage validates that the Private Link Enpoint Request Message is less than 140 characters | ||
func PrivateLinkEnpointRequestMessage(i interface{}, k string) (_ []string, errors []error) { | ||
return stringMaxLength(140)(i, k) | ||
} | ||
|
||
func stringMaxLength(maxLength int) func(i interface{}, k string) (_ []string, errors []error) { | ||
return func(i interface{}, k string) (_ []string, errors []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
return nil, []error{fmt.Errorf("expected type of %q to be string", k)} | ||
} | ||
|
||
if len(v) > maxLength { | ||
return nil, []error{fmt.Errorf("%q must not be longer than %d characters, got %d", k, maxLength, len(v))} | ||
} | ||
|
||
if strings.TrimSpace(v) == "" { | ||
return nil, []error{fmt.Errorf("%q must not be empty", k)} | ||
} | ||
|
||
return | ||
} | ||
} | ||
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 have 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. Same comment 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.
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. It is? looking at the code: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package network | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
) | ||
|
||
func ValidatePrivateLinkEndpointSettings(d *schema.ResourceData) error { | ||
privateServiceConnections := d.Get("private_service_connection").([]interface{}) | ||
|
||
for _, psc := range privateServiceConnections { | ||
privateServiceConnection := psc.(map[string]interface{}) | ||
name := privateServiceConnection["name"].(string) | ||
|
||
// If this is not a manule connection and the message is set return an error since this does not make sense. | ||
if !privateServiceConnection["is_manual_connection"].(bool) && privateServiceConnection["request_message"].(string) != "" { | ||
return fmt.Errorf(`"private_service_connection":%q is invalid, the "request_message" attribute cannot be set if the "is_manual_connection" attribute is "false"`, name) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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.
Could we do a regex validation here?
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.
As before, could we do some better validation here?
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... I was hoping that the private link service was going to be merged before this one so I can re-use the validation in that PR. However, I have added the validation in this one as well.