-
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_dev_center_gallery
#23760
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
189 changes: 189 additions & 0 deletions
189
internal/services/devcenter/dev_center_gallery_resource_gen.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,189 @@ | ||||||
package devcenter | ||||||
|
||||||
// NOTE: this file is generated - manual changes will be overwritten. | ||||||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||||||
// Licensed under the MIT License. See NOTICE.txt in the project root for license information. | ||||||
import ( | ||||||
"context" | ||||||
"fmt" | ||||||
"time" | ||||||
|
||||||
"github.com/hashicorp/go-azure-helpers/lang/response" | ||||||
"github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2023-04-01/galleries" | ||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||||||
) | ||||||
|
||||||
var _ sdk.Resource = DevCenterGalleryResource{} | ||||||
|
||||||
type DevCenterGalleryResource struct{} | ||||||
|
||||||
func (r DevCenterGalleryResource) ModelObject() interface{} { | ||||||
return &DevCenterGalleryResourceSchema{} | ||||||
} | ||||||
|
||||||
type DevCenterGalleryResourceSchema struct { | ||||||
DevCenterId string `tfschema:"dev_center_id"` | ||||||
GalleryResourceId string `tfschema:"gallery_resource_id"` | ||||||
Name string `tfschema:"name"` | ||||||
} | ||||||
|
||||||
func (r DevCenterGalleryResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||||||
return galleries.ValidateGalleryID | ||||||
} | ||||||
func (r DevCenterGalleryResource) ResourceType() string { | ||||||
return "azurerm_dev_center_gallery" | ||||||
} | ||||||
func (r DevCenterGalleryResource) Arguments() map[string]*pluginsdk.Schema { | ||||||
return map[string]*pluginsdk.Schema{ | ||||||
"dev_center_id": { | ||||||
ForceNew: true, | ||||||
Required: true, | ||||||
Type: pluginsdk.TypeString, | ||||||
}, | ||||||
"gallery_resource_id": { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed. |
||||||
ForceNew: true, | ||||||
Required: true, | ||||||
Type: pluginsdk.TypeString, | ||||||
}, | ||||||
"name": { | ||||||
ForceNew: true, | ||||||
Required: true, | ||||||
Type: pluginsdk.TypeString, | ||||||
}, | ||||||
} | ||||||
} | ||||||
func (r DevCenterGalleryResource) Attributes() map[string]*pluginsdk.Schema { | ||||||
return map[string]*pluginsdk.Schema{} | ||||||
} | ||||||
func (r DevCenterGalleryResource) Create() sdk.ResourceFunc { | ||||||
return sdk.ResourceFunc{ | ||||||
Timeout: 30 * time.Minute, | ||||||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||||||
client := metadata.Client.DevCenter.V20230401.Galleries | ||||||
|
||||||
var config DevCenterGalleryResourceSchema | ||||||
if err := metadata.Decode(&config); err != nil { | ||||||
return fmt.Errorf("decoding: %+v", err) | ||||||
} | ||||||
|
||||||
subscriptionId := metadata.Client.Account.SubscriptionId | ||||||
|
||||||
devCenterId, err := galleries.ParseDevCenterID(config.DevCenterId) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
id := galleries.NewGalleryID(subscriptionId, devCenterId.ResourceGroupName, devCenterId.DevCenterName, config.Name) | ||||||
|
||||||
existing, err := client.Get(ctx, id) | ||||||
if err != nil { | ||||||
if !response.WasNotFound(existing.HttpResponse) { | ||||||
return fmt.Errorf("checking for the presence of an existing %s: %+v", id, err) | ||||||
} | ||||||
} | ||||||
if !response.WasNotFound(existing.HttpResponse) { | ||||||
return metadata.ResourceRequiresImport(r.ResourceType(), id) | ||||||
} | ||||||
|
||||||
var payload galleries.Gallery | ||||||
if err := r.mapDevCenterGalleryResourceSchemaToGallery(config, &payload); err != nil { | ||||||
return fmt.Errorf("mapping schema model to sdk model: %+v", err) | ||||||
} | ||||||
|
||||||
if err := client.CreateOrUpdateThenPoll(ctx, id, payload); err != nil { | ||||||
return fmt.Errorf("creating %s: %+v", id, err) | ||||||
} | ||||||
|
||||||
metadata.SetID(id) | ||||||
return nil | ||||||
}, | ||||||
} | ||||||
} | ||||||
func (r DevCenterGalleryResource) Read() sdk.ResourceFunc { | ||||||
return sdk.ResourceFunc{ | ||||||
Timeout: 5 * time.Minute, | ||||||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||||||
client := metadata.Client.DevCenter.V20230401.Galleries | ||||||
schema := DevCenterGalleryResourceSchema{} | ||||||
|
||||||
id, err := galleries.ParseGalleryID(metadata.ResourceData.Id()) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
devCenterId := galleries.NewDevCenterID(id.SubscriptionId, id.ResourceGroupName, id.DevCenterName) | ||||||
|
||||||
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 model := resp.Model; model != nil { | ||||||
schema.DevCenterId = devCenterId.ID() | ||||||
schema.Name = id.GalleryName | ||||||
if err := r.mapGalleryToDevCenterGalleryResourceSchema(*model, &schema); err != nil { | ||||||
return fmt.Errorf("flattening model: %+v", err) | ||||||
} | ||||||
} | ||||||
|
||||||
return metadata.Encode(&schema) | ||||||
}, | ||||||
} | ||||||
} | ||||||
func (r DevCenterGalleryResource) Delete() sdk.ResourceFunc { | ||||||
return sdk.ResourceFunc{ | ||||||
Timeout: 30 * time.Minute, | ||||||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||||||
client := metadata.Client.DevCenter.V20230401.Galleries | ||||||
|
||||||
id, err := galleries.ParseGalleryID(metadata.ResourceData.Id()) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
if err := client.DeleteThenPoll(ctx, *id); err != nil { | ||||||
return fmt.Errorf("deleting %s: %+v", *id, err) | ||||||
} | ||||||
|
||||||
return nil | ||||||
}, | ||||||
} | ||||||
} | ||||||
|
||||||
func (r DevCenterGalleryResource) mapDevCenterGalleryResourceSchemaToGalleryProperties(input DevCenterGalleryResourceSchema, output *galleries.GalleryProperties) error { | ||||||
output.GalleryResourceId = input.GalleryResourceId | ||||||
return nil | ||||||
} | ||||||
|
||||||
func (r DevCenterGalleryResource) mapGalleryPropertiesToDevCenterGalleryResourceSchema(input galleries.GalleryProperties, output *DevCenterGalleryResourceSchema) error { | ||||||
output.GalleryResourceId = input.GalleryResourceId | ||||||
return nil | ||||||
} | ||||||
|
||||||
func (r DevCenterGalleryResource) mapDevCenterGalleryResourceSchemaToGallery(input DevCenterGalleryResourceSchema, output *galleries.Gallery) error { | ||||||
|
||||||
if output.Properties == nil { | ||||||
output.Properties = &galleries.GalleryProperties{} | ||||||
} | ||||||
if err := r.mapDevCenterGalleryResourceSchemaToGalleryProperties(input, output.Properties); err != nil { | ||||||
return fmt.Errorf("mapping Schema to SDK Field %q / Model %q: %+v", "GalleryProperties", "Properties", err) | ||||||
} | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
func (r DevCenterGalleryResource) mapGalleryToDevCenterGalleryResourceSchema(input galleries.Gallery, output *DevCenterGalleryResourceSchema) error { | ||||||
|
||||||
if input.Properties == nil { | ||||||
input.Properties = &galleries.GalleryProperties{} | ||||||
} | ||||||
if err := r.mapGalleryPropertiesToDevCenterGalleryResourceSchema(*input.Properties, output); err != nil { | ||||||
return fmt.Errorf("mapping SDK Field %q / Model %q to Schema: %+v", "GalleryProperties", "Properties", err) | ||||||
} | ||||||
|
||||||
return nil | ||||||
} |
200 changes: 200 additions & 0 deletions
200
internal/services/devcenter/dev_center_gallery_resource_gen_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,200 @@ | ||
package devcenter_test | ||
|
||
// NOTE: this file is generated - manual changes will be overwritten. | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See NOTICE.txt in the project root for license information. | ||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/devcenter/2023-04-01/galleries" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/utils" | ||
) | ||
|
||
type DevCenterGalleryTestResource struct{} | ||
|
||
func TestAccDevCenterGallery_basic(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_dev_center_gallery", "test") | ||
r := DevCenterGalleryTestResource{} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep(), | ||
}) | ||
} | ||
|
||
func TestAccDevCenterGallery_requiresImport(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_dev_center_gallery", "test") | ||
r := DevCenterGalleryTestResource{} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.RequiresImportErrorStep(r.requiresImport), | ||
}) | ||
} | ||
|
||
func TestAccDevCenterGallery_complete(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_dev_center_gallery", "test") | ||
r := DevCenterGalleryTestResource{} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.complete(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep(), | ||
}) | ||
} | ||
|
||
func TestAccDevCenterGallery_update(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_dev_center_gallery", "test") | ||
r := DevCenterGalleryTestResource{} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep(), | ||
{ | ||
Config: r.complete(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep(), | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep(), | ||
}) | ||
} | ||
func (r DevCenterGalleryTestResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { | ||
id, err := galleries.ParseGalleryID(state.ID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resp, err := clients.DevCenter.V20230401.Galleries.Get(ctx, *id) | ||
if err != nil { | ||
return nil, fmt.Errorf("reading %s: %+v", *id, err) | ||
} | ||
|
||
return utils.Bool(resp.Model != nil), nil | ||
} | ||
func (r DevCenterGalleryTestResource) basic(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
resource "azurerm_dev_center_gallery" "test" { | ||
dev_center_id = azurerm_dev_center.test.id | ||
gallery_resource_id = azurerm_shared_image_gallery.test.id | ||
name = "acctestdcg${var.random_string}" | ||
} | ||
`, r.template(data)) | ||
} | ||
|
||
func (r DevCenterGalleryTestResource) requiresImport(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
resource "azurerm_dev_center_gallery" "import" { | ||
dev_center_id = azurerm_dev_center_gallery.test.dev_center_id | ||
gallery_resource_id = azurerm_dev_center_gallery.test.gallery_resource_id | ||
name = azurerm_dev_center_gallery.test.name | ||
} | ||
`, r.basic(data)) | ||
} | ||
|
||
func (r DevCenterGalleryTestResource) complete(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
resource "azurerm_dev_center_gallery" "test" { | ||
dev_center_id = azurerm_dev_center.test.id | ||
gallery_resource_id = azurerm_shared_image_gallery.test.id | ||
name = "acctestdcg${var.random_string}" | ||
} | ||
`, r.template(data)) | ||
} | ||
|
||
func (r DevCenterGalleryTestResource) template(data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
variable "primary_location" { | ||
default = %q | ||
} | ||
variable "random_integer" { | ||
default = %d | ||
} | ||
variable "random_string" { | ||
default = %q | ||
} | ||
|
||
resource "azurerm_dev_center" "test" { | ||
name = "acctestdc-${var.random_string}" | ||
resource_group_name = azurerm_resource_group.test.name | ||
location = azurerm_resource_group.test.location | ||
|
||
identity { | ||
type = "UserAssigned" | ||
identity_ids = [azurerm_user_assigned_identity.test.id] | ||
} | ||
} | ||
|
||
|
||
resource "azurerm_resource_group" "test" { | ||
name = "acctestrg-${var.random_integer}" | ||
location = var.primary_location | ||
} | ||
|
||
resource "azurerm_user_assigned_identity" "test" { | ||
name = "acctestuami-${var.random_string}" | ||
location = azurerm_resource_group.test.location | ||
resource_group_name = azurerm_resource_group.test.name | ||
} | ||
|
||
|
||
resource "azurerm_shared_image_gallery" "test" { | ||
name = "acctestsig${var.random_string}" | ||
location = azurerm_resource_group.test.location | ||
resource_group_name = azurerm_resource_group.test.name | ||
} | ||
|
||
|
||
resource "azurerm_role_assignment" "test" { | ||
scope = azurerm_shared_image_gallery.test.id | ||
role_definition_name = "Owner" | ||
principal_id = azurerm_user_assigned_identity.test.principal_id | ||
} | ||
`, data.Locations.Primary, data.RandomInteger, data.RandomString) | ||
} |
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
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.
Like we did for the generated resource let's rename this to
shared_gallery_id