-
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.
New Resource: azurerm_security_center_assessment_metadata (#10124)
Currently, terraform doesn't support Security.AssessmentMetadata RP. So submitted this PR to implement it. --- PASS: TestAccSecurityCenterAssessmentMetadata_basic (66.90s) --- PASS: TestAccSecurityCenterAssessmentMetadata_complete (68.07s) --- PASS: TestAccSecurityCenterAssessmentMetadata_update (125.80s) The api in go sdk package: https://github.com/Azure/azure-sdk-for-go/blob/master/services/preview/security/mgmt/v3.0/security/assessmentsmetadata.go
- Loading branch information
Neil Ye
authored
Feb 22, 2021
1 parent
b1fef30
commit afe0f3d
Showing
11 changed files
with
751 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
61 changes: 61 additions & 0 deletions
61
azurerm/internal/services/securitycenter/parse/assessment_metadata.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,61 @@ | ||
package parse | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" | ||
) | ||
|
||
type AssessmentMetadataId struct { | ||
SubscriptionId string | ||
AssessmentMetadataName string | ||
} | ||
|
||
func NewAssessmentMetadataID(subscriptionId, assessmentMetadataName string) AssessmentMetadataId { | ||
return AssessmentMetadataId{ | ||
SubscriptionId: subscriptionId, | ||
AssessmentMetadataName: assessmentMetadataName, | ||
} | ||
} | ||
|
||
func (id AssessmentMetadataId) String() string { | ||
segments := []string{ | ||
fmt.Sprintf("Assessment Metadata Name %q", id.AssessmentMetadataName), | ||
} | ||
segmentsStr := strings.Join(segments, " / ") | ||
return fmt.Sprintf("%s: (%s)", "Assessment Metadata", segmentsStr) | ||
} | ||
|
||
func (id AssessmentMetadataId) ID() string { | ||
fmtString := "/subscriptions/%s/providers/Microsoft.Security/assessmentMetadata/%s" | ||
return fmt.Sprintf(fmtString, id.SubscriptionId, id.AssessmentMetadataName) | ||
} | ||
|
||
// AssessmentMetadataID parses a AssessmentMetadata ID into an AssessmentMetadataId struct | ||
func AssessmentMetadataID(input string) (*AssessmentMetadataId, error) { | ||
id, err := azure.ParseAzureResourceID(input) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resourceId := AssessmentMetadataId{ | ||
SubscriptionId: id.SubscriptionID, | ||
} | ||
|
||
if resourceId.SubscriptionId == "" { | ||
return nil, fmt.Errorf("ID was missing the 'subscriptions' element") | ||
} | ||
|
||
if resourceId.AssessmentMetadataName, err = id.PopSegment("assessmentMetadata"); err != nil { | ||
return nil, err | ||
} | ||
|
||
if err := id.ValidateNoEmptySegments(input); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &resourceId, nil | ||
} |
96 changes: 96 additions & 0 deletions
96
azurerm/internal/services/securitycenter/parse/assessment_metadata_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,96 @@ | ||
package parse | ||
|
||
// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/resourceid" | ||
) | ||
|
||
var _ resourceid.Formatter = AssessmentMetadataId{} | ||
|
||
func TestAssessmentMetadataIDFormatter(t *testing.T) { | ||
actual := NewAssessmentMetadataID("12345678-1234-9876-4563-123456789012", "metadata1").ID() | ||
expected := "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/assessmentMetadata/metadata1" | ||
if actual != expected { | ||
t.Fatalf("Expected %q but got %q", expected, actual) | ||
} | ||
} | ||
|
||
func TestAssessmentMetadataID(t *testing.T) { | ||
testData := []struct { | ||
Input string | ||
Error bool | ||
Expected *AssessmentMetadataId | ||
}{ | ||
|
||
{ | ||
// empty | ||
Input: "", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing SubscriptionId | ||
Input: "/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for SubscriptionId | ||
Input: "/subscriptions/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing AssessmentMetadataName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// missing value for AssessmentMetadataName | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/assessmentMetadata/", | ||
Error: true, | ||
}, | ||
|
||
{ | ||
// valid | ||
Input: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/assessmentMetadata/metadata1", | ||
Expected: &AssessmentMetadataId{ | ||
SubscriptionId: "12345678-1234-9876-4563-123456789012", | ||
AssessmentMetadataName: "metadata1", | ||
}, | ||
}, | ||
|
||
{ | ||
// upper-cased | ||
Input: "/SUBSCRIPTIONS/12345678-1234-9876-4563-123456789012/PROVIDERS/MICROSOFT.SECURITY/ASSESSMENTMETADATA/METADATA1", | ||
Error: true, | ||
}, | ||
} | ||
|
||
for _, v := range testData { | ||
t.Logf("[DEBUG] Testing %q", v.Input) | ||
|
||
actual, err := AssessmentMetadataID(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.AssessmentMetadataName != v.Expected.AssessmentMetadataName { | ||
t.Fatalf("Expected %q but got %q for AssessmentMetadataName", v.Expected.AssessmentMetadataName, actual.AssessmentMetadataName) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package securitycenter | ||
|
||
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=AssessmentMetadata -id=/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.Security/assessmentMetadata/metadata1 | ||
//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=IotSecuritySolution -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Security/IoTSecuritySolutions/solution1 |
Oops, something went wrong.