-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Adding Ports To Container Groups #1930
Conversation
1. Adding ports field to allow for multiple port exposures 2. Refactore tests
Hi @nathanjsweet, It looks like this is still a WIP? as tests and documentation is missing. There is an existing branch I never finished here One thing to note is protocol is applies to all containers so it can be pulled out into the top level, simplifying the logic. |
I did change the tests. It doesn't look like ports where being tested before. Should we update the tests altogether?. |
We should have 1 test with the old property so we know it still works, and another one with multiple ports. Also the documentation should to be updated. |
ForceNew: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeInt, | ||
ValidateFunc: validation.IntBetween(1, 65535), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an existing validation function validate.PortNumber
that could be used here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't find it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is in the validate package
Hi @nathanjsweet, Just wondering if you are intending to continue working on this? 🙂 |
@katbyte I updated the code to merge port and protocol (which is what Azure does). If and when the tests pass, let me know if you'd like me to update the documentation. The next thing I would like to do is add the private IP type so that people can launch network inaccessible containers. |
@katbyte Here is the error I'm getting:
It seems like I'm using the |
Hi @nathanjsweet, Sorry for the delay, its been a busy time with v1.17 last week and hashiconf this week. I'll try and look at it next week, however could you merge in the latest master and see if you can fix the build? The error: I believe it may be fixed by changing the conflicts with string to |
What if it isn't the 0th container? |
It will still work because no matter how many elements are in the other property, the first will always exist and trigger a conflict. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've gone through the PR and left comments inline, i'm happy to see your testing the port
-> ports
upgrade path! My main concern is that the tests should only be checking the state and not the response. I don't think the additional checks in the exists function are required.
The code is also failing to compile, it looks like you forgot to vendor in some packages?
}, | ||
|
||
"ports": { | ||
Type: schema.TypeList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably use a TypeSet
here as order doesn't matter? at we shouldn't allow duplicates.
) | ||
|
||
var emptyCheck = func(cg containerinstance.ContainerGroup) error { return nil } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not required
@@ -595,8 +766,7 @@ func testCheckAzureRMContainerGroupExists(name string) resource.TestCheckFunc { | |||
} | |||
return fmt.Errorf("Bad: Get on containerGroupsClient: %+v", err) | |||
} | |||
|
|||
return nil | |||
return checkResp(resp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only be checking the resource exists here, anything more should be via the state.
@katbyte I don't know where or how to do the documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All that needs to be done for the documentation is remove port
and add ports
from this file.
I have also re ran the tests and now the fail with:
------- Stdout: -------
=== RUN TestAccAzureRMContainerGroup_imageRegistryCredentials
=== PAUSE TestAccAzureRMContainerGroup_imageRegistryCredentials
=== CONT TestAccAzureRMContainerGroup_imageRegistryCredentials
--- FAIL: TestAccAzureRMContainerGroup_imageRegistryCredentials (66.78s)
testing.go:538: Step 0 error: Error applying: 1 error(s) occurred:
* azurerm_container_group.test: 1 error(s) occurred:
* azurerm_container_group.test: containerinstance.ContainerGroupsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="UnreferencedIpAddressPorts" Message="Following ports '5443' in the 'ipAddress' are not used by any container in container group 'acctestcontainergroup-8589748340137379081'."
FAIL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests as still failing with the following:
------- Stdout: -------
=== RUN TestAccAzureRMContainerGroup_imageRegistryCredentials
=== PAUSE TestAccAzureRMContainerGroup_imageRegistryCredentials
=== CONT TestAccAzureRMContainerGroup_imageRegistryCredentials
--- FAIL: TestAccAzureRMContainerGroup_imageRegistryCredentials (63.39s)
testing.go:538: Step 0 error: Error applying: 1 error(s) occurred:
* azurerm_container_group.test: 1 error(s) occurred:
* azurerm_container_group.test: containerinstance.ContainerGroupsClient#CreateOrUpdate: Failure sending request: StatusCode=0 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="UnreferencedIpAddressPorts" Message="Following ports '5443' in the 'ipAddress' are not used by any container in container group 'acctestcontainergroup-7738923082888827735'."
FAIL
Optional: true, | ||
ForceNew: true, | ||
DiffSuppressFunc: ignoreCaseDiffSuppressFunc, | ||
Default: string("TCP"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default: string("TCP"), | |
Default: string(containerinstance.TCP), |
@@ -81,6 +83,9 @@ func TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate(t *testing.T) { | |||
resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.server", "hub.docker.com"), | |||
resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.username", "updatedusername"), | |||
resource.TestCheckResourceAttr(resourceName, "image_registry_credential.0.password", "updatedpassword"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "1"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.0.port", "80"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail because with a set you can no longer use .0.
notation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what can I do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best way is to simply check the count via #. You can calculate the hash and access it that way however that isn't required.
@@ -143,6 +149,11 @@ func TestAccAzureRMContainerGroup_linuxBasicUpdate(t *testing.T) { | |||
Check: resource.ComposeTestCheckFunc( | |||
testCheckAzureRMContainerGroupExists(resourceName), | |||
resource.TestCheckResourceAttr(resourceName, "container.#", "2"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "2"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.0.port", "80"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail because with a set you can no longer use .0. notation.
@@ -165,6 +176,9 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) { | |||
Check: resource.ComposeTestCheckFunc( | |||
testCheckAzureRMContainerGroupExists(resourceName), | |||
resource.TestCheckResourceAttr(resourceName, "container.#", "1"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "1"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.0.port", "80"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail because with a set you can no longer use .0. notation.
@@ -216,6 +230,11 @@ func TestAccAzureRMContainerGroup_windowsBasic(t *testing.T) { | |||
testCheckAzureRMContainerGroupExists(resourceName), | |||
resource.TestCheckResourceAttr(resourceName, "container.#", "1"), | |||
resource.TestCheckResourceAttr(resourceName, "os_type", "Windows"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "2"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.0.port", "80"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail because with a set you can no longer use .0. notation.
@@ -243,6 +262,9 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) { | |||
Check: resource.ComposeTestCheckFunc( | |||
testCheckAzureRMContainerGroupExists(resourceName), | |||
resource.TestCheckResourceAttr(resourceName, "container.#", "1"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.#", "1"), | |||
resource.TestCheckResourceAttr(resourceName, "container.0.ports.0.port", "80"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail because with a set you can no longer use .0. notation.
|
||
* `port` - (Required) The port number the container will expose. | ||
|
||
* `protocol` - (Optional) The network protocol ("tcp"/"udp") the port will use. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should specify what the default is:
* `protocol` - (Optional) The network protocol ("tcp"/"udp") the port will use. | |
* `protocol` - (Optional) The network protocol associated with port. Possible values are `TCP`, `UDP` and the default is `TCP`. |
Just wondering if you are still working on this 🙂 |
@@ -436,6 +469,25 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc | |||
containerGroupPorts = append(containerGroupPorts, containerGroupPort) | |||
} | |||
|
|||
if v, ok := data["ports"]; ok { | |||
s := v.(*schema.Set) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I also need to deploy a container instance with multiple open ports, I cherry-picked the change in this pull request to a forked repo: https://github.com/TechhubLisbon/terraform-provider-azurerm/tree/patched_master
I only had one issue: panic: interface conversion: interface {} is *schema.Set, not []interface {}
I fixed this by replacing this line with s := v.([]interface{})
Commit: tblxio@dc95c9e
Everything else looked good!
Hi @nathanjsweet, I hope you don't mind but I have made some updates to your code to get it to pass so i can get it merged today/tomorrow. |
Tests pass:
|
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! |
(fixes #1662)