-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_sim_group
; New DataSource: azurerm_mobile_network_sim_group
#20339
Merged
Merged
New Resource: azurerm_mobile_network_sim_group
; New DataSource: azurerm_mobile_network_sim_group
#20339
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
87fa185
New Resource: `azurerm_mobile_network_sim_group`; New DataSource: `az…
ziyeqf 7da5f03
remove unused forcenew
ziyeqf 080ad91
Merge branch 'main' into tengzh/mn_sg
ziyeqf b13bf7f
refresh vendor
ziyeqf 61b130c
update schema
ziyeqf 613f517
Merge branch 'main' into tengzh/mn_sg
ziyeqf 89e141a
update code
ziyeqf 2d8cf00
update code
ziyeqf d9ef23f
Merge branch 'main' into tengzh/mn_sg
ziyeqf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
132 changes: 132 additions & 0 deletions
132
internal/services/mobilenetwork/mobile_network_sim_group_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/response" | ||
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" | ||
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity" | ||
"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/simgroup" | ||
"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 SimGroupDataSource struct{} | ||
|
||
var _ sdk.DataSource = SimGroupDataSource{} | ||
|
||
func (r SimGroupDataSource) ResourceType() string { | ||
return "azurerm_mobile_network_sim_group" | ||
} | ||
|
||
func (r SimGroupDataSource) ModelObject() interface{} { | ||
return &SimGroupModel{} | ||
} | ||
|
||
func (r SimGroupDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return simgroup.ValidateSimGroupID | ||
} | ||
|
||
func (r SimGroupDataSource) 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 SimGroupDataSource) Attributes() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
|
||
"encryption_key_url": { // needs UserAssignedIdentity | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"identity": commonschema.SystemOrUserAssignedIdentityComputed(), | ||
|
||
"location": commonschema.LocationComputed(), | ||
|
||
"tags": commonschema.TagsDataSource(), | ||
} | ||
} | ||
|
||
func (r SimGroupDataSource) Read() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 5 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
var metaModel SimGroupModel | ||
if err := metadata.Decode(&metaModel); err != nil { | ||
return fmt.Errorf("decoding: %+v", err) | ||
} | ||
|
||
client := metadata.Client.MobileNetwork.SIMGroupClient | ||
parsedMobileNetworkId, err := mobilenetwork.ParseMobileNetworkID(metaModel.MobileNetworkId) | ||
if err != nil { | ||
return fmt.Errorf("parsing `mobile_network_id`: %+v", err) | ||
} | ||
id := simgroup.NewSimGroupID(parsedMobileNetworkId.SubscriptionId, parsedMobileNetworkId.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) | ||
} | ||
|
||
if resp.Model == nil { | ||
return fmt.Errorf("retrieving %s: model was nil", id) | ||
} | ||
|
||
model := *resp.Model | ||
|
||
state := SimGroupModel{ | ||
Name: id.SimGroupName, | ||
MobileNetworkId: metaModel.MobileNetworkId, | ||
Location: location.Normalize(model.Location), | ||
} | ||
|
||
identityValue, err := identity.FlattenLegacySystemAndUserAssignedMap(model.Identity) | ||
if err != nil { | ||
return fmt.Errorf("flattening `identity`: %+v", err) | ||
} | ||
|
||
if err := metadata.ResourceData.Set("identity", identityValue); err != nil { | ||
return fmt.Errorf("setting `identity`: %+v", err) | ||
} | ||
|
||
properties := model.Properties | ||
|
||
if properties.EncryptionKey != nil && properties.EncryptionKey.KeyUrl != nil { | ||
state.EncryptionKeyUrl = *properties.EncryptionKey.KeyUrl | ||
} | ||
|
||
if properties.MobileNetwork != nil { | ||
state.MobileNetworkId = properties.MobileNetwork.Id | ||
} | ||
|
||
if model.Tags != nil { | ||
state.Tags = *model.Tags | ||
} | ||
|
||
metadata.SetID(id) | ||
|
||
return metadata.Encode(&state) | ||
}, | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
internal/services/mobilenetwork/mobile_network_sim_group_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,41 @@ | ||
package mobilenetwork_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
) | ||
|
||
type MobileNetworkSimGroupDataSource struct{} | ||
|
||
func TestAccMobileNetworkSimGroupDataSource_complete(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_mobile_network_sim_group", "test") | ||
// Limited regional availability for Mobile Network | ||
data.Locations.Primary = "eastus" | ||
|
||
d := MobileNetworkSimGroupDataSource{} | ||
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_network_id`).Exists(), | ||
check.That(data.ResourceName).Key(`encryption_key_url`).Exists(), | ||
check.That(data.ResourceName).Key("tags.%").HasValue("1"), | ||
), | ||
}, | ||
}) | ||
} | ||
|
||
func (r MobileNetworkSimGroupDataSource) complete(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
data "azurerm_mobile_network_sim_group" "test" { | ||
name = azurerm_mobile_network_sim_group.test.name | ||
mobile_network_id = azurerm_mobile_network.test.id | ||
} | ||
`, MobileNetworkSimGroupResource{}.complete(data)) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ziyeqf is there a Swagger bug for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just opened one Azure/azure-rest-api-specs#22634
and added comments to code on this PR #20474