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_policy_set_definition #2535

Merged

Conversation

olohmann
Copy link
Contributor

This PR adds support for a new resource: Policy Set Definitions (aka Policy Initiatives).

Addresses issue #2193

Test Results:

> $ make testacc TESTARGS='-run=TestAccAzureRMPolicySetDefinition'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccAzureRMPolicySetDefinition -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
?   	github.com/terraform-providers/terraform-provider-azurerm	[no test files]
=== RUN   TestAccAzureRMPolicySetDefinition_basic
=== PAUSE TestAccAzureRMPolicySetDefinition_basic
=== CONT  TestAccAzureRMPolicySetDefinition_basic
--- PASS: TestAccAzureRMPolicySetDefinition_basic (113.77s)

(fixed #2193)

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.

Hi @olohmann,

Thank you for the new resource! Aside from a few (mostly minor) comments i've left inline this is looking pretty good. Once those issues have been addressed look forward to getting this merged for you 🙂

azurerm/resource_arm_policy_set_definition.go Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition.go Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition.go Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition.go Outdated Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition.go Outdated Show resolved Hide resolved
website/docs/r/policy_set_definition.html.markdown Outdated Show resolved Hide resolved
website/docs/r/policy_set_definition.html.markdown Outdated Show resolved Hide resolved
website/docs/r/policy_set_definition.html.markdown Outdated Show resolved Hide resolved
website/docs/r/policy_set_definition.html.markdown Outdated Show resolved Hide resolved
website/docs/r/policy_set_definition.html.markdown Outdated Show resolved Hide resolved
@olohmann
Copy link
Contributor Author

@katbyte - thanks so much for that quick and helpful review!

Applied requested changes and ran acceptance tests again.

> $ make testacc TESTARGS='-run=TestAccAzureRMPolicySetDefinition'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccAzureRMPolicySetDefinition -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
?   	github.com/terraform-providers/terraform-provider-azurerm	[no test files]
=== RUN   TestAccAzureRMPolicySetDefinition_basic
=== PAUSE TestAccAzureRMPolicySetDefinition_basic
=== CONT  TestAccAzureRMPolicySetDefinition_basic
--- PASS: TestAccAzureRMPolicySetDefinition_basic (111.78s)

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.

hey @olohmann

Thanks for pushing those changes - I've taken a look through and left some minor comments in line but this is otherwise looking good; if we can fix those up (and add an extra test case) we should be able to get this merged 👍

Thanks!

azurerm/resource_arm_policy_set_definition.go Outdated Show resolved Hide resolved
website/docs/r/policy_set_definition.html.markdown Outdated Show resolved Hide resolved
website/docs/r/policy_set_definition.html.markdown Outdated Show resolved Hide resolved
website/docs/r/policy_set_definition.html.markdown Outdated Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition.go Outdated Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition.go Outdated Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition.go Outdated Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition.go Outdated Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition.go Outdated Show resolved Hide resolved
azurerm/resource_arm_policy_set_definition_test.go Outdated Show resolved Hide resolved
@olohmann
Copy link
Contributor Author

@tombuildsstuff - cheers for the review! Added requested changes.

Acceptance test results:

> $ make testacc TESTARGS='-run=TestAccAzureRMPolicySetDefinition'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test $(go list ./... |grep -v 'vendor') -v -run=TestAccAzureRMPolicySetDefinition -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
?   	github.com/terraform-providers/terraform-provider-azurerm	[no test files]
=== RUN   TestAccAzureRMPolicySetDefinition_built_in_policy
=== PAUSE TestAccAzureRMPolicySetDefinition_built_in_policy
=== RUN   TestAccAzureRMPolicySetDefinition_custom_policy
=== PAUSE TestAccAzureRMPolicySetDefinition_custom_policy
=== CONT  TestAccAzureRMPolicySetDefinition_built_in_policy
=== CONT  TestAccAzureRMPolicySetDefinition_custom_policy
--- PASS: TestAccAzureRMPolicySetDefinition_built_in_policy (111.13s)
--- PASS: TestAccAzureRMPolicySetDefinition_custom_policy (202.65s)

@ghost ghost removed the waiting-response label Dec 19, 2018
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.

hey @olohmann

Thanks for pushing those changes - aside from a few minor comments (which I'll push a commit to fix) this otherwise LGTM 👍

Thanks!

"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMPolicySetDefinition_built_in_policy(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func TestAccAzureRMPolicySetDefinition_built_in_policy(t *testing.T) {
func TestAccAzureRMPolicySetDefinition_builtIn(t *testing.T) {

})
}

func TestAccAzureRMPolicySetDefinition_custom_policy(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func TestAccAzureRMPolicySetDefinition_custom_policy(t *testing.T) {
func TestAccAzureRMPolicySetDefinition_custom(t *testing.T) {

CheckDestroy: testCheckAzureRMPolicySetDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAzureRMPolicySetDefinition_built_in_policy(ri),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Config: testAzureRMPolicySetDefinition_built_in_policy(ri),
Config: testAzureRMPolicySetDefinition_builtIn(ri),

CheckDestroy: testCheckAzureRMPolicySetDefinitionDestroy,
Steps: []resource.TestStep{
{
Config: testAzureRMPolicySetDefinition_custom_policy(ri),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Config: testAzureRMPolicySetDefinition_custom_policy(ri),
Config: testAzureRMPolicySetDefinition_custom(ri),

})
}

func testAzureRMPolicySetDefinition_built_in_policy(ri int) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func testAzureRMPolicySetDefinition_built_in_policy(ri int) string {
func testAzureRMPolicySetDefinition_builtIn(ri int) string {

`, ri, ri)
}

func testAzureRMPolicySetDefinition_custom_policy(ri int) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func testAzureRMPolicySetDefinition_custom_policy(ri int) string {
func testAzureRMPolicySetDefinition_custom(ri int) string {

ValidateFunc: validation.StringInSlice([]string{
string(policy.TypeBuiltIn),
string(policy.TypeCustom),
string(policy.TypeNotSpecified),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should remove NotSpecified here

Suggested change
string(policy.TypeNotSpecified),

d.Set("name", resp.Name)

if props := resp.SetDefinitionProperties; props != nil {
d.Set("policy_type", props.PolicyType)
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is returned as an Enum rather than a string, it's best to cast this to a string explicitly here:

Suggested change
d.Set("policy_type", props.PolicyType)
d.Set("policy_type", string(props.PolicyType))


* `name` - (Required) The name of the policy set definition. Changing this forces a new resource to be created.

* `policy_type` - (Required) The policy set type. The value can be `BuiltIn`, `Custom` or `NotSpecified`
Copy link
Contributor

Choose a reason for hiding this comment

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

We tend to phrase this as:

Suggested change
* `policy_type` - (Required) The policy set type. The value can be `BuiltIn`, `Custom` or `NotSpecified`
* `policy_type` - (Required) The policy set type. Possible values are `BuiltIn` or `Custom`. Changing this forces a new resource to be created.

(note I've removed NotSpecified since I don't believe we need to support it)

@tombuildsstuff tombuildsstuff dismissed katbyte’s stale review December 20, 2018 09:37

changes have been pushed

@tombuildsstuff
Copy link
Contributor

Tests pass:

screenshot 2018-12-20 at 09 48 16

@tombuildsstuff tombuildsstuff merged commit 09831b6 into hashicorp:master Dec 20, 2018
tombuildsstuff added a commit that referenced this pull request Dec 20, 2018
@ghost
Copy link

ghost commented Mar 5, 2019

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 and limited conversation to collaborators Mar 5, 2019
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.

Support for azurerm_policy_set_definition
3 participants