-
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_app_service_certificate_order
- fix the incorrect ID issue (#…
…25428) * fix the incorrect app service certificate order issue * remove unnecessary fields for state migration
- Loading branch information
Showing
10 changed files
with
469 additions
and
11 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
159 changes: 159 additions & 0 deletions
159
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,159 @@ | ||
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, | ||
}, | ||
|
||
"location": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"resource_group_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"auto_renew": { | ||
Type: pluginsdk.TypeBool, | ||
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, | ||
}, | ||
|
||
"product_type": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"validity_in_years": { | ||
Type: pluginsdk.TypeInt, | ||
Optional: true, | ||
}, | ||
|
||
"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.