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

Adding Ports To Container Groups #1930

Merged
merged 19 commits into from
Jan 11, 2019
Merged

Adding Ports To Container Groups #1930

merged 19 commits into from
Jan 11, 2019

Conversation

nathanjsweet
Copy link
Contributor

@nathanjsweet nathanjsweet commented Sep 14, 2018

  1. Adding ports field to allow for multiple port exposures
  2. Refactor tests

(fixes #1662)

1. Adding ports field to allow for multiple port exposures
2. Refactore tests
@ghost ghost added the size/M label Sep 14, 2018
@katbyte
Copy link
Collaborator

katbyte commented Sep 19, 2018

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.

@nathanjsweet
Copy link
Contributor Author

I did change the tests. It doesn't look like ports where being tested before. Should we update the tests altogether?.

@katbyte
Copy link
Collaborator

katbyte commented Sep 20, 2018

@nathanjsweet,

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.

azurerm/resource_arm_container_group.go Outdated Show resolved Hide resolved
azurerm/resource_arm_container_group.go Show resolved Hide resolved
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
ValidateFunc: validation.IntBetween(1, 65535),
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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

@katbyte
Copy link
Collaborator

katbyte commented Oct 16, 2018

Hi @nathanjsweet,

Just wondering if you are intending to continue working on this? 🙂

@ghost ghost added size/XL and removed size/M labels Oct 16, 2018
@nathanjsweet
Copy link
Contributor Author

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

@nathanjsweet
Copy link
Contributor Author

@katbyte Here is the error I'm getting:

--- FAIL: TestProvider (0.03s)
	provider_test.go:28: err: 1 error(s) occurred:
		
		* resource azurerm_container_group: port: ConflictsWith references unknown attribute (ports)

It seems like I'm using the ConflictsWith attribute incorrectly. Would you mind taking a look and making a suggestion?

@katbyte katbyte self-assigned this Oct 25, 2018
@katbyte katbyte added this to the 1.19.0 milestone Oct 25, 2018
@katbyte
Copy link
Collaborator

katbyte commented Oct 25, 2018

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: * resource azurerm_container_group: port: ConflictsWith references unknown attribute (ports)

I believe it may be fixed by changing the conflicts with string to container.0.ports

@nathanjsweet
Copy link
Contributor Author

I believe it may be fixed by changing the conflicts with string to container.0.ports

What if it isn't the 0th container?

@katbyte
Copy link
Collaborator

katbyte commented Oct 29, 2018

@nathanjsweet,

It will still work because no matter how many elements are in the other property, the first will always exist and trigger a conflict.

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.

@nathanjsweet,

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?

azurerm/resource_arm_container_group.go Outdated Show resolved Hide resolved
},

"ports": {
Type: schema.TypeList,
Copy link
Collaborator

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.

azurerm/resource_arm_container_group_test.go Outdated Show resolved Hide resolved
)

var emptyCheck = func(cg containerinstance.ContainerGroup) error { return nil }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not required

azurerm/resource_arm_container_group_test.go Outdated Show resolved Hide resolved
@@ -595,8 +766,7 @@ func testCheckAzureRMContainerGroupExists(name string) resource.TestCheckFunc {
}
return fmt.Errorf("Bad: Get on containerGroupsClient: %+v", err)
}

return nil
return checkResp(resp)
Copy link
Collaborator

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.

azurerm/resource_arm_container_group.go Outdated Show resolved Hide resolved
@nathanjsweet
Copy link
Contributor Author

@katbyte I don't know where or how to do the documentation.

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

@nathanjsweet,

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

@ghost ghost added size/L and removed size/M labels Nov 29, 2018
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.

@nathanjsweet,

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"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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"),
Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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"),
Copy link
Collaborator

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"),
Copy link
Collaborator

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"),
Copy link
Collaborator

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"),
Copy link
Collaborator

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.
Copy link
Collaborator

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:

Suggested change
* `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`.

@tombuildsstuff tombuildsstuff modified the milestones: 1.20.0, 1.21.0 Dec 6, 2018
@katbyte
Copy link
Collaborator

katbyte commented Dec 20, 2018

@nathanjsweet 👋

Just wondering if you are still working on this 🙂

@ghost ghost added the documentation label Jan 5, 2019
@@ -436,6 +469,25 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc
containerGroupPorts = append(containerGroupPorts, containerGroupPort)
}

if v, ok := data["ports"]; ok {
s := v.(*schema.Set)
Copy link

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!

@katbyte
Copy link
Collaborator

katbyte commented Jan 11, 2019

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.

@katbyte
Copy link
Collaborator

katbyte commented Jan 11, 2019

Tests pass:

==> Fixing source code with gofmt...
gofmt -s -w ./azurerm
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./azurerm -v -test.run=TestAccAzureRMContainerGroup -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccAzureRMContainerGroup_imageRegistryCredentials
=== PAUSE TestAccAzureRMContainerGroup_imageRegistryCredentials
=== RUN   TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate
=== PAUSE TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate
=== RUN   TestAccAzureRMContainerGroup_linuxBasic
=== PAUSE TestAccAzureRMContainerGroup_linuxBasic
=== RUN   TestAccAzureRMContainerGroup_requiresImport
--- SKIP: TestAccAzureRMContainerGroup_requiresImport (0.00s)
    resource_arm_container_group_test.go:128: Skipping since resources aren't required to be imported
=== RUN   TestAccAzureRMContainerGroup_linuxBasicUpdate
=== PAUSE TestAccAzureRMContainerGroup_linuxBasicUpdate
=== RUN   TestAccAzureRMContainerGroup_linuxComplete
=== PAUSE TestAccAzureRMContainerGroup_linuxComplete
=== RUN   TestAccAzureRMContainerGroup_windowsBasic
=== PAUSE TestAccAzureRMContainerGroup_windowsBasic
=== RUN   TestAccAzureRMContainerGroup_windowsComplete
=== PAUSE TestAccAzureRMContainerGroup_windowsComplete
=== CONT  TestAccAzureRMContainerGroup_imageRegistryCredentials
=== CONT  TestAccAzureRMContainerGroup_linuxComplete
=== CONT  TestAccAzureRMContainerGroup_linuxBasic
=== CONT  TestAccAzureRMContainerGroup_windowsComplete
=== CONT  TestAccAzureRMContainerGroup_linuxBasicUpdate
=== CONT  TestAccAzureRMContainerGroup_windowsBasic
=== CONT  TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate
--- PASS: TestAccAzureRMContainerGroup_imageRegistryCredentials (82.65s)
--- PASS: TestAccAzureRMContainerGroup_windowsBasic (83.04s)
--- PASS: TestAccAzureRMContainerGroup_linuxBasic (83.58s)
--- PASS: TestAccAzureRMContainerGroup_windowsComplete (84.46s)
--- PASS: TestAccAzureRMContainerGroup_linuxBasicUpdate (104.66s)
--- PASS: TestAccAzureRMContainerGroup_imageRegistryCredentialsUpdate (107.03s)
--- PASS: TestAccAzureRMContainerGroup_linuxComplete (146.48s)
PASS
ok  	github.com/terraform-providers/terraform-provider-azurerm/azurerm	147.623s

@katbyte katbyte merged commit 6889f3e into hashicorp:master Jan 11, 2019
katbyte added a commit that referenced this pull request Jan 11, 2019
@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 👉 hashibot-feedback@hashicorp.com. 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.

Allow Container ~Group~ Ports to be specifically specified rather than aggregating the container ports
5 participants