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_control_plane;New Datasource: azurerm_mobile_network_packet_core_control_plane #21071

Merged
merged 32 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e659256
New Resource:`azurerm_mobile_network_packet_core_control_plane`;New D…
ziyeqf Mar 2, 2023
3dbf05b
update doc
ziyeqf Mar 2, 2023
f21e00d
terrafmt
ziyeqf Mar 2, 2023
744e7ed
rename property & limit test region
ziyeqf Mar 3, 2023
d544279
rename `interop_settings` to `interop_json`
ziyeqf Mar 15, 2023
721b291
Merge remote-tracking branch 'hashi/main' into tengzh/mn_pccp
ziyeqf Mar 15, 2023
9d5a13d
refresh vendor
ziyeqf Mar 15, 2023
60a0c4c
limit test region
ziyeqf Mar 15, 2023
1ab70fb
update per comments
ziyeqf Mar 22, 2023
97a6787
Merge remote-tracking branch 'hashi/main' into tengzh/mn_pccp
ziyeqf Mar 22, 2023
4fa2399
refresh vendor
ziyeqf Mar 22, 2023
39feda4
remove sku with vendor
ziyeqf Mar 22, 2023
f79441f
add `BaseVM` for `platform.type`
ziyeqf Mar 23, 2023
aaef3db
Merge branch 'main' into tengzh/mn_pccp
ziyeqf Apr 3, 2023
083e683
rename `interop_json` to `vendor_interop_json`
ziyeqf Apr 6, 2023
fcd662a
Moving kubernetes fleet manager from containers to container category…
dewhurstwill Apr 6, 2023
eee4f31
Merge remote-tracking branch 'hashi/main' into tengzh/mn_pccp
ziyeqf Apr 6, 2023
db67853
refresh vendor
ziyeqf Apr 6, 2023
04e91e4
Merge remote-tracking branch 'hashi/main' into tengzh/mn_pccp
ziyeqf Apr 7, 2023
f661687
update dependency
ziyeqf Apr 7, 2023
f74136a
make generate
ziyeqf Apr 7, 2023
b71e434
rename properties
ziyeqf Apr 11, 2023
fd906a1
update per comments
ziyeqf Apr 18, 2023
b012897
update test case
ziyeqf Apr 18, 2023
1d8e724
golint
ziyeqf Apr 18, 2023
8e6e709
rename `version` to `software_version`
ziyeqf May 8, 2023
43bb7e1
Merge remote-tracking branch 'hashi/main' into tengzh/mn_pccp
ziyeqf May 8, 2023
5782268
refresh dependencies
ziyeqf May 8, 2023
c2ca8f0
update per comments
ziyeqf May 11, 2023
ac624df
Merge remote-tracking branch 'hashi/main' into tengzh/mn_pccp
ziyeqf May 11, 2023
7cc75d6
update docs
ziyeqf May 11, 2023
4b927a3
update docs
ziyeqf May 11, 2023
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
34 changes: 20 additions & 14 deletions internal/services/mobilenetwork/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
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/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 @@ -12,13 +13,14 @@ import (
)

type Client struct {
MobileNetworkClient *mobilenetwork.MobileNetworkClient
ServiceClient *service.ServiceClient
SIMGroupClient *simgroup.SIMGroupClient
SliceClient *slice.SliceClient
SiteClient *site.SiteClient
DataNetworkClient *datanetwork.DataNetworkClient
SIMPolicyClient *simpolicy.SIMPolicyClient
MobileNetworkClient *mobilenetwork.MobileNetworkClient
ServiceClient *service.ServiceClient
SIMGroupClient *simgroup.SIMGroupClient
SliceClient *slice.SliceClient
SiteClient *site.SiteClient
DataNetworkClient *datanetwork.DataNetworkClient
SIMPolicyClient *simpolicy.SIMPolicyClient
PacketCoreControlPlaneClient *packetcorecontrolplane.PacketCoreControlPlaneClient
}

func NewClient(o *common.ClientOptions) *Client {
Expand All @@ -43,13 +45,17 @@ func NewClient(o *common.ClientOptions) *Client {
simPolicyClient := simpolicy.NewSIMPolicyClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&simPolicyClient.Client, o.ResourceManagerAuthorizer)

packetCoreControlPlaneClient := packetcorecontrolplane.NewPacketCoreControlPlaneClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&packetCoreControlPlaneClient.Client, o.ResourceManagerAuthorizer)

return &Client{
MobileNetworkClient: &mobileNetworkClient,
DataNetworkClient: &dataNetworkClient,
ServiceClient: &serviceClient,
SIMGroupClient: &simGroupClient,
SiteClient: &siteClient,
SliceClient: &sliceClient,
SIMPolicyClient: &simPolicyClient,
MobileNetworkClient: &mobileNetworkClient,
DataNetworkClient: &dataNetworkClient,
ServiceClient: &serviceClient,
SIMGroupClient: &simGroupClient,
SiteClient: &siteClient,
SliceClient: &sliceClient,
SIMPolicyClient: &simPolicyClient,
PacketCoreControlPlaneClient: &packetCoreControlPlaneClient,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
package mobilenetwork

import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/packetcorecontrolplane"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"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 PacketCoreControlPlaneDataSource struct{}

var _ sdk.DataSource = PacketCoreControlPlaneDataSource{}

func (r PacketCoreControlPlaneDataSource) ResourceType() string {
return "azurerm_mobile_network_packet_core_control_plane"
}

func (r PacketCoreControlPlaneDataSource) ModelObject() interface{} {
return &PacketCoreControlPlaneModel{}
}

func (r PacketCoreControlPlaneDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return packetcorecontrolplane.ValidatePacketCoreControlPlaneID
}

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

"resource_group_name": commonschema.ResourceGroupName(),
}
}

func (r PacketCoreControlPlaneDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{

"location": commonschema.LocationComputed(),

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

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

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

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

"site_ids": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},

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

"user_equipment_mtu_in_bytes": {
Type: pluginsdk.TypeInt,
Computed: true,
},

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

"platform": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"edge_device_id": {
Type: pluginsdk.TypeString,
Computed: true,
},

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

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

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

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

"identity": commonschema.UserAssignedIdentityComputed(),

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

"local_diagnostics_access": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*schema.Schema{
"authentication_type": {
Type: pluginsdk.TypeString,
Computed: true,
},
"https_server_certificate_url": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},

"tags": commonschema.TagsDataSource(),

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

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

client := metadata.Client.MobileNetwork.PacketCoreControlPlaneClient
subscriptionId := metadata.Client.Account.SubscriptionId
id := packetcorecontrolplane.NewPacketCoreControlPlaneID(subscriptionId, metaModel.ResourceGroupName, 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 := PacketCoreControlPlaneModel{
Name: id.PacketCoreControlPlaneName,
ResourceGroupName: id.ResourceGroupName,
}

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

if model.Properties.UeMtu != nil {
state.UeMtu = *model.Properties.UeMtu
}

identityValue, err := identity.FlattenLegacySystemAndUserAssignedMap(model.Identity)
if err != nil {
return fmt.Errorf("flattening `identity`: %+v", err)
}

if err := metadata.ResourceData.Set("identity", identityValue); err != nil {
return fmt.Errorf("setting `identity`: %+v", err)
}

properties := model.Properties

if properties.ControlPlaneAccessInterface.IPv4Address != nil {
state.ControlPlaneAccessIPv4Address = *properties.ControlPlaneAccessInterface.IPv4Address
}

if properties.ControlPlaneAccessInterface.IPv4Gateway != nil {
state.ControlPlaneAccessIPv4Gateway = *properties.ControlPlaneAccessInterface.IPv4Gateway
}

if properties.ControlPlaneAccessInterface.IPv4Subnet != nil {
state.ControlPlaneAccessIPv4Subnet = *properties.ControlPlaneAccessInterface.IPv4Subnet
}

if properties.ControlPlaneAccessInterface.Name != nil {
state.ControlPlaneAccessName = *properties.ControlPlaneAccessInterface.Name
}

if properties.CoreNetworkTechnology != nil {
state.CoreNetworkTechnology = string(*properties.CoreNetworkTechnology)
}

if properties.InteropSettings != nil && *properties.InteropSettings != nil {
interopSettingsValue, err := json.Marshal(*properties.InteropSettings)
if err != nil {
return err
}

state.InteropSettings = string(interopSettingsValue)
}

state.LocalDiagnosticsAccess = flattenLocalPacketCoreControlLocalDiagnosticsAccessConfiguration(properties.LocalDiagnosticsAccess)

state.SiteIds = flattenPacketCoreControlPlaneSites(properties.Sites)

platformValue := flattenPlatformConfigurationModel(properties.Platform)
state.Platform = platformValue

state.Sku = string(properties.Sku)

if properties.Version != nil {
state.Version = *properties.Version
}
if model.Tags != nil {
state.Tags = *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 MobileNetworkPacketCoreControlPlanDataSource struct{}

func TestAccMobileNetworkPacketCoreControlPlanDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mobile_network_packet_core_control_plane", "test")

// Limited regional availability for Mobile Network
data.Locations.Primary = "eastus"

d := MobileNetworkPacketCoreControlPlanDataSource{}
data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key(`location`).Exists(),
check.That(data.ResourceName).Key(`sku`).HasValue("G0"),
check.That(data.ResourceName).Key(`site_ids.#`).HasValue("1"),
check.That(data.ResourceName).Key(`local_diagnostics_access.0.authentication_type`).HasValue("AAD"),
check.That(data.ResourceName).Key(`platform.0.type`).HasValue("AKS-HCI"),
),
},
})
}

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

data "azurerm_mobile_network_packet_core_control_plane" "test" {
name = azurerm_mobile_network_packet_core_control_plane.test.name
resource_group_name = azurerm_mobile_network_packet_core_control_plane.test.resource_group_name
}
`, MobileNetworkPacketCoreControlPlaneResource{}.basic(data))
}
Loading