-
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
azurerm_app_service_certificate_order
- fix the incorrect ID issue
#25428
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 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
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
166 changes: 166 additions & 0 deletions
166
internal/services/web/migration/app_service_certificate_order.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,166 @@ | ||
package migration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/web/parse" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
var _ pluginsdk.StateUpgrade = AppServiceCertificateOrderResourceV0ToV1{} | ||
|
||
type AppServiceCertificateOrderResourceV0ToV1 struct{} | ||
|
||
func (AppServiceCertificateOrderResourceV0ToV1) Schema() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"location": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"resource_group_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"auto_renew": { | ||
Type: pluginsdk.TypeBool, | ||
Default: true, | ||
Optional: true, | ||
}, | ||
|
||
"certificates": { | ||
Type: pluginsdk.TypeList, | ||
Computed: true, | ||
Elem: &pluginsdk.Resource{ | ||
Schema: map[string]*pluginsdk.Schema{ | ||
"certificate_name": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"key_vault_id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"key_vault_secret_name": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"provisioning_state": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
||
"csr": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"distinguished_name": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"key_size": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Default: 2048, | ||
}, | ||
|
||
"product_type": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Default: "Standard", | ||
}, | ||
|
||
"validity_in_years": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
Default: 1, | ||
}, | ||
|
||
"domain_verification_token": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"status": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"expiration_time": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"is_private_key_external": { | ||
Type: pluginsdk.TypeBool, | ||
Computed: true, | ||
}, | ||
|
||
"app_service_certificate_not_renewable_reasons": { | ||
Type: pluginsdk.TypeList, | ||
Computed: true, | ||
Elem: &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeString, | ||
}, | ||
}, | ||
|
||
"signed_certificate_thumbprint": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"root_thumbprint": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"intermediate_thumbprint": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tags": { | ||
Type: pluginsdk.TypeMap, | ||
Optional: true, | ||
Elem: &pluginsdk.Schema{ | ||
Type: pluginsdk.TypeString, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (AppServiceCertificateOrderResourceV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { | ||
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
oldIdRaw := rawState["id"].(string) | ||
oldId, err := parse.CertificateOrderOldID(oldIdRaw) | ||
if err != nil { | ||
return rawState, fmt.Errorf("parsing ID %q to upgrade: %+v", oldIdRaw, err) | ||
} | ||
|
||
appServiceCertOrderId := parse.NewCertificateOrderID(oldId.SubscriptionId, oldId.ResourceGroup, oldId.CertificateOrderName) | ||
newId := appServiceCertOrderId.ID() | ||
|
||
rawState["id"] = newId | ||
return rawState, 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
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,72 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package parse | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" | ||
) | ||
|
||
type CertificateOrderOldId struct { | ||
SubscriptionId string | ||
ResourceGroup string | ||
CertificateOrderName string | ||
} | ||
|
||
func NewCertificateOrderOldID(subscriptionId, resourceGroup, certificateOrderName string) CertificateOrderOldId { | ||
return CertificateOrderOldId{ | ||
SubscriptionId: subscriptionId, | ||
ResourceGroup: resourceGroup, | ||
CertificateOrderName: certificateOrderName, | ||
} | ||
} | ||
|
||
func (id CertificateOrderOldId) String() string { | ||
segments := []string{ | ||
fmt.Sprintf("Certificate Order Name %q", id.CertificateOrderName), | ||
fmt.Sprintf("Resource Group %q", id.ResourceGroup), | ||
} | ||
segmentsStr := strings.Join(segments, " / ") | ||
return fmt.Sprintf("%s: (%s)", "Certificate Order Old", segmentsStr) | ||
} | ||
|
||
func (id CertificateOrderOldId) ID() string { | ||
fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/certificateOrders/%s" | ||
return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.CertificateOrderName) | ||
} | ||
|
||
// CertificateOrderOldID parses a CertificateOrderOld ID into an CertificateOrderOldId struct | ||
func CertificateOrderOldID(input string) (*CertificateOrderOldId, error) { | ||
id, err := resourceids.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing %q as an CertificateOrderOld ID: %+v", input, err) | ||
} | ||
|
||
resourceId := CertificateOrderOldId{ | ||
SubscriptionId: id.SubscriptionID, | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if resourceId.SubscriptionId == "" { | ||
return nil, fmt.Errorf("ID was missing the 'subscriptions' element") | ||
} | ||
|
||
if resourceId.ResourceGroup == "" { | ||
return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") | ||
} | ||
|
||
if resourceId.CertificateOrderName, err = id.PopSegment("certificateOrders"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &resourceId, nil | ||
} |
115 changes: 115 additions & 0 deletions
115
internal/services/web/parse/certificate_order_old_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,115 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package parse | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" | ||
) | ||
|
||
var _ resourceids.Id = CertificateOrderOldId{} | ||
|
||
func TestCertificateOrderOldIDFormatter(t *testing.T) { | ||
actual := NewCertificateOrderOldID("12345678-1234-9876-4563-123456789012", "resGroup1", "order1").ID() | ||
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/certificateOrders/order1" | ||
if actual != expected { | ||
t.Fatalf("Expected %q but got %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestCertificateOrderOldID(t *testing.T) { | ||
testData := []struct { | ||
Input string | ||
Error bool | ||
Expected *CertificateOrderOldId | ||
}{ | ||
|
||
{ | ||
// empty | ||
Input: "", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing SubscriptionId | ||
Input: "/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for SubscriptionId | ||
Input: "/subscriptions/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing ResourceGroup | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for ResourceGroup | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing CertificateOrderName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for CertificateOrderName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/certificateOrders/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// valid | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Web/certificateOrders/order1", | ||
Expected: &CertificateOrderOldId{ | ||
SubscriptionId: "12345678-1234-9876-4563-123456789012", | ||
ResourceGroup: "resGroup1", | ||
CertificateOrderName: "order1", | ||
}, | ||
}, | ||
|
||
{ | ||
// upper-cased | ||
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/RESOURCEGROUPS/RESGROUP1/PROVIDERS/MICROSOFT.WEB/CERTIFICATEORDERS/ORDER1", | ||
Error: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Input) | ||
|
||
actual, err := CertificateOrderOldID(v.Input) | ||
if err != nil { | ||
if v.Error { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expect a value but got an error: %s", err) | ||
} | ||
if v.Error { | ||
t.Fatal("Expect an error but didn't get one") | ||
} | ||
|
||
if actual.SubscriptionId != v.Expected.SubscriptionId { | ||
t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) | ||
} | ||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for ResourceGroup", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
if actual.CertificateOrderName != v.Expected.CertificateOrderName { | ||
t.Fatalf("Expected %q but got %q for CertificateOrderName", v.Expected.CertificateOrderName, actual.CertificateOrderName) | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
We have a guide on state migrations in the contributor docs which explains which attributes are necessary and which can be omitted in the schema (point 3.) Can you please update the schema here and remove attributes that are unnecessary e.g.
ForceNew
,Default
etc.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.
removed the unnecessary fields. As for the docs, the ID was formatted in the correct way:
terraform import azurerm_app_service_certificate_order.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/Microsoft.CertificateRegistration/certificateOrders/certificateorder1
https://github.com/hashicorp/terraform-provider-azurerm/blob/main/website/docs/r/app_service_certificate_order.html.markdown?plain=1#L107