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

azurerm_container_registry: support for network_rule_set property #3194

Merged

Conversation

fraserdarwent
Copy link
Contributor

@fraserdarwent fraserdarwent commented Apr 5, 2019

In response to #3134

(upgrades "github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2017-10-01/containerregistry" to 2018-09-01)

Example Terraform code

resource "azurerm_container_registry" "acr" {
  name = "registry"
  resource_group_name = "${azurerm_resource_group.main.name}"
  location = "${azurerm_resource_group.main.location}"
  sku = "Premium"
  admin_enabled = false
  
  network_rules_profile {
    default_action = "Deny"
    
    ip_rule {
      action = "Allow"
      ip_range = "8.8.8.8/32"
    }
    
    subnet_rule {
      action = "Allow"
      subnet_id = "${azurerm_subnet.main.id}"
    }
  }

Getting an early PR in for feedback.
Still need to update docs and tests.

Fixes #3134

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 @fraserdarwent

Thanks for this PR - apologies for the delayed review here!

Taking a look through this mostly LGTM - I've left some (mostly minor) comments in-line, but the main thing remaining is the tests; if we can fix up the comments and add some tests this should otherwise be good to merge 👍

Thanks!

azurerm/resource_arm_container_registry.go Outdated Show resolved Hide resolved
ValidateFunc: validation.StringInSlice([]string{
string(containerregistry.DefaultActionAllow),
string(containerregistry.DefaultActionDeny),
}, true),
Copy link
Contributor

Choose a reason for hiding this comment

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

we're making all new fields case-sensitive; as such can we make this:

Suggested change
}, true),
}, false),

Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(containerregistry.Allow),
}, true),
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) we're making all new fields case-sensitive - as such can we make this:

Suggested change
}, true),
}, false),

},
"subnet_id": {
Type: schema.TypeString,
Required: true,
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 a Subnet/Resource ID can we validate this:

Suggested change
Required: true,
Required: true,
ValidateFunc: validate.AzureResourceID,

Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(containerregistry.Allow),
}, true),
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) all new fields in the provider are case-sensitive - as such can we make this:

Suggested change
}, true),
}, false),


`subnet_rule` supports the following:

* `action` - (Required) The behaviour for requests matching this rule. Can only be `Allow`
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency with other resources can we make this:

Suggested change
* `action` - (Required) The behaviour for requests matching this rule. Can only be `Allow`
* `action` - (Required) The behaviour for requests matching this rule. At this time the only supported value is `Allow`


* `action` - (Required) The behaviour for requests matching this rule. Can only be `Allow`

* `subnet_id` - (Required) Resource ID of the subnet from which requests will match the rule.
Copy link
Contributor

Choose a reason for hiding this comment

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

for consistency with other resources can we make this:

Suggested change
* `subnet_id` - (Required) Resource ID of the subnet from which requests will match the rule.
* `subnet_id` - (Required) The ID of the Subnet from which requests will match the rule.

config := configs[0].(map[string]interface{})

virtualNetworkRuleConfigs := config["subnet_rule"].([]interface{})
virtualNetworkRules := make([]containerregistry.VirtualNetworkRule, 0, len(virtualNetworkRuleConfigs))
Copy link
Contributor

Choose a reason for hiding this comment

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

we can remove this last item here:

Suggested change
virtualNetworkRules := make([]containerregistry.VirtualNetworkRule, 0, len(virtualNetworkRuleConfigs))
virtualNetworkRules := make([]containerregistry.VirtualNetworkRule, 0)

@@ -499,3 +560,39 @@ func validateAzureRMContainerRegistryName(v interface{}, k string) (warnings []s

return warnings, errors
}

func expandNetworkRuleSet(d *schema.ResourceData) *containerregistry.NetworkRuleSet {
configs := d.Get("network_access_profile").(*schema.Set).List()
Copy link
Contributor

Choose a reason for hiding this comment

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

since we're making this a List (above) we can make this:

Suggested change
configs := d.Get("network_access_profile").(*schema.Set).List()
configs := d.Get("network_access_profile").([]interface{})

}

ipRuleConfigs := config["ip_rule"].([]interface{})
ipRules := make([]containerregistry.IPRule, 0, len(ipRuleConfigs))
Copy link
Contributor

Choose a reason for hiding this comment

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

(as above) we can remove this final argument here:

Suggested change
ipRules := make([]containerregistry.IPRule, 0, len(ipRuleConfigs))
ipRules := make([]containerregistry.IPRule, 0)

@fraserdarwent
Copy link
Contributor Author

@tombuildsstuff addressed comments

@ghost ghost removed the waiting-response label Apr 16, 2019
@fraserdarwent
Copy link
Contributor Author

@katbyte made suggested changes to pass the tests as the value is computed

@ghost ghost removed the waiting-response label May 20, 2019
@katbyte
Copy link
Collaborator

katbyte commented May 20, 2019

Hi @fraserdarwent,
Still seeing mulitple tests failing with:

------- Stdout: -------
=== RUN   TestAccAzureRMContainerRegistry_geoReplication
=== PAUSE TestAccAzureRMContainerRegistry_geoReplication
=== CONT  TestAccAzureRMContainerRegistry_geoReplication
--- FAIL: TestAccAzureRMContainerRegistry_geoReplication (405.09s)
    testing.go:568: Step 4 error: errors during apply:
        
        Error: `network_rule_set` can only be specified for a Premium Sku.
        
          on /opt/teamcity-agent/temp/buildTmp/tf-test829217438/main.tf line 7:
          (source code not available)
        
        
FAIL

@katbyte katbyte modified the milestones: v1.29.0, v1.30.0 May 25, 2019
@tombuildsstuff tombuildsstuff modified the milestones: v1.30.0, v1.31.0 Jun 6, 2019
@katbyte katbyte modified the milestones: v1.31.0, v1.32.0 Jun 28, 2019
@katbyte
Copy link
Collaborator

katbyte commented Jul 2, 2019

Hi @fraserdarwent,

I hope you don't mind but i've pushed some changes to this branch to fix the above error, rename the property to better match the API as well as adding some more tests so I can merge this. It appears VNET rules are being ignored by the API? and only ip_rules are actually being set. As such i have opened an issue on the SDK and removed that from this PR. I'll open a new PR shortly with that property so once the API is fixed we can get that merged in too 🙂

@katbyte katbyte changed the title Support for networkRuleSet in azurerm_container_registry azurerm_container_registry: support for network_rule_set property Jul 2, 2019
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.

Have pushed required changes

@katbyte katbyte merged commit 91131da into hashicorp:master Jul 3, 2019
katbyte added a commit that referenced this pull request Jul 3, 2019
@ghost
Copy link

ghost commented Jul 30, 2019

This has been released in version 1.32.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 = "~> 1.32.0"
}
# ... other configuration ...

@ghost ghost removed the waiting-response label Jul 30, 2019
@ghost
Copy link

ghost commented Aug 2, 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 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Aug 2, 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.

Add support for networkRuleSet to azurerm_container_registry
3 participants