-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
; New DataSource: `azurerm_mobi…
…le_network`; (#20128)
- Loading branch information
Showing
27 changed files
with
1,440 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
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
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
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
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,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
118
internal/services/mobilenetwork/mobile_network_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,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) | ||
}, | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
internal/services/mobilenetwork/mobile_network_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,42 @@ | ||
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") | ||
|
||
// Limited regional availability for Mobile Network | ||
data.Locations.Primary = "eastus" | ||
|
||
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)) | ||
} |
Oops, something went wrong.