-
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_data_plane
;New Dat…
…aSource: `azurerm_mobile_network_packet_core_data_plane` (#21053)
- Loading branch information
Showing
22 changed files
with
1,499 additions
and
0 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
132 changes: 132 additions & 0 deletions
132
internal/services/mobilenetwork/mobile_network_packet_core_data_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,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) | ||
}, | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
internal/services/mobilenetwork/mobile_network_packet_core_data_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 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)) | ||
} |
Oops, something went wrong.