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: azurerm_mobile_network_packet_core_data_plane;New DataSource: azurerm_mobile_network_packet_core_data_plane #21053

Merged
merged 2 commits into from
Jun 13, 2023
Merged
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
6 changes: 6 additions & 0 deletions internal/services/mobilenetwork/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/datanetwork"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/mobilenetwork"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/packetcorecontrolplane"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/packetcoredataplane"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/service"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/simgroup"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/simpolicy"
Expand All @@ -21,6 +22,7 @@ type Client struct {
DataNetworkClient *datanetwork.DataNetworkClient
SIMPolicyClient *simpolicy.SIMPolicyClient
PacketCoreControlPlaneClient *packetcorecontrolplane.PacketCoreControlPlaneClient
PacketCoreDataPlaneClient *packetcoredataplane.PacketCoreDataPlaneClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand Down Expand Up @@ -48,6 +50,9 @@ func NewClient(o *common.ClientOptions) *Client {
packetCoreControlPlaneClient := packetcorecontrolplane.NewPacketCoreControlPlaneClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&packetCoreControlPlaneClient.Client, o.ResourceManagerAuthorizer)

packetCoreDataPlaneClient := packetcoredataplane.NewPacketCoreDataPlaneClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&packetCoreDataPlaneClient.Client, o.ResourceManagerAuthorizer)

return &Client{
MobileNetworkClient: &mobileNetworkClient,
DataNetworkClient: &dataNetworkClient,
Expand All @@ -57,5 +62,6 @@ func NewClient(o *common.ClientOptions) *Client {
SliceClient: &sliceClient,
SIMPolicyClient: &simPolicyClient,
PacketCoreControlPlaneClient: &packetCoreControlPlaneClient,
PacketCoreDataPlaneClient: &packetCoreDataPlaneClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package mobilenetwork

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/packetcorecontrolplane"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/packetcoredataplane"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

type PacketCoreDataPlaneDataSource struct{}

var _ sdk.DataSource = PacketCoreDataPlaneDataSource{}

func (r PacketCoreDataPlaneDataSource) ResourceType() string {
return "azurerm_mobile_network_packet_core_data_plane"
}

func (r PacketCoreDataPlaneDataSource) ModelObject() interface{} {
return &PacketCoreDataPlaneModel{}
}

func (r PacketCoreDataPlaneDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return packetcoredataplane.ValidatePacketCoreDataPlaneID
}

func (r PacketCoreDataPlaneDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"mobile_network_packet_core_control_plane_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: packetcorecontrolplane.ValidatePacketCoreControlPlaneID,
},
}
}

func (r PacketCoreDataPlaneDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"location": commonschema.LocationComputed(),

"tags": commonschema.TagsDataSource(),

"user_plane_access_name": {
Type: pluginsdk.TypeString,
Computed: true,
},

"user_plane_access_ipv4_address": {
Type: pluginsdk.TypeString,
Computed: true,
},

"user_plane_access_ipv4_subnet": {
Type: pluginsdk.TypeString,
Computed: true,
},

"user_plane_access_ipv4_gateway": {
Type: pluginsdk.TypeString,
Computed: true,
},
}
}

func (r PacketCoreDataPlaneDataSource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
var metaModel PacketCoreDataPlaneModel
if err := metadata.Decode(&metaModel); err != nil {
return fmt.Errorf("decoding: %+v", err)
}

client := metadata.Client.MobileNetwork.PacketCoreDataPlaneClient
packetCoreControlPlaneId, err := packetcorecontrolplane.ParsePacketCoreControlPlaneID(metaModel.MobileNetworkPacketCoreControlPlaneId)
if err != nil {
return err
}

id := packetcoredataplane.NewPacketCoreDataPlaneID(packetCoreControlPlaneId.SubscriptionId, packetCoreControlPlaneId.ResourceGroupName, packetCoreControlPlaneId.PacketCoreControlPlaneName, metaModel.Name)

resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}

return fmt.Errorf("retrieving %s: %+v", id, err)
}

state := PacketCoreDataPlaneModel{
Name: id.PacketCoreDataPlaneName,
MobileNetworkPacketCoreControlPlaneId: packetcorecontrolplane.NewPacketCoreControlPlaneID(id.SubscriptionId, id.ResourceGroupName, id.PacketCoreControlPlaneName).ID(),
}

if resp.Model != nil {
state.Location = location.Normalize(resp.Model.Location)

props := resp.Model.Properties

state.UserPlaneAccessIPv4Address = pointer.From(props.UserPlaneAccessInterface.IPv4Address)
state.UserPlaneAccessIPv4Gateway = pointer.From(props.UserPlaneAccessInterface.IPv4Gateway)
state.UserPlaneAccessIPv4Subnet = pointer.From(props.UserPlaneAccessInterface.IPv4Subnet)
state.UserPlaneAccessName = pointer.From(props.UserPlaneAccessInterface.Name)

if resp.Model.Tags != nil {
state.Tags = *resp.Model.Tags
}
}

metadata.SetID(id)

return metadata.Encode(&state)
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package mobilenetwork_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type MobileNetworkPacketCoreDataPlaneDataSource struct{}

func TestAccMobileNetworkPacketCoreDataPlaneDataSource_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mobile_network_packet_core_data_plane", "test")
// Limited regional availability for Mobile Network
data.Locations.Primary = "eastus"

d := MobileNetworkPacketCoreDataPlaneDataSource{}
data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key(`location`).Exists(),
check.That(data.ResourceName).Key(`user_plane_access_name`).HasValue("default-interface"),
check.That(data.ResourceName).Key(`user_plane_access_ipv4_address`).HasValue("192.168.1.199"),
check.That(data.ResourceName).Key(`user_plane_access_ipv4_gateway`).HasValue("192.168.1.1"),
check.That(data.ResourceName).Key(`user_plane_access_ipv4_subnet`).HasValue("192.168.1.0/25"),
check.That(data.ResourceName).Key("tags.%").HasValue("1"),
),
},
})
}

func (r MobileNetworkPacketCoreDataPlaneDataSource) complete(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

data "azurerm_mobile_network_packet_core_data_plane" "test" {
name = azurerm_mobile_network_packet_core_data_plane.test.name
mobile_network_packet_core_control_plane_id = azurerm_mobile_network_packet_core_data_plane.test.mobile_network_packet_core_control_plane_id
}
`, MobileNetworkPacketCoreDataPlaneResource{}.complete(data))
}
Loading