-
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_api_management_diagnostic
- support required property `api_…
…management_logger_id` (#6682) fix #6619 This will be a breaking change for it adds a required field "logger_id" === RUN TestAccAzureRMApiManagementDiagnostic_basic === PAUSE TestAccAzureRMApiManagementDiagnostic_basic === CONT TestAccAzureRMApiManagementDiagnostic_basic --- PASS: TestAccAzureRMApiManagementDiagnostic_basic (2498.17s) === RUN TestAccAzureRMApiManagementDiagnostic_update === PAUSE TestAccAzureRMApiManagementDiagnostic_update === CONT TestAccAzureRMApiManagementDiagnostic_update --- PASS: TestAccAzureRMApiManagementDiagnostic_update (2566.13s) === RUN TestAccAzureRMApiManagementDiagnostic_requiresImport === PAUSE TestAccAzureRMApiManagementDiagnostic_requiresImport === CONT TestAccAzureRMApiManagementDiagnostic_requiresImport --- PASS: TestAccAzureRMApiManagementDiagnostic_requiresImport (2330.79s) PASS (also fixes #6104)
- Loading branch information
Showing
7 changed files
with
424 additions
and
54 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
69 changes: 69 additions & 0 deletions
69
azurerm/internal/services/apimanagement/parse/apimanagement.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,69 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type ApiManagementLoggerId struct { | ||
ResourceGroup string | ||
ServiceName string | ||
Name string | ||
} | ||
|
||
func ApiManagementLoggerID(input string) (*ApiManagementLoggerId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing Api Management Logger ID %q: %+v", input, err) | ||
} | ||
|
||
logger := ApiManagementLoggerId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if logger.ServiceName, err = id.PopSegment("service"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if logger.Name, err = id.PopSegment("loggers"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &logger, nil | ||
} | ||
|
||
type ApiManagementDiagnosticId struct { | ||
ResourceGroup string | ||
ServiceName string | ||
Name string | ||
} | ||
|
||
func ApiManagementDiagnosticID(input string) (*ApiManagementDiagnosticId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing Api Management Diagnostic ID %q: %+v", input, err) | ||
} | ||
|
||
diagnostic := ApiManagementDiagnosticId{ | ||
ResourceGroup: id.ResourceGroup, | ||
} | ||
|
||
if diagnostic.ServiceName, err = id.PopSegment("service"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if diagnostic.Name, err = id.PopSegment("diagnostics"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &diagnostic, nil | ||
} |
169 changes: 169 additions & 0 deletions
169
azurerm/internal/services/apimanagement/parse/apimanagement_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,169 @@ | ||
package parse | ||
|
||
import "testing" | ||
|
||
func TestApiManagementLoggerID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *ApiManagementLoggerId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Service Name", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Logger", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Logger Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/loggers", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Logger ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/loggers/logger1", | ||
Expected: &ApiManagementLoggerId{ | ||
Name: "logger1", | ||
ServiceName: "service1", | ||
ResourceGroup: "resGroup1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong Casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/Loggers/logger1", | ||
Expected: nil, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := ApiManagementLoggerID(v.Input) | ||
if err != nil { | ||
if v.Expected == nil { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.Name != v.Expected.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) | ||
} | ||
|
||
if actual.ServiceName != v.Expected.ServiceName { | ||
t.Fatalf("Expected %q but got %q for Service Name", v.Expected.Name, actual.Name) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
} | ||
} | ||
|
||
func TestApiManagementDiagnosticID(t *testing.T) { | ||
testData := []struct { | ||
Name string | ||
Input string | ||
Expected *ApiManagementDiagnosticId | ||
}{ | ||
{ | ||
Name: "Empty", | ||
Input: "", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Segment", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "No Resource Groups Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Resource Group ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/foo/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Service Name", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Diagnostic", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Missing Diagnostic Value", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/diagnostics", | ||
Expected: nil, | ||
}, | ||
{ | ||
Name: "Diagnostic ID", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/diagnostics/diagnostic1", | ||
Expected: &ApiManagementDiagnosticId{ | ||
Name: "diagnostic1", | ||
ServiceName: "service1", | ||
ResourceGroup: "resGroup1", | ||
}, | ||
}, | ||
{ | ||
Name: "Wrong Casing", | ||
Input: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.ApiManagement/service/service1/Diagnostics/diagnostic1", | ||
Expected: nil, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Name) | ||
|
||
actual, err := ApiManagementDiagnosticID(v.Input) | ||
if err != nil { | ||
if v.Expected == nil { | ||
continue | ||
} | ||
|
||
t.Fatalf("Expected a value but got an error: %s", err) | ||
} | ||
|
||
if actual.Name != v.Expected.Name { | ||
t.Fatalf("Expected %q but got %q for Name", v.Expected.Name, actual.Name) | ||
} | ||
|
||
if actual.ServiceName != v.Expected.ServiceName { | ||
t.Fatalf("Expected %q but got %q for Service Name", v.Expected.Name, actual.Name) | ||
} | ||
|
||
if actual.ResourceGroup != v.Expected.ResourceGroup { | ||
t.Fatalf("Expected %q but got %q for Resource Group", v.Expected.ResourceGroup, actual.ResourceGroup) | ||
} | ||
} | ||
} |
Oops, something went wrong.