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_group - Add supports of http_headers #17519

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions internal/services/containers/container_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1477,16 +1477,53 @@ func expandContainerProbe(input interface{}) *containerinstance.ContainerProbe {

httpGetScheme := containerinstance.Scheme(scheme)
probe.HttpGet = &containerinstance.ContainerHttpGet{
Path: pointer.FromString(path),
Port: int64(port),
Scheme: &httpGetScheme,
Path: pointer.FromString(path),
Port: int64(port),
Scheme: &httpGetScheme,
HttpHeaders: expandContainerProbeHttpHeaders(x["http_headers"].(map[string]interface{})),
}
}
}
}
return &probe
}

func expandContainerProbeHttpHeaders(input map[string]interface{}) *[]containerinstance.HttpHeader {
if len(input) == 0 {
return nil
}

headers := []containerinstance.HttpHeader{}
for k, v := range input {
header := containerinstance.HttpHeader{
Name: pointer.FromString(k),
Value: pointer.FromString(v.(string)),
}
headers = append(headers, header)
}
return &headers
}

func flattenContainerProbeHttpHeaders(input *[]containerinstance.HttpHeader) map[string]interface{} {
if input == nil {
return nil
}

output := map[string]interface{}{}
for _, header := range *input {
name := ""
if header.Name != nil {
name = *header.Name
}
value := ""
if header.Value != nil {
value = *header.Value
}
output[name] = value
}
return output
}

func flattenContainerImageRegistryCredentials(d *pluginsdk.ResourceData, input *[]containerinstance.ImageRegistryCredential) []interface{} {
if input == nil {
return nil
Expand Down Expand Up @@ -1786,6 +1823,7 @@ func flattenContainerProbes(input *containerinstance.ContainerProbe) []interface
}
httpGet["port"] = get.Port
httpGet["scheme"] = get.Scheme
httpGet["http_headers"] = flattenContainerProbeHttpHeaders(get.HttpHeaders)
httpGets = append(httpGets, httpGet)
}
output["http_get"] = httpGets
Expand Down
12 changes: 12 additions & 0 deletions internal/services/containers/container_group_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,10 @@ resource "azurerm_container_group" "test" {
path = "/"
port = 443
scheme = "Http"
http_headers = {
h1 = "v1"
h2 = "v2"
}
}
}
}
Expand Down Expand Up @@ -1764,6 +1768,10 @@ resource "azurerm_container_group" "test" {
path = "/"
port = 443
scheme = "Http"
http_headers = {
h1 = "v1"
h2 = "v2"
}
}

initial_delay_seconds = 1
Expand Down Expand Up @@ -1910,6 +1918,10 @@ resource "azurerm_container_group" "test" {
path = "/"
port = 443
scheme = "Http"
http_headers = {
h1 = "v1"
h2 = "v2"
}
}

initial_delay_seconds = 1
Expand Down
8 changes: 8 additions & 0 deletions internal/services/containers/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ func SchemaContainerGroupProbe() *pluginsdk.Schema {
"Https",
}, false),
},
"http_headers": {
Type: pluginsdk.TypeMap,
Optional: true,
ForceNew: true,
Elem: &pluginsdk.Schema{
Type: pluginsdk.TypeString,
},
},
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/container_group.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ The `http_get` block supports:

* `scheme` - (Optional) Scheme to use for connecting to the host. Possible values are `Http` and `Https`. Changing this forces a new resource to be created.

* `http_headers` - (Optional) A map of HTTP headers used to access on the container. Changing this forces a new resource to be created.

---

The `dns_config` block supports:
Expand Down