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

Code generation from magic-module-specs#121 for Terraform #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
200 changes: 200 additions & 0 deletions azurerm/data_source_private_endpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file at
// https://github.com/Azure/magic-module-specs
//
// ----------------------------------------------------------------------------

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 dataSourceArmPrivateEndpoint() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmPrivateEndpointRead,

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

"location": azure.SchemaLocationForDataSource(),

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"manual_private_link_service_connections": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"private_link_service_id": {
Type: schema.TypeString,
Computed: true,
},
"group_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"request_message": {
Type: schema.TypeString,
Computed: true,
},
"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,
},
},
},
},
},
},
},

"network_interfaces": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"private_link_service_connections": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"private_link_service_id": {
Type: schema.TypeString,
Computed: true,
},
"group_ids": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"request_message": {
Type: schema.TypeString,
Computed: true,
},
"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,
},
},
},
},
},
},
},

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

"tags": tagsForDataSourceSchema(),
},
}
}

func dataSourceArmPrivateEndpointRead(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)
}

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 privateEndpointProperties := resp.PrivateEndpointProperties; privateEndpointProperties != nil {
if err := d.Set("manual_private_link_service_connections", flattenArmPrivateEndpointPrivateLinkServiceConnection(privateEndpointProperties.ManualPrivateLinkServiceConnections)); err != nil {
return fmt.Errorf("Error setting `manual_private_link_service_connections`: %+v", err)
}
if err := d.Set("network_interfaces", flattenArmPrivateEndpointInterface(privateEndpointProperties.NetworkInterfaces)); err != nil {
return fmt.Errorf("Error setting `network_interfaces`: %+v", err)
}
if err := d.Set("private_link_service_connections", flattenArmPrivateEndpointPrivateLinkServiceConnection(privateEndpointProperties.PrivateLinkServiceConnections)); err != nil {
return fmt.Errorf("Error setting `private_link_service_connections`: %+v", err)
}
if subnet := privateEndpointProperties.Subnet; subnet != nil {
d.Set("subnet_id", subnet.ID)
}
}
tags.FlattenAndSet(d, resp.Tags)

return nil
}
124 changes: 124 additions & 0 deletions azurerm/data_source_private_endpoint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file at
// https://github.com/Azure/magic-module-specs
//
// ----------------------------------------------------------------------------

package azurerm

import (
"fmt"
"testing"

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

func TestAccDataSourceAzureRMPrivateEndpoint_basic(t *testing.T) {
dataSourceName := "data.azurerm_private_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"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.0.name", "<%= get_resource_name('privatelinkservice', 'connection') -%>"),
),
},
},
})
}
func TestAccDataSourceAzureRMPrivateEndpoint_complete(t *testing.T) {
dataSourceName := "data.azurerm_private_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, "private_link_service_connections.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.0.name", "<%= get_resource_name('privatelinkservice', 'connection') -%>"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.0.group_ids.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.0.request_message", "plz approve my request"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName, "tags.env", "test"),
),
},
},
})
}
func TestAccDataSourceAzureRMPrivateEndpoint_update(t *testing.T) {
dataSourceName := "data.azurerm_private_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"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.0.name", "<%= get_resource_name('privatelinkservice', 'connection') -%>"),
),
},
{
Config: testAccDataSourcePrivateEndpoint_complete(ri, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(dataSourceName, "subnet_id"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.#", "1"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.0.name", "<%= get_resource_name('privatelinkservice', 'connection') -%>"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.0.group_ids.#", "0"),
resource.TestCheckResourceAttr(dataSourceName, "private_link_service_connections.0.request_message", "plz approve my request"),
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_endpoint" "test" {
resource_group_name = "${azurerm_private_endpoint.test.resource_group_name}"
name = "${azurerm_private_endpoint.test.name}"
}
`, config)
}

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

data "azurerm_private_endpoint" "test" {
resource_group_name = "${azurerm_private_endpoint.test.resource_group_name}"
name = "${azurerm_private_endpoint.test.name}"
}
`, config)
}
Loading