-
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/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
Changes from 31 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
c320621
Add new resources and data sources
WodansSon 978be18
Manual fixup
WodansSon b196c7f
TOC tweaks
WodansSon 3ad7245
Examples fix
WodansSon e86b1e5
[WIP] Current Progress
WodansSon 99a9179
[WIP] Updates to code
WodansSon cfb7bc0
[WIP] gofmt
WodansSon b2b681e
[WIP] Final changes
WodansSon 5abd85a
[WIP] Updated Tests and Docs
WodansSon 19c8dfd
[WIP] Updated test cases
WodansSon d4bd7e4
[WIP] fix test and lint
WodansSon 08695db
[WIP] Update attribute
WodansSon 8067191
[WIP] Progress
WodansSon 3ffd269
[WIP] Progress
WodansSon 693df4b
Updates per PR
WodansSon d54e001
Gofmt
WodansSon deec420
Merge branch 'master' of https://github.com/terraform-providers/terra…
WodansSon 5422f4f
Updates for the new terraform-plugin-sdk
WodansSon cf6a876
Removed leading newline
WodansSon 44052c7
Updates per PR feedback
WodansSon 474375a
A couple other things
WodansSon a1e79b2
Gofmt validate
WodansSon d1ae650
Update Subnet documentation
WodansSon 24d5986
Fix schema and removed unused code refactor
WodansSon 1ea5f77
Merge branch 'master' into nr_private-link-service
WodansSon 97f86ee
Fixed conflict
WodansSon 11cb0e2
Added some more validation
WodansSon 1870099
Resource is good now
WodansSon a2e93d8
Update name all private link endpoint attributes
WodansSon bca2ca5
New datasource and refactor done
WodansSon 1f68a54
Fix test and lint issues
WodansSon ae318b6
Updates per PR comments
WodansSon 2526235
Add subbcategory to docs
WodansSon 94e12d1
Updated name of policy enforcement
WodansSon 627cf84
Fix docs and example
WodansSon 315128f
in progress
WodansSon d85ba9a
Updates per Tom PR comment and test
WodansSon e635720
Update website/docs/r/subnet.html.markdown
WodansSon 8301465
Update website/docs/d/private_link_service.html.markdown
WodansSon d4100c5
Merge branch 'master' into nr_private-link-service
WodansSon d55f495
gofmt provider
WodansSon 26d0a88
Merge branch 'master' of https://github.com/terraform-providers/terra…
WodansSon 708d10c
Add private link service datasource
WodansSon e05fc52
Updates per PR comments
WodansSon 50467d8
Merge branch 'master' into nr_private-link-service
WodansSon 00bc22b
Updates per PR comments
WodansSon 8bc37dc
Added state wait code
WodansSon 29a07fd
Fix test collision issue
WodansSon b2dec30
Update data source validation
WodansSon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,197 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" | ||
"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: aznet.ValidatePrivateLinkServiceName, | ||
}, | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"resource_group_name": azure.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, | ||
}, | ||
}, | ||
|
||
// currently not implemented yet, timeline unknown, exact purpose unknown, maybe coming to a future API near you | ||
// "fqdns": { | ||
// Type: schema.TypeList, | ||
// Computed: true, | ||
// Elem: &schema.Schema{ | ||
// Type: schema.TypeString, | ||
// }, | ||
// }, | ||
|
||
"primary_nat_ip_configuration": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"private_ip_address": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"private_ip_address_version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"subnet_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"secondary_nat_ip_configuration": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"private_ip_address": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"private_ip_address_version": { | ||
Type: schema.TypeString, | ||
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, | ||
}, | ||
}, | ||
|
||
"alias": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"network_interface_ids": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
|
||
"tags": tags.SchemaDataSource(), | ||
}, | ||
} | ||
} | ||
|
||
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) | ||
} | ||
if resp.ID == nil { | ||
return fmt.Errorf("Cannot read ID for Private Link Service %q (Resource Group %q)", name, resourceGroup) | ||
} | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("resource_group_name", resourceGroup) | ||
d.Set("location", azure.NormalizeLocation(*resp.Location)) | ||
|
||
if props := resp.PrivateLinkServiceProperties; props != nil { | ||
d.Set("alias", props.Alias) | ||
if props.AutoApproval.Subscriptions != nil { | ||
if err := d.Set("auto_approval_subscription_ids", utils.FlattenStringSlice(props.AutoApproval.Subscriptions)); err != nil { | ||
return fmt.Errorf("Error setting `auto_approval_subscription_ids`: %+v", err) | ||
} | ||
} | ||
if props.Visibility.Subscriptions != nil { | ||
if err := d.Set("visibility_subscription_ids", utils.FlattenStringSlice(props.Visibility.Subscriptions)); err != nil { | ||
return fmt.Errorf("Error setting `visibility_subscription_ids`: %+v", err) | ||
} | ||
} | ||
// currently not implemented yet, timeline unknown, exact purpose unknown, maybe coming to a future API near you | ||
// if props.Fqdns != nil { | ||
// if err := d.Set("fqdns", utils.FlattenStringSlice(props.Fqdns)); err != nil { | ||
// return fmt.Errorf("Error setting `fqdns`: %+v", err) | ||
// } | ||
// } | ||
if props.IPConfigurations != nil { | ||
primaryIpConfig, secondaryIpConfig := flattenArmPrivateLinkServiceIPConfiguration(props.IPConfigurations) | ||
if err := d.Set("primary_nat_ip_configuration", primaryIpConfig); err != nil { | ||
return fmt.Errorf("Error setting `primary_nat_ip_configuration`: %+v", err) | ||
} | ||
if err := d.Set("secondary_nat_ip_configuration", secondaryIpConfig); err != nil { | ||
return fmt.Errorf("Error setting `secondary_nat_ip_configuration`: %+v", err) | ||
} | ||
} | ||
if props.LoadBalancerFrontendIPConfigurations != nil { | ||
if err := d.Set("load_balancer_frontend_ip_configuration_ids", flattenArmPrivateLinkServiceFrontendIPConfiguration(props.LoadBalancerFrontendIPConfigurations)); err != nil { | ||
return fmt.Errorf("Error setting `load_balancer_frontend_ip_configuration_ids`: %+v", err) | ||
} | ||
} | ||
if props.NetworkInterfaces != nil { | ||
if err := d.Set("network_interface_ids", flattenArmPrivateLinkServiceInterface(props.NetworkInterfaces)); err != nil { | ||
return fmt.Errorf("Error setting `network_interface_ids`: %+v", err) | ||
} | ||
} | ||
} | ||
|
||
if resp.ID == nil || *resp.ID == "" { | ||
return fmt.Errorf("API returns a nil/empty id on Private Link Service %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
d.SetId(*resp.ID) | ||
|
||
return tags.FlattenAndSet(d, resp.Tags) | ||
} |
149 changes: 149 additions & 0 deletions
149
azurerm/data_source_private_link_service_endpoint_connection_status.go
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,149 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-06-01/network" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
aznet "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network" | ||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" | ||
) | ||
|
||
func dataSourceArmPrivateLinkServiceEndpointConnectionStatus() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceArmPrivateLinkServiceEndpointConnectionStatusRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: aznet.ValidatePrivateLinkServiceName, | ||
}, | ||
|
||
"location": azure.SchemaLocationForDataSource(), | ||
|
||
"resource_group_name": azure.SchemaResourceGroupNameForDataSource(), | ||
|
||
"private_endpoint_connections": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"connection_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"connection_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"private_endpoint_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"private_endpoint_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"action_required": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceArmPrivateLinkServiceEndpointConnectionStatusRead(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) | ||
} | ||
if resp.ID == nil || *resp.ID == "" { | ||
return fmt.Errorf("API returns a nil/empty id on Private Link Service Endpoint Connection Status %q (Resource Group %q): %+v", name, resourceGroup, err) | ||
} | ||
|
||
d.Set("name", resp.Name) | ||
d.Set("resource_group_name", resourceGroup) | ||
d.Set("location", azure.NormalizeLocation(*resp.Location)) | ||
|
||
if props := resp.PrivateLinkServiceProperties; props != nil { | ||
if ip := props.PrivateEndpointConnections; ip != nil { | ||
if err := d.Set("private_endpoint_connections", flattenArmPrivateLinkServicePrivateEndpointConnections(ip)); err != nil { | ||
return fmt.Errorf("Error setting `private_endpoint_connections`: %+v", err) | ||
} | ||
} | ||
} | ||
|
||
d.SetId(*resp.ID) | ||
|
||
return nil | ||
} | ||
|
||
func flattenArmPrivateLinkServicePrivateEndpointConnections(input *[]network.PrivateEndpointConnection) []interface{} { | ||
results := make([]interface{}, 0) | ||
if input == nil { | ||
return results | ||
} | ||
|
||
for _, item := range *input { | ||
v := make(map[string]interface{}) | ||
if id := item.ID; id != nil { | ||
v["connection_id"] = *id | ||
} | ||
if name := item.Name; name != nil { | ||
v["connection_name"] = *name | ||
} | ||
|
||
if props := item.PrivateEndpointConnectionProperties; props != nil { | ||
if p := props.PrivateEndpoint; p != nil { | ||
if id := p.ID; id != nil { | ||
v["private_endpoint_id"] = *id | ||
|
||
id, _ := azure.ParseAzureResourceID(*id) | ||
name := id.Path["privateEndpoints"] | ||
if name != "" { | ||
v["private_endpoint_name"] = name | ||
} | ||
} | ||
} | ||
if s := props.PrivateLinkServiceConnectionState; s != nil { | ||
if a := s.ActionRequired; a != nil { | ||
v["action_required"] = *a | ||
} else { | ||
v["action_required"] = "none" | ||
} | ||
if d := s.Description; d != nil { | ||
v["description"] = *d | ||
} | ||
if t := s.Status; t != nil { | ||
v["status"] = *t | ||
} | ||
} | ||
} | ||
|
||
results = append(results, v) | ||
} | ||
|
||
return results | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this data source be called
aurerm_private_link_service_endpoint_connections
, and i'm still not sure it should be in terraformThere 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.
Updated the name, this data source is the only way the end user can query the state of the endpoints that are connected to the service.