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

Monitoring add content type #2233

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3706.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
monitoring: added `request_method`, `content_type`, and `body` fields within the `http_check` object to `google_monitoring_uptime_check_config` resource
```
71 changes: 71 additions & 0 deletions google-beta/resource_monitoring_uptime_check_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,20 @@ func resourceMonitoringUptimeCheckConfig() *schema.Resource {
},
AtLeastOneOf: []string{"http_check.0.auth_info", "http_check.0.port", "http_check.0.headers", "http_check.0.path", "http_check.0.use_ssl", "http_check.0.mask_headers"},
},
"body": {
Type: schema.TypeString,
Optional: true,
Description: `The request body associated with the HTTP POST request. If contentType is URL_ENCODED, the body passed in must be URL-encoded. Users can provide a Content-Length header via the headers field or the API will do so. If the requestMethod is GET and body is not empty, the API will return an error. The maximum byte size is 1 megabyte. Note - As with all bytes fields JSON representations are base64 encoded. e.g. "foo=bar" in URL-encoded form is "foo%3Dbar" and in base64 encoding is "Zm9vJTI1M0RiYXI=".`,
},
"content_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"TYPE_UNSPECIFIED", "URL_ENCODED", ""}, false),
Description: `The content type to use for the check. Possible values: ["TYPE_UNSPECIFIED", "URL_ENCODED"]`,
},
"headers": {
Type: schema.TypeMap,
Computed: true,
Optional: true,
Description: `The list of headers to send as part of the uptime check request. If two headers have the same key and different values, they should be entered as a single header, with the value being a comma-separated list of all the desired values as described at https://www.w3.org/Protocols/rfc2616/rfc2616.txt (page 31). Entering two separate headers with the same key in a Create call will cause the first to be overwritten by the second. The maximum number of headers allowed is 100.`,
Elem: &schema.Schema{Type: schema.TypeString},
Expand All @@ -131,6 +143,14 @@ func resourceMonitoringUptimeCheckConfig() *schema.Resource {
Description: `The port to the page to run the check against. Will be combined with host (specified within the MonitoredResource) and path to construct the full URL. Optional (defaults to 80 without SSL, or 443 with SSL).`,
AtLeastOneOf: []string{"http_check.0.auth_info", "http_check.0.port", "http_check.0.headers", "http_check.0.path", "http_check.0.use_ssl", "http_check.0.mask_headers"},
},
"request_method": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"METHOD_UNSPECIFIED", "GET", "POST", ""}, false),
Description: `The HTTP request method to use for the check. If set to METHOD_UNSPECIFIED then requestMethod defaults to GET. Default value: "GET" Possible values: ["METHOD_UNSPECIFIED", "GET", "POST"]`,
Default: "GET",
},
"use_ssl": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -670,6 +690,10 @@ func flattenMonitoringUptimeCheckConfigHttpCheck(v interface{}, d *schema.Resour
return nil
}
transformed := make(map[string]interface{})
transformed["request_method"] =
flattenMonitoringUptimeCheckConfigHttpCheckRequestMethod(original["requestMethod"], d, config)
transformed["content_type"] =
flattenMonitoringUptimeCheckConfigHttpCheckContentType(original["contentType"], d, config)
transformed["auth_info"] =
flattenMonitoringUptimeCheckConfigHttpCheckAuthInfo(original["authInfo"], d, config)
transformed["port"] =
Expand All @@ -684,8 +708,18 @@ func flattenMonitoringUptimeCheckConfigHttpCheck(v interface{}, d *schema.Resour
flattenMonitoringUptimeCheckConfigHttpCheckValidateSsl(original["validateSsl"], d, config)
transformed["mask_headers"] =
flattenMonitoringUptimeCheckConfigHttpCheckMaskHeaders(original["maskHeaders"], d, config)
transformed["body"] =
flattenMonitoringUptimeCheckConfigHttpCheckBody(original["body"], d, config)
return []interface{}{transformed}
}
func flattenMonitoringUptimeCheckConfigHttpCheckRequestMethod(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenMonitoringUptimeCheckConfigHttpCheckContentType(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenMonitoringUptimeCheckConfigHttpCheckAuthInfo(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -746,6 +780,10 @@ func flattenMonitoringUptimeCheckConfigHttpCheckMaskHeaders(v interface{}, d *sc
return v
}

func flattenMonitoringUptimeCheckConfigHttpCheckBody(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenMonitoringUptimeCheckConfigTcpCheck(v interface{}, d *schema.ResourceData, config *Config) interface{} {
if v == nil {
return nil
Expand Down Expand Up @@ -885,6 +923,20 @@ func expandMonitoringUptimeCheckConfigHttpCheck(v interface{}, d TerraformResour
original := raw.(map[string]interface{})
transformed := make(map[string]interface{})

transformedRequestMethod, err := expandMonitoringUptimeCheckConfigHttpCheckRequestMethod(original["request_method"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedRequestMethod); val.IsValid() && !isEmptyValue(val) {
transformed["requestMethod"] = transformedRequestMethod
}

transformedContentType, err := expandMonitoringUptimeCheckConfigHttpCheckContentType(original["content_type"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedContentType); val.IsValid() && !isEmptyValue(val) {
transformed["contentType"] = transformedContentType
}

transformedAuthInfo, err := expandMonitoringUptimeCheckConfigHttpCheckAuthInfo(original["auth_info"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -934,9 +986,24 @@ func expandMonitoringUptimeCheckConfigHttpCheck(v interface{}, d TerraformResour
transformed["maskHeaders"] = transformedMaskHeaders
}

transformedBody, err := expandMonitoringUptimeCheckConfigHttpCheckBody(original["body"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedBody); val.IsValid() && !isEmptyValue(val) {
transformed["body"] = transformedBody
}

return transformed, nil
}

func expandMonitoringUptimeCheckConfigHttpCheckRequestMethod(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigHttpCheckContentType(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigHttpCheckAuthInfo(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -1002,6 +1069,10 @@ func expandMonitoringUptimeCheckConfigHttpCheckMaskHeaders(v interface{}, d Terr
return v, nil
}

func expandMonitoringUptimeCheckConfigHttpCheckBody(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandMonitoringUptimeCheckConfigTcpCheck(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
l := v.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ resource "google_monitoring_uptime_check_config" "http" {
http_check {
path = "/some-path"
port = "8010"
request_method = "POST"
content_type = "URL_ENCODED"
body = "Zm9vJTI1M0RiYXI="
}

monitored_resource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ resource "google_monitoring_uptime_check_config" "http" {
http_check {
path = "/%s"
port = "8010"
request_method = "GET"
auth_info {
username = "name"
password = "%s"
Expand Down
25 changes: 25 additions & 0 deletions website/docs/r/monitoring_uptime_check_config.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ resource "google_monitoring_uptime_check_config" "http" {
http_check {
path = "/some-path"
port = "8010"
request_method = "POST"
content_type = "URL_ENCODED"
body = "Zm9vJTI1M0RiYXI="
}

monitored_resource {
Expand Down Expand Up @@ -195,6 +198,24 @@ The `content_matchers` block supports:

The `http_check` block supports:

* `request_method` -
(Optional)
The HTTP request method to use for the check. If set to METHOD_UNSPECIFIED then requestMethod defaults to GET.

Default value: `GET`
Possible values are:
* `METHOD_UNSPECIFIED`
* `GET`
* `POST`

* `content_type` -
(Optional)
The content type to use for the check.

Possible values are:
* `TYPE_UNSPECIFIED`
* `URL_ENCODED`

* `auth_info` -
(Optional)
The authentication information. Optional when creating an HTTP check; defaults to empty. Structure is documented below.
Expand Down Expand Up @@ -223,6 +244,10 @@ The `http_check` block supports:
(Optional)
Boolean specifying whether to encrypt the header information. Encryption should be specified for any headers related to authentication that you do not wish to be seen when retrieving the configuration. The server will be responsible for encrypting the headers. On Get/List calls, if mask_headers is set to True then the headers will be obscured with ******.

* `body` -
(Optional)
The request body associated with the HTTP POST request. If contentType is URL_ENCODED, the body passed in must be URL-encoded. Users can provide a Content-Length header via the headers field or the API will do so. If the requestMethod is GET and body is not empty, the API will return an error. The maximum byte size is 1 megabyte. Note - As with all bytes fields JSON representations are base64 encoded. e.g. "foo=bar" in URL-encoded form is "foo%3Dbar" and in base64 encoding is "Zm9vJTI1M0RiYXI=".


The `auth_info` block supports:

Expand Down