diff --git a/internal/services/automation/automation_source_control.go b/internal/services/automation/automation_source_control.go index 2eb3d517b07f..b8bf3c16528a 100644 --- a/internal/services/automation/automation_source_control.go +++ b/internal/services/automation/automation_source_control.go @@ -7,6 +7,7 @@ import ( "github.com/Azure/azure-sdk-for-go/services/preview/automation/mgmt/2020-01-13-preview/automation" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -37,6 +38,15 @@ type SourceControlResource struct{} var _ sdk.Resource = (*SourceControlResource)(nil) +func (r SourceControlResource) StateUpgraders() sdk.StateUpgradeData { + return sdk.StateUpgradeData{ + SchemaVersion: 1, + Upgraders: map[int]pluginsdk.StateUpgrade{ + 0: migration.AutomationSourceControlV0ToV1{}, + }, + } +} + func (m SourceControlResource) Arguments() map[string]*pluginsdk.Schema { return map[string]*pluginsdk.Schema{ "automation_account_id": { diff --git a/internal/services/automation/automation_webhook.go b/internal/services/automation/automation_webhook.go index cdfc7fa70cd5..776eefab7937 100644 --- a/internal/services/automation/automation_webhook.go +++ b/internal/services/automation/automation_webhook.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -32,6 +33,11 @@ func resourceAutomationWebhook() *pluginsdk.Resource { return err }), + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.AutomationWebhookV0ToV1{}, + }), + Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(30 * time.Minute), Read: pluginsdk.DefaultTimeout(5 * time.Minute), diff --git a/internal/services/automation/migration/automation_source_control_migration_v0_to_v1.go b/internal/services/automation/migration/automation_source_control_migration_v0_to_v1.go new file mode 100644 index 000000000000..8befcbff5e84 --- /dev/null +++ b/internal/services/automation/migration/automation_source_control_migration_v0_to_v1.go @@ -0,0 +1,104 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type AutomationSourceControlV0ToV1 struct{} + +func (s AutomationSourceControlV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "automation_account_id": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "repository_url": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "branch": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "folder_path": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "automatic_sync": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "publish_runbook_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, + + "source_control_type": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "description": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "security": { + Type: pluginsdk.TypeList, + Required: true, + MaxItems: 1, + MinItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "token": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "refresh_token": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "token_type": { + Type: pluginsdk.TypeString, + Required: true, + }, + }, + }, + }, + } +} + +func (s AutomationSourceControlV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.SourceControlIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/automation/migration/automation_webhook_migration_v0_to_v1.go b/internal/services/automation/migration/automation_webhook_migration_v0_to_v1.go new file mode 100644 index 000000000000..18a4d298cc9b --- /dev/null +++ b/internal/services/automation/migration/automation_webhook_migration_v0_to_v1.go @@ -0,0 +1,85 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type AutomationWebhookV0ToV1 struct{} + +func (s AutomationWebhookV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "resource_group_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "automation_account_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "expiry_time": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, + + "runbook_name": { + Type: pluginsdk.TypeString, + Required: true, + }, + "run_on_worker_group": { + Type: pluginsdk.TypeString, + Optional: true, + }, + "parameters": { + Type: pluginsdk.TypeMap, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + "uri": { + Type: pluginsdk.TypeString, + ConfigMode: schema.SchemaConfigModeAttr, + Optional: true, + ForceNew: true, + Computed: true, + Sensitive: true, + }, + } +} + +func (s AutomationWebhookV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.WebhookIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/automation/parse/source_control.go b/internal/services/automation/parse/source_control.go index 733baa33f6c7..f70dd5eb6269 100644 --- a/internal/services/automation/parse/source_control.go +++ b/internal/services/automation/parse/source_control.go @@ -36,7 +36,7 @@ func (id SourceControlId) String() string { } func (id SourceControlId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automation/automationAccounts/%s/sourcecontrols/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automation/automationAccounts/%s/sourceControls/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.AutomationAccountName, id.Name) } @@ -63,7 +63,63 @@ func SourceControlID(input string) (*SourceControlId, error) { if resourceId.AutomationAccountName, err = id.PopSegment("automationAccounts"); err != nil { return nil, err } - if resourceId.Name, err = id.PopSegment("sourcecontrols"); err != nil { + if resourceId.Name, err = id.PopSegment("sourceControls"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} + +// SourceControlIDInsensitively parses an SourceControl ID into an SourceControlId struct, insensitively +// This should only be used to parse an ID for rewriting, the SourceControlID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func SourceControlIDInsensitively(input string) (*SourceControlId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := SourceControlId{ + 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") + } + + // find the correct casing for the 'automationAccounts' segment + automationAccountsKey := "automationAccounts" + for key := range id.Path { + if strings.EqualFold(key, automationAccountsKey) { + automationAccountsKey = key + break + } + } + if resourceId.AutomationAccountName, err = id.PopSegment(automationAccountsKey); err != nil { + return nil, err + } + + // find the correct casing for the 'sourceControls' segment + sourceControlsKey := "sourceControls" + for key := range id.Path { + if strings.EqualFold(key, sourceControlsKey) { + sourceControlsKey = key + break + } + } + if resourceId.Name, err = id.PopSegment(sourceControlsKey); err != nil { return nil, err } diff --git a/internal/services/automation/parse/source_control_test.go b/internal/services/automation/parse/source_control_test.go index 69a65162acd9..98f68d840340 100644 --- a/internal/services/automation/parse/source_control_test.go +++ b/internal/services/automation/parse/source_control_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = SourceControlId{} func TestSourceControlIDFormatter(t *testing.T) { actual := NewSourceControlID("12345678-1234-9876-4563-123456789012", "group1", "account1", "sample").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourcecontrols/sample" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourceControls/sample" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -75,13 +75,13 @@ func TestSourceControlID(t *testing.T) { { // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourcecontrols/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourceControls/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourcecontrols/sample", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourceControls/sample", Expected: &SourceControlId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "group1", @@ -126,3 +126,139 @@ func TestSourceControlID(t *testing.T) { } } } + +func TestSourceControlIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *SourceControlId + }{ + + { + // 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 AutomationAccountName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/", + Error: true, + }, + + { + // missing value for AutomationAccountName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/", + Error: true, + }, + + { + // missing Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/", + Error: true, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourceControls/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourceControls/sample", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "group1", + AutomationAccountName: "account1", + Name: "sample", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationaccounts/account1/sourcecontrols/sample", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "group1", + AutomationAccountName: "account1", + Name: "sample", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/AUTOMATIONACCOUNTS/account1/SOURCECONTROLS/sample", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "group1", + AutomationAccountName: "account1", + Name: "sample", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/AuToMaTiOnAcCoUnTs/account1/SoUrCeCoNtRoLs/sample", + Expected: &SourceControlId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "group1", + AutomationAccountName: "account1", + Name: "sample", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := SourceControlIDInsensitively(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.AutomationAccountName != v.Expected.AutomationAccountName { + t.Fatalf("Expected %q but got %q for AutomationAccountName", v.Expected.AutomationAccountName, actual.AutomationAccountName) + } + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + } +} diff --git a/internal/services/automation/parse/webhook.go b/internal/services/automation/parse/webhook.go index 251b688f152d..f08f59e383d5 100644 --- a/internal/services/automation/parse/webhook.go +++ b/internal/services/automation/parse/webhook.go @@ -36,7 +36,7 @@ func (id WebhookId) String() string { } func (id WebhookId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automation/automationAccounts/%s/webhooks/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Automation/automationAccounts/%s/webHooks/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.AutomationAccountName, id.Name) } @@ -63,7 +63,63 @@ func WebhookID(input string) (*WebhookId, error) { if resourceId.AutomationAccountName, err = id.PopSegment("automationAccounts"); err != nil { return nil, err } - if resourceId.Name, err = id.PopSegment("webhooks"); err != nil { + if resourceId.Name, err = id.PopSegment("webHooks"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} + +// WebhookIDInsensitively parses an Webhook ID into an WebhookId struct, insensitively +// This should only be used to parse an ID for rewriting, the WebhookID +// method should be used instead for validation etc. +// +// Whilst this may seem strange, this enables Terraform have consistent casing +// which works around issues in Core, whilst handling broken API responses. +func WebhookIDInsensitively(input string) (*WebhookId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, err + } + + resourceId := WebhookId{ + 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") + } + + // find the correct casing for the 'automationAccounts' segment + automationAccountsKey := "automationAccounts" + for key := range id.Path { + if strings.EqualFold(key, automationAccountsKey) { + automationAccountsKey = key + break + } + } + if resourceId.AutomationAccountName, err = id.PopSegment(automationAccountsKey); err != nil { + return nil, err + } + + // find the correct casing for the 'webHooks' segment + webHooksKey := "webHooks" + for key := range id.Path { + if strings.EqualFold(key, webHooksKey) { + webHooksKey = key + break + } + } + if resourceId.Name, err = id.PopSegment(webHooksKey); err != nil { return nil, err } diff --git a/internal/services/automation/parse/webhook_test.go b/internal/services/automation/parse/webhook_test.go index 4959d120b047..d78a0b0a1aae 100644 --- a/internal/services/automation/parse/webhook_test.go +++ b/internal/services/automation/parse/webhook_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = WebhookId{} func TestWebhookIDFormatter(t *testing.T) { actual := NewWebhookID("12345678-1234-9876-4563-123456789012", "group1", "account1", "webhook1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webhooks/webhook1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webHooks/webhook1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -75,13 +75,13 @@ func TestWebhookID(t *testing.T) { { // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webhooks/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webHooks/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webhooks/webhook1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webHooks/webhook1", Expected: &WebhookId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "group1", @@ -126,3 +126,139 @@ func TestWebhookID(t *testing.T) { } } } + +func TestWebhookIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *WebhookId + }{ + + { + // 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 AutomationAccountName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/", + Error: true, + }, + + { + // missing value for AutomationAccountName + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/", + Error: true, + }, + + { + // missing Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/", + Error: true, + }, + + { + // missing value for Name + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webHooks/", + Error: true, + }, + + { + // valid + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webHooks/webhook1", + Expected: &WebhookId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "group1", + AutomationAccountName: "account1", + Name: "webhook1", + }, + }, + + { + // lower-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationaccounts/account1/webhooks/webhook1", + Expected: &WebhookId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "group1", + AutomationAccountName: "account1", + Name: "webhook1", + }, + }, + + { + // upper-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/AUTOMATIONACCOUNTS/account1/WEBHOOKS/webhook1", + Expected: &WebhookId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "group1", + AutomationAccountName: "account1", + Name: "webhook1", + }, + }, + + { + // mixed-cased segment names + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/AuToMaTiOnAcCoUnTs/account1/WeBhOoKs/webhook1", + Expected: &WebhookId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroup: "group1", + AutomationAccountName: "account1", + Name: "webhook1", + }, + }, + } + + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := WebhookIDInsensitively(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.AutomationAccountName != v.Expected.AutomationAccountName { + t.Fatalf("Expected %q but got %q for AutomationAccountName", v.Expected.AutomationAccountName, actual.AutomationAccountName) + } + if actual.Name != v.Expected.Name { + t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) + } + } +} diff --git a/internal/services/automation/resourceids.go b/internal/services/automation/resourceids.go index 489bc0e1c03b..038b06f2cf7e 100644 --- a/internal/services/automation/resourceids.go +++ b/internal/services/automation/resourceids.go @@ -6,7 +6,7 @@ package automation //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Certificate -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/certificates/cert1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Credential -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/credentials/cred1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Schedule -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/schedules/schedule1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SourceControl -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourcecontrols/sample +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=SourceControl -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourceControls/sample -rewrite=true //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Module -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/modules/module1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=NodeConfiguration -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/nodeConfigurations/nodeconfig1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Runbook -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/runbooks/runbook1 @@ -14,5 +14,5 @@ package automation //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Configuration -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/configurations/config1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=JobSchedule -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/jobSchedules/schedule1 //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Variable -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/variables/variable1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Webhook -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webhooks/webhook1 +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Webhook -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webHooks/webhook1 -rewrite=true //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=Watcher -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/watchers/watcher1 diff --git a/internal/services/automation/validate/source_control_id_test.go b/internal/services/automation/validate/source_control_id_test.go index 0cb693a9007d..8f161d1dce33 100644 --- a/internal/services/automation/validate/source_control_id_test.go +++ b/internal/services/automation/validate/source_control_id_test.go @@ -60,13 +60,13 @@ func TestSourceControlID(t *testing.T) { { // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourcecontrols/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourceControls/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourcecontrols/sample", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourceControls/sample", Valid: true, }, diff --git a/internal/services/automation/validate/webhook_id_test.go b/internal/services/automation/validate/webhook_id_test.go index b987c62cb9b1..abbb61da502e 100644 --- a/internal/services/automation/validate/webhook_id_test.go +++ b/internal/services/automation/validate/webhook_id_test.go @@ -60,13 +60,13 @@ func TestWebhookID(t *testing.T) { { // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webhooks/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webHooks/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webhooks/webhook1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webHooks/webhook1", Valid: true, }, diff --git a/website/docs/r/automation_source_control.html.markdown b/website/docs/r/automation_source_control.html.markdown index 32bb83eec890..67a543f7ed16 100644 --- a/website/docs/r/automation_source_control.html.markdown +++ b/website/docs/r/automation_source_control.html.markdown @@ -84,5 +84,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Automations can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_automation_source_control.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourcecontrols/sc1 +terraform import azurerm_automation_source_control.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/sourceControls/sc1 ``` diff --git a/website/docs/r/automation_webhook.html.markdown b/website/docs/r/automation_webhook.html.markdown index 01f2e4914006..afd821a7570f 100644 --- a/website/docs/r/automation_webhook.html.markdown +++ b/website/docs/r/automation_webhook.html.markdown @@ -98,5 +98,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Automation Webhooks can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_automation_webhook.TestRunbook_webhook /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webhooks/TestRunbook_webhook +terraform import azurerm_automation_webhook.TestRunbook_webhook /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Automation/automationAccounts/account1/webHooks/TestRunbook_webhook ```