-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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_slice
; New Data Source: `azure…
…rm_mobile_network_slice` (#20336) * New Resource: `azurerm_mobile_network_slice` * limit acctest location * fix docs and error output * refresh vendor * update code * update code * doc update
- Loading branch information
Showing
23 changed files
with
1,476 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
137 changes: 137 additions & 0 deletions
137
internal/services/mobilenetwork/mobile_network_slice_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,137 @@ | ||
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/go-azure-sdk/resource-manager/mobilenetwork/2022-11-01/slice" | ||
"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 SliceDataSource struct{} | ||
|
||
var _ sdk.DataSource = SliceDataSource{} | ||
|
||
func (r SliceDataSource) ResourceType() string { | ||
return "azurerm_mobile_network_slice" | ||
} | ||
|
||
func (r SliceDataSource) ModelObject() interface{} { | ||
return &SliceModel{} | ||
} | ||
|
||
func (r SliceDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return slice.ValidateSliceID | ||
} | ||
|
||
func (r SliceDataSource) Arguments() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringIsNotEmpty, | ||
}, | ||
|
||
"mobile_network_id": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: mobilenetwork.ValidateMobileNetworkID, | ||
}, | ||
} | ||
} | ||
|
||
func (r SliceDataSource) Attributes() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
|
||
"description": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"location": commonschema.LocationComputed(), | ||
|
||
"single_network_slice_selection_assistance_information": { | ||
Type: pluginsdk.TypeList, | ||
Computed: true, | ||
|
||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*pluginsdk.Schema{ | ||
"slice_differentiator": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"slice_service_type": { | ||
Type: pluginsdk.TypeInt, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"tags": commonschema.TagsDataSource(), | ||
} | ||
} | ||
|
||
func (r SliceDataSource) Read() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 5 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
var metaModel SliceModel | ||
if err := metadata.Decode(&metaModel); err != nil { | ||
return fmt.Errorf("decoding: %+v", err) | ||
} | ||
|
||
client := metadata.Client.MobileNetwork.SliceClient | ||
mobileNetworkId, err := mobilenetwork.ParseMobileNetworkID(metaModel.MobileNetworkMobileNetworkId) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
id := slice.NewSliceID(mobileNetworkId.SubscriptionId, mobileNetworkId.ResourceGroupName, mobileNetworkId.MobileNetworkName, 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) | ||
} | ||
|
||
if resp.Model == nil { | ||
return fmt.Errorf("retrieving %s: model was nil", id) | ||
} | ||
|
||
model := *resp.Model | ||
|
||
state := SliceModel{ | ||
Name: id.SliceName, | ||
MobileNetworkMobileNetworkId: mobilenetwork.NewMobileNetworkID(id.SubscriptionId, id.ResourceGroupName, id.MobileNetworkName).ID(), | ||
Location: location.Normalize(model.Location), | ||
} | ||
|
||
properties := model.Properties | ||
if properties.Description != nil { | ||
state.Description = *properties.Description | ||
} | ||
|
||
state.Snssai = flattenSnssaiModel(properties.Snssai) | ||
|
||
if resp.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_slice_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 MobileNetworkSliceDataSource struct{} | ||
|
||
func TestAccMobileNetworkSliceDataSource_complete(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_mobile_network_slice", "test") | ||
|
||
// Limited regional availability for Mobile Network | ||
data.Locations.Primary = "eastus" | ||
|
||
d := MobileNetworkSliceDataSource{} | ||
data.DataSourceTest(t, []acceptance.TestStep{ | ||
{ | ||
Config: d.complete(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).Key(`location`).Exists(), | ||
check.That(data.ResourceName).Key(`description`).HasValue("my favorite slice"), | ||
check.That(data.ResourceName).Key(`single_network_slice_selection_assistance_information.0.slice_service_type`).HasValue("1"), | ||
check.That(data.ResourceName).Key("tags.%").HasValue("1"), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (r MobileNetworkSliceDataSource) complete(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "azurerm_mobile_network_slice" "test" { | ||
name = azurerm_mobile_network_slice.test.name | ||
mobile_network_id = azurerm_mobile_network_slice.test.mobile_network_id | ||
} | ||
`, MobileNetworkSliceResource{}.complete(data)) | ||
} |
Oops, something went wrong.