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; New DataSource: azurerm_mobile_network; #20128

Merged
merged 4 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions .github/labeler-pull-request-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ service/media:
service/mixed-reality:
- internal/services/mixedreality/**/*

service/mobile-network:
- internal/services/mobilenetwork/**/*

service/monitor:
- internal/services/monitor/**/*

Expand Down
1 change: 1 addition & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var services = mapOf(
"media" to "Media",
"mssql" to "Microsoft SQL Server / Azure SQL",
"mixedreality" to "Mixed Reality",
"mobilenetwork" to "Mobile Network",
"monitor" to "Monitor",
"mysql" to "MySQL",
"netapp" to "NetApp",
Expand Down
3 changes: 3 additions & 0 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import (
mariadb "github.com/hashicorp/terraform-provider-azurerm/internal/services/mariadb/client"
media "github.com/hashicorp/terraform-provider-azurerm/internal/services/media/client"
mixedreality "github.com/hashicorp/terraform-provider-azurerm/internal/services/mixedreality/client"
mobilenetwork "github.com/hashicorp/terraform-provider-azurerm/internal/services/mobilenetwork/client"
monitor "github.com/hashicorp/terraform-provider-azurerm/internal/services/monitor/client"
mssql "github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql/client"
mysql "github.com/hashicorp/terraform-provider-azurerm/internal/services/mysql/client"
Expand Down Expand Up @@ -201,6 +202,7 @@ type Client struct {
Media *media.Client
MixedReality *mixedreality.Client
Monitor *monitor.Client
MobileNetwork *mobilenetwork.Client
MSSQL *mssql.Client
MySQL *mysql.Client
NetApp *netapp.Client
Expand Down Expand Up @@ -322,6 +324,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Media = media.NewClient(o)
client.MixedReality = mixedreality.NewClient(o)
client.Monitor = monitor.NewClient(o)
client.MobileNetwork = mobilenetwork.NewClient(o)
client.MSSQL = mssql.NewClient(o)
client.MySQL = mysql.NewClient(o)
client.NetApp = netapp.NewClient(o)
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mariadb"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/media"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mixedreality"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mobilenetwork"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/monitor"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mssql"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/mysql"
Expand Down Expand Up @@ -146,6 +147,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
loganalytics.Registration{},
media.Registration{},
monitor.Registration{},
mobilenetwork.Registration{},
mssql.Registration{},
network.Registration{},
nginx.Registration{},
Expand Down
19 changes: 19 additions & 0 deletions internal/services/mobilenetwork/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package client

import (
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/mobilenetwork"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

type Client struct {
MobileNetworkClient *mobilenetwork.MobileNetworkClient
}

func NewClient(o *common.ClientOptions) *Client {
mobileNetworkClient := mobilenetwork.NewMobileNetworkClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&mobileNetworkClient.Client, o.ResourceManagerAuthorizer)

return &Client{
MobileNetworkClient: &mobileNetworkClient,
}
}
118 changes: 118 additions & 0 deletions internal/services/mobilenetwork/mobile_network_data_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package mobilenetwork

import (
"context"
"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/location"
"github.com/hashicorp/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/mobilenetwork"
"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 MobileNetworkDataSource struct{}

var _ sdk.DataSource = MobileNetworkDataSource{}

func (r MobileNetworkDataSource) ResourceType() string {
return "azurerm_mobile_network"
}

func (r MobileNetworkDataSource) ModelObject() interface{} {
return &MobileNetworkModel{}
}

func (r MobileNetworkDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc {
return mobilenetwork.ValidateMobileNetworkID
}

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

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

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

"location": commonschema.LocationComputed(),

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

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

"tags": commonschema.TagsDataSource(),

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

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

client := metadata.Client.MobileNetwork.MobileNetworkClient
subscriptionId := metadata.Client.Account.SubscriptionId
id := mobilenetwork.NewMobileNetworkID(subscriptionId, metaModel.ResourceGroupName, metaModel.Name)

resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return metadata.MarkAsGone(id)
}

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

model := resp.Model
if model == nil {
return fmt.Errorf("retrieving %s: model was nil", id)
}

state := MobileNetworkModel{
Name: id.MobileNetworkName,
ResourceGroupName: id.ResourceGroupName,
Location: location.Normalize(model.Location),
MobileCountryCode: model.Properties.PublicLandMobileNetworkIdentifier.Mcc,
MobileNetworkCode: model.Properties.PublicLandMobileNetworkIdentifier.Mnc,
}

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

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,38 @@
package mobilenetwork_test

import (
"fmt"
"testing"

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

type MobileNetworkDataSource struct{}

func TestAccMobileNetworkDataSource_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mobile_network", "test")
d := MobileNetworkDataSource{}
data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key(`location`).Exists(),
check.That(data.ResourceName).Key(`mobile_country_code`).HasValue("001"),
check.That(data.ResourceName).Key(`mobile_network_code`).HasValue("01"),
),
},
data.ImportStep(),
})
}

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

data "azurerm_mobile_network" "test" {
name = azurerm_mobile_network.test.name
resource_group_name = azurerm_mobile_network.test.resource_group_name
}
`, MobileNetworkResource{}.complete(data))
}
Loading