-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Resource:
azurerm_mobile_network_packet_core_control_plane
;New D…
…atasource: `azurerm_mobile_network_packet_core_control_plane` (#21071) Co-authored-by: Will Dewhurst <[email protected]>
- Loading branch information
1 parent
da6e07a
commit f06130a
Showing
34 changed files
with
2,734 additions
and
15 deletions.
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
241 changes: 241 additions & 0 deletions
241
internal/services/mobilenetwork/mobile_network_packet_core_control_plane_data_source.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,241 @@ | ||
package mobilenetwork | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"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/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(), | ||
|
||
"interoperability_settings_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(), | ||
|
||
"software_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) | ||
|
||
state.Identity, err = flattenMobileNetworkUserAssignedToNetworkLegacyIdentity(model.Identity) | ||
if err != nil { | ||
return fmt.Errorf("flattening `identity`: %+v", err) | ||
} | ||
|
||
properties := model.Properties | ||
|
||
state.UeMtu = pointer.From(model.Properties.UeMtu) | ||
|
||
state.ControlPlaneAccessIPv4Address = pointer.From(properties.ControlPlaneAccessInterface.IPv4Address) | ||
|
||
state.ControlPlaneAccessIPv4Gateway = pointer.From(properties.ControlPlaneAccessInterface.IPv4Gateway) | ||
|
||
state.ControlPlaneAccessIPv4Subnet = pointer.From(properties.ControlPlaneAccessInterface.IPv4Subnet) | ||
|
||
state.ControlPlaneAccessName = pointer.From(properties.ControlPlaneAccessInterface.Name) | ||
|
||
// it still needs a nil check because it needs to do type conversion | ||
if properties.CoreNetworkTechnology != nil { | ||
state.CoreNetworkTechnology = string(pointer.From(properties.CoreNetworkTechnology)) | ||
} | ||
|
||
// Marshal on a nil interface{} may get random result. | ||
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) | ||
|
||
state.Platform = flattenPlatformConfigurationModel(properties.Platform) | ||
|
||
state.Sku = string(properties.Sku) | ||
|
||
state.SoftwareVersion = pointer.From(properties.Version) | ||
state.Tags = pointer.From(model.Tags) | ||
} | ||
|
||
metadata.SetID(id) | ||
|
||
return metadata.Encode(&state) | ||
}, | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
internal/services/mobilenetwork/mobile_network_packet_core_control_plane_data_source_test.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,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)) | ||
} |
Oops, something went wrong.