Skip to content
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

New Resource: azurerm_security_center_assessment_metadata #10124

Merged
merged 14 commits into from
Feb 22, 2021

Conversation

neil-yechenwei
Copy link
Contributor

@neil-yechenwei neil-yechenwei commented Jan 11, 2021

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

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some test failing:

------- Stdout: -------
=== RUN   TestAccSecurityCenterAssessmentMetadata_complete
=== PAUSE TestAccSecurityCenterAssessmentMetadata_complete
=== CONT  TestAccSecurityCenterAssessmentMetadata_complete
    testing.go:745: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.
        
        Error: Check failed: "azurerm_security_center_assessment_metadata.test" still exists
        
        State: <no state>
--- FAIL: TestAccSecurityCenterAssessmentMetadata_complete (43.00s)
FAIL

------- Stdout: -------
=== RUN   TestAccSecurityCenterAssessmentMetadata_update
=== PAUSE TestAccSecurityCenterAssessmentMetadata_update
=== CONT  TestAccSecurityCenterAssessmentMetadata_update
    testing.go:684: Step 0 error: Check failed: Check 1/1 error: "azurerm_security_center_assessment_metadata.test" did not exist
--- FAIL: TestAccSecurityCenterAssessmentMetadata_update (22.06s)
FAIL

@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Jan 14, 2021

@katbyte , After rerun, seems all test cases passed on my local. Maybe rerun or clean-up test env can resolve your problem?

$ make testacc TEST=./azurerm/internal/services/securitycenter/ TESTARGS="-parallel 11 -test.run=TestAccSecurityCenterAssessmentMetadata_"
==> Checking that code complies with gofmt requirements...
==> Checking that Custom Timeouts are used...
==> Checking that acceptance test packages are used...
TF_ACC=1 go test ./azurerm/internal/services/securitycenter/ -v -parallel 11 -test.run=TestAccSecurityCenterAssessmentMetadata_ -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN TestAccSecurityCenterAssessmentMetadata_basic
=== PAUSE TestAccSecurityCenterAssessmentMetadata_basic
=== RUN TestAccSecurityCenterAssessmentMetadata_requiresImport
=== PAUSE TestAccSecurityCenterAssessmentMetadata_requiresImport
=== RUN TestAccSecurityCenterAssessmentMetadata_complete
=== PAUSE TestAccSecurityCenterAssessmentMetadata_complete
=== RUN TestAccSecurityCenterAssessmentMetadata_update
=== PAUSE TestAccSecurityCenterAssessmentMetadata_update
=== CONT TestAccSecurityCenterAssessmentMetadata_basic
=== CONT TestAccSecurityCenterAssessmentMetadata_update
=== CONT TestAccSecurityCenterAssessmentMetadata_complete
=== CONT TestAccSecurityCenterAssessmentMetadata_requiresImport
--- PASS: TestAccSecurityCenterAssessmentMetadata_basic (64.15s)
--- PASS: TestAccSecurityCenterAssessmentMetadata_complete (65.74s)
--- PASS: TestAccSecurityCenterAssessmentMetadata_requiresImport (79.13s)
--- PASS: TestAccSecurityCenterAssessmentMetadata_update (116.31s)
PASS
ok github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/securitycenter 121.073s

@neil-yechenwei
Copy link
Contributor Author

@katbyte , may I ask whether the test cases are passed from your side?

@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Jan 27, 2021

@katbyte , Seems test case can pass after rerun on CI.

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @neil-yechenwei

Thanks for this PR - I've taken a look through and left some comments inline - since several of these fields can't be (or don't make sense to be, in the case of the uuid) user specified, it'd be worth rethinking the design here (since we can generate/default values for these as necessary) - but if we can fix those up then we should be able to take another look.

Thanks!

Required: true,
ForceNew: true,
ValidateFunc: validation.IsUUID,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless this UUID can represent a built-in value - to be honest there's not much point making this user configurable - instead we'd be better to make this a Computed-only field and generate a default value in the Create function here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

}
}

func resourceArmSecurityCenterAssessmentMetadataCreateUpdate(d *schema.ResourceData, meta interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need to split this Create and Update function here to be able to use ignore_changes on these fields (since d.GetOk won't capture that) - which also makes the uuid logic easier here if we're generating them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


* `name` - (Required) The GUID as name which should be used for this Security Center Assessment Metadata. Changing this forces a new Security Center Assessment Metadata to be created.

* `assessment_type` - (Required) The type of the Security Center Assessment which can be specified by user. Possible value is `CustomerManaged`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is the only possible value, there's no point exposing this field - we may as well default it

Copy link
Contributor Author

@neil-yechenwei neil-yechenwei Jan 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


* `threats` - (Optional) A list of the threat impacts for the Security Center Assessment. Possible values are `AccountBreach`, `DataExfiltration`, `DataSpillage`, `DenialOfService`, `ElevationOfPrivilege`, `MaliciousInsider`, `MissingCoverage` and `ThreatResistance`.

* `user_impact` - (Optional) The user impact of the Security Center Assessment. Possible values are `Low`, `Moderate` and `High`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a default value for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on previous testing, there is no default value when this property isn't specified.

@neil-yechenwei
Copy link
Contributor Author

neil-yechenwei commented Feb 2, 2021

@tombuildsstuff , thanks for your comments. I've updated code and provide my idea. Please have an another look.

@katbyte katbyte added this to the v2.49.0 milestone Feb 22, 2021
Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @neil-yechenwei - this LGTM 👍

@katbyte katbyte merged commit afe0f3d into hashicorp:master Feb 22, 2021
katbyte added a commit that referenced this pull request Feb 22, 2021
@ghost
Copy link

ghost commented Feb 26, 2021

This has been released in version 2.49.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.49.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Mar 25, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants