-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azurerm_trusted_signing_account
- new resource support (#27720)
* `azurerm_trusted_signing_account` - new resource support * make generate * update per comments * update per comments * update code * update typo and code pattern * normalize location
- Loading branch information
Showing
51 changed files
with
2,802 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
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" | ||
|
||
codesigning_v2024_09_30_preview "github.com/hashicorp/go-azure-sdk/resource-manager/codesigning/2024-09-30-preview" | ||
|
||
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/common" | ||
) | ||
|
||
type Client struct { | ||
Client codesigning_v2024_09_30_preview.Client | ||
} | ||
|
||
func NewClient(o *common.ClientOptions) (*Client, error) { | ||
V20240930previewClient, err := codesigning_v2024_09_30_preview.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) { | ||
o.Configure(c, o.Authorizers.ResourceManager) | ||
}) | ||
if err != nil { | ||
return nil, fmt.Errorf("building client for codesigning v20240930preview: %+v", err) | ||
} | ||
|
||
return &Client{ | ||
Client: *V20240930previewClient, | ||
}, 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,40 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package codesigning | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
) | ||
|
||
type Registration struct{} | ||
|
||
var _ sdk.TypedServiceRegistration = Registration{} | ||
|
||
func (r Registration) AssociatedGitHubLabel() string { | ||
return "service/trustedsigning" | ||
} | ||
|
||
// Name is the name of this Service | ||
func (r Registration) Name() string { | ||
return "Trusted Signing" | ||
} | ||
|
||
// WebsiteCategories returns a list of categories which can be used for the sidebar | ||
func (r Registration) WebsiteCategories() []string { | ||
return []string{ | ||
"Trusted Signing", | ||
} | ||
} | ||
|
||
// DataSources returns a list of Data Sources supported by this Service | ||
func (r Registration) DataSources() []sdk.DataSource { | ||
return []sdk.DataSource{} | ||
} | ||
|
||
// Resources returns a list of Resources supported by this Service | ||
func (r Registration) Resources() []sdk.Resource { | ||
return []sdk.Resource{ | ||
TrustedSigningAccountResource{}, | ||
} | ||
} |
222 changes: 222 additions & 0 deletions
222
internal/services/codesigning/trusted_signing_account_resource.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,222 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package codesigning | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"regexp" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
"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/codesigning/2024-09-30-preview/codesigningaccounts" | ||
"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 TrustedSigningAccountModel struct { | ||
Name string `tfschema:"name"` | ||
Location string `tfschema:"location"` | ||
ResourceGroupName string `tfschema:"resource_group_name"` | ||
AccountUri string `tfschema:"account_uri"` | ||
SkuName string `tfschema:"sku_name"` | ||
Tags map[string]string `tfschema:"tags"` | ||
} | ||
|
||
type TrustedSigningAccountResource struct{} | ||
|
||
var _ sdk.Resource = (*TrustedSigningAccountResource)(nil) | ||
|
||
func (m TrustedSigningAccountResource) Arguments() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: validation.All( | ||
validation.StringLenBetween(3, 24), | ||
validation.StringMatch( | ||
regexp.MustCompile("^[A-Za-z][A-Za-z0-9]*(?:-[A-Za-z0-9]+)*$"), | ||
"An account's name must be between 3-24 alphanumeric characters. The name must begin with a letter, end with a letter or digit, and not contain consecutive hyphens.", | ||
), | ||
), | ||
}, | ||
|
||
"location": commonschema.Location(), | ||
|
||
"resource_group_name": commonschema.ResourceGroupName(), | ||
|
||
"sku_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ValidateFunc: validation.StringInSlice( | ||
codesigningaccounts.PossibleValuesForSkuName(), | ||
false), | ||
}, | ||
|
||
"tags": commonschema.Tags(), | ||
} | ||
} | ||
|
||
func (m TrustedSigningAccountResource) Attributes() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"account_uri": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
} | ||
} | ||
|
||
func (m TrustedSigningAccountResource) ModelObject() interface{} { | ||
return &TrustedSigningAccountModel{} | ||
} | ||
|
||
func (m TrustedSigningAccountResource) ResourceType() string { | ||
return "azurerm_trusted_signing_account" | ||
} | ||
|
||
func (m TrustedSigningAccountResource) Create() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 30 * time.Minute, | ||
Func: func(ctx context.Context, meta sdk.ResourceMetaData) error { | ||
client := meta.Client.CodeSigning.Client.CodeSigningAccounts | ||
|
||
var model TrustedSigningAccountModel | ||
if err := meta.Decode(&model); err != nil { | ||
return fmt.Errorf("decoding: %+v", err) | ||
} | ||
|
||
subscriptionID := meta.Client.Account.SubscriptionId | ||
id := codesigningaccounts.NewCodeSigningAccountID(subscriptionID, model.ResourceGroupName, model.Name) | ||
existing, err := client.Get(ctx, id) | ||
if !response.WasNotFound(existing.HttpResponse) { | ||
if err != nil { | ||
return fmt.Errorf("retrieving %s: %v", id, err) | ||
} | ||
return meta.ResourceRequiresImport(m.ResourceType(), id) | ||
} | ||
|
||
req := codesigningaccounts.CodeSigningAccount{ | ||
Name: &model.Name, | ||
Location: location.Normalize(model.Location), | ||
Tags: &model.Tags, | ||
Properties: &codesigningaccounts.CodeSigningAccountProperties{ | ||
Sku: &codesigningaccounts.AccountSku{ | ||
Name: codesigningaccounts.SkuName(model.SkuName), | ||
}, | ||
}, | ||
} | ||
|
||
err = client.CreateThenPoll(ctx, id, req) | ||
if err != nil { | ||
return fmt.Errorf("creating %s: %v", id, err) | ||
} | ||
|
||
meta.SetID(id) | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func (m TrustedSigningAccountResource) Read() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 5 * time.Minute, | ||
Func: func(ctx context.Context, meta sdk.ResourceMetaData) error { | ||
client := meta.Client.CodeSigning.Client.CodeSigningAccounts | ||
|
||
id, err := codesigningaccounts.ParseCodeSigningAccountID(meta.ResourceData.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
result, err := client.Get(ctx, *id) | ||
if err != nil { | ||
return fmt.Errorf("retrieving %s: %+v", id, err) | ||
} | ||
|
||
output := TrustedSigningAccountModel{ | ||
Name: id.CodeSigningAccountName, | ||
ResourceGroupName: id.ResourceGroupName, | ||
} | ||
|
||
if model := result.Model; model != nil { | ||
output.Location = location.Normalize(model.Location) | ||
output.Tags = pointer.From(model.Tags) | ||
|
||
if prop := model.Properties; prop != nil { | ||
output.AccountUri = pointer.From(prop.AccountUri) | ||
if sku := prop.Sku; sku != nil { | ||
output.SkuName = string(sku.Name) | ||
} | ||
} | ||
} | ||
|
||
return meta.Encode(&output) | ||
}, | ||
} | ||
} | ||
|
||
func (m TrustedSigningAccountResource) Update() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 10 * time.Minute, | ||
Func: func(ctx context.Context, meta sdk.ResourceMetaData) (err error) { | ||
client := meta.Client.CodeSigning.Client.CodeSigningAccounts | ||
id, err := codesigningaccounts.ParseCodeSigningAccountID(meta.ResourceData.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
var model TrustedSigningAccountModel | ||
if err = meta.Decode(&model); err != nil { | ||
return fmt.Errorf("decoding: %+v", err) | ||
} | ||
|
||
var patch codesigningaccounts.CodeSigningAccountPatch | ||
if meta.ResourceData.HasChange("sku_name") { | ||
patch.Properties = pointer.To(codesigningaccounts.CodeSigningAccountPatchProperties{ | ||
Sku: pointer.To(codesigningaccounts.AccountSkuPatch{ | ||
Name: pointer.To(codesigningaccounts.SkuName(model.SkuName)), | ||
}), | ||
}) | ||
} | ||
if meta.ResourceData.HasChange("tags") { | ||
patch.Tags = pointer.To(model.Tags) | ||
} | ||
|
||
if err = client.UpdateThenPoll(ctx, *id, patch); err != nil { | ||
return fmt.Errorf("updating %s: %v", id, err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func (m TrustedSigningAccountResource) Delete() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 10 * time.Minute, | ||
Func: func(ctx context.Context, meta sdk.ResourceMetaData) error { | ||
client := meta.Client.CodeSigning.Client.CodeSigningAccounts | ||
|
||
id, err := codesigningaccounts.ParseCodeSigningAccountID(meta.ResourceData.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
meta.Logger.Infof("deleting %s", id) | ||
|
||
if _, err = client.Delete(ctx, *id); err != nil { | ||
return fmt.Errorf("deleting %s: %v", id, err) | ||
} | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func (m TrustedSigningAccountResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return codesigningaccounts.ValidateCodeSigningAccountID | ||
} |
Oops, something went wrong.