-
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.
- Loading branch information
Showing
89 changed files
with
4,606 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
internal/services/chaosstudio/chaos_studio_target_resource_create.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,82 @@ | ||
package chaosstudio | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
"github.com/hashicorp/go-azure-helpers/lang/response" | ||
"github.com/hashicorp/go-azure-helpers/resourcemanager/location" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/chaosstudio/2023-11-01/targets" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/chaosstudio/2023-11-01/targettypes" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
) | ||
|
||
func (r ChaosStudioTargetResource) Create() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
client := metadata.Client.ChaosStudio.V20231101.Targets | ||
targetTypesClient := metadata.Client.ChaosStudio.V20231101.TargetTypes | ||
subscriptionId := metadata.Client.Account.SubscriptionId | ||
|
||
var config ChaosStudioTargetResourceSchema | ||
|
||
if err := metadata.Decode(&config); err != nil { | ||
return fmt.Errorf("decoding: %+v", err) | ||
} | ||
|
||
locationId := targettypes.NewLocationID(subscriptionId, config.Location) | ||
resp, err := targetTypesClient.ListComplete(ctx, locationId, targettypes.DefaultListOperationOptions()) | ||
if err != nil { | ||
return fmt.Errorf("retrieving list of chaos target types: %+v", err) | ||
} | ||
|
||
// Validate name which needs to be of format [publisher]-[targetType] | ||
// Only certain target types are accepted, and they could vary by region | ||
targetTypes := map[string][]string{} | ||
nameIsValid := false | ||
for _, item := range resp.Items { | ||
if name := item.Name; name != nil { | ||
if strings.EqualFold(config.TargetType, *item.Name) { | ||
nameIsValid = true | ||
} | ||
targetTypes[*item.Name] = pointer.From(item.Properties.ResourceTypes) | ||
} | ||
} | ||
|
||
if !nameIsValid { | ||
return fmt.Errorf("%q is not a valid `target_type` for the region %s, must be one of %+v", config.TargetType, config.Location, targetTypes) | ||
} | ||
|
||
id := targets.NewScopedTargetID(config.TargetResourceId, config.TargetType) | ||
|
||
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 targets.Target | ||
|
||
// The API only accepts requests with an empty body for Properties | ||
props := struct{}{} | ||
|
||
payload.Location = pointer.To(location.Normalize(config.Location)) | ||
payload.Properties = pointer.To(props) | ||
|
||
if _, err := client.CreateOrUpdate(ctx, id, payload); err != nil { | ||
return fmt.Errorf("creating %s: %+v", id, err) | ||
} | ||
|
||
metadata.SetID(id) | ||
return nil | ||
}, | ||
Timeout: 30 * time.Minute, | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
internal/services/chaosstudio/chaos_studio_target_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,44 @@ | ||
package chaosstudio | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
var _ sdk.Resource = ChaosStudioTargetResource{} | ||
|
||
type ChaosStudioTargetResource struct{} | ||
|
||
type ChaosStudioTargetResourceSchema struct { | ||
Location string `tfschema:"location"` | ||
TargetType string `tfschema:"target_type"` | ||
TargetResourceId string `tfschema:"target_resource_id"` | ||
} | ||
|
||
func (r ChaosStudioTargetResource) ModelObject() interface{} { | ||
return nil | ||
} | ||
|
||
func (r ChaosStudioTargetResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return nil | ||
} | ||
|
||
func (r ChaosStudioTargetResource) ResourceType() string { | ||
return "" | ||
} | ||
|
||
func (r ChaosStudioTargetResource) Arguments() map[string]*pluginsdk.Schema { | ||
return nil | ||
} | ||
|
||
func (r ChaosStudioTargetResource) Attributes() map[string]*pluginsdk.Schema { | ||
return nil | ||
} | ||
|
||
func (r ChaosStudioTargetResource) Read() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{} | ||
} | ||
|
||
func (r ChaosStudioTargetResource) Delete() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{} | ||
} |
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,27 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
chaosstudioV20231101 "github.com/hashicorp/go-azure-sdk/resource-manager/chaosstudio/2023-11-01" | ||
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/common" | ||
) | ||
|
||
type AutoClient struct { | ||
V20231101 chaosstudioV20231101.Client | ||
} | ||
|
||
func NewClient(o *common.ClientOptions) (*AutoClient, error) { | ||
|
||
v20231101Client, err := chaosstudioV20231101.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) { | ||
o.Configure(c, o.Authorizers.ResourceManager) | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("building client for chaosstudio V20231101: %+v", err) | ||
} | ||
|
||
return &AutoClient{ | ||
V20231101: *v20231101Client, | ||
}, nil | ||
} |
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,33 @@ | ||
package chaosstudio | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
) | ||
|
||
type Registration struct { | ||
autoRegistration | ||
} | ||
|
||
// Name is the name of this Service | ||
func (r Registration) Name() string { | ||
return r.autoRegistration.Name() | ||
} | ||
|
||
// WebsiteCategories returns a list of categories which can be used for the sidebar | ||
func (r Registration) WebsiteCategories() []string { | ||
return r.autoRegistration.WebsiteCategories() | ||
} | ||
|
||
// DataSources returns a list of Data Sources supported by this Service | ||
func (r Registration) DataSources() []sdk.DataSource { | ||
dataSources := []sdk.DataSource{} | ||
dataSources = append(dataSources, r.autoRegistration.DataSources()...) | ||
return dataSources | ||
} | ||
|
||
// Resources returns a list of Resources supported by this Service | ||
func (r Registration) Resources() []sdk.Resource { | ||
resources := []sdk.Resource{} | ||
resources = append(resources, r.autoRegistration.Resources()...) | ||
return resources | ||
} |
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,30 @@ | ||
package chaosstudio | ||
|
||
// NOTE: this file is generated - manual changes will be overwritten. | ||
|
||
import "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
|
||
var _ sdk.TypedServiceRegistration = autoRegistration{} | ||
|
||
type autoRegistration struct { | ||
} | ||
|
||
func (autoRegistration) Name() string { | ||
return "ChaosStudio" | ||
} | ||
|
||
func (autoRegistration) DataSources() []sdk.DataSource { | ||
return []sdk.DataSource{} | ||
} | ||
|
||
func (autoRegistration) Resources() []sdk.Resource { | ||
return []sdk.Resource{ | ||
ChaosStudioTargetResource{}, | ||
} | ||
} | ||
|
||
func (autoRegistration) WebsiteCategories() []string { | ||
return []string{ | ||
"Chaos Studio", | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...orp/go-azure-sdk/resource-manager/chaosstudio/2023-11-01/capabilities/README.md
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
...com/hashicorp/go-azure-sdk/resource-manager/chaosstudio/2023-11-01/capabilities/client.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.