diff --git a/docs/resources/google_cloud_scheduler_job.md b/docs/resources/google_cloud_scheduler_job.md new file mode 100644 index 000000000..7fc253b13 --- /dev/null +++ b/docs/resources/google_cloud_scheduler_job.md @@ -0,0 +1,97 @@ +--- +title: About the google_cloud_scheduler_job resource +platform: gcp +--- + +## Syntax +A `google_cloud_scheduler_job` is used to test a Google Job resource + +## Examples +``` +describe google_cloud_scheduler_job(project: 'chef-gcp-inspec', region: us-central1, name: 'job-name') do + it { should exist } + + its('description') { should cmp 'A description' } + its('schedule') { should cmp '*/8 * * * *' } + its('time_zone') { should cmp 'America/New_York' } + its('http_target.http_method') { should cmp 'POST' } + its('http_target.uri') { should cmp 'https://example.com/ping' } +end +``` + +## Properties +Properties that can be accessed from the `google_cloud_scheduler_job` resource: + + + * `name`: The name of the job. + + * `description`: A human-readable description for the job. This string must not contain more than 500 characters. + + * `schedule`: Describes the schedule on which the job will be executed. + + * `time_zone`: Specifies the time zone to be used in interpreting schedule. The value of this field must be a time zone name from the tz database. + + * `retry_config`: By default, if a job does not complete successfully, meaning that an acknowledgement is not received from the handler, then it will be retried with exponential backoff according to the settings + + * `retry_count`: The number of attempts that the system will make to run a job using the exponential backoff procedure described by maxDoublings. Values greater than 5 and negative values are not allowed. + + * `max_retry_duration`: The time limit for retrying a failed job, measured from time when an execution was first attempted. If specified with retryCount, the job will be retried until both limits are reached. A duration in seconds with up to nine fractional digits, terminated by 's'. + + * `min_backoff_duration`: The minimum amount of time to wait before retrying a job after it fails. A duration in seconds with up to nine fractional digits, terminated by 's'. + + * `max_backoff_duration`: The maximum amount of time to wait before retrying a job after it fails. A duration in seconds with up to nine fractional digits, terminated by 's'. + + * `max_doublings`: The time between retries will double maxDoublings times. A job's retry interval starts at minBackoffDuration, then doubles maxDoublings times, then increases linearly, and finally retries retries at intervals of maxBackoffDuration up to retryCount times. + + * `pubsub_target`: Pub/Sub target If the job providers a Pub/Sub target the cron will publish a message to the provided topic + + * `topic_name`: The name of the Cloud Pub/Sub topic to which messages will be published when a job is delivered. The topic name must be in the same format as required by PubSub's PublishRequest.name, for example projects/PROJECT_ID/topics/TOPIC_ID. + + * `data`: The message payload for PubsubMessage. Pubsub message must contain either non-empty data, or at least one attribute. + + * `attributes`: Attributes for PubsubMessage. Pubsub message must contain either non-empty data, or at least one attribute. + + * `app_engine_http_target`: App Engine HTTP target. If the job providers a App Engine HTTP target the cron will send a request to the service instance + + * `http_method`: Which HTTP method to use for the request. + + * `app_engine_routing`: App Engine Routing setting for the job. + + * `service`: App service. By default, the job is sent to the service which is the default service when the job is attempted. + + * `version`: App version. By default, the job is sent to the version which is the default version when the job is attempted. + + * `instance`: App instance. By default, the job is sent to an instance which is available when the job is attempted. + + * `relative_uri`: The relative URI. The relative URL must begin with "/" and must be a valid HTTP relative URL. It can contain a path, query string arguments, and \# fragments. If the relative URL is empty, then the root path "/" will be used. No spaces are allowed, and the maximum length allowed is 2083 characters + + * `body`: HTTP request body. A request body is allowed only if the HTTP method is POST or PUT. It will result in invalid argument error to set a body on a job with an incompatible HttpMethod. + + * `headers`: HTTP request headers. This map contains the header field names and values. Headers can be set when the job is created. + + * `http_target`: HTTP target. If the job providers a http_target the cron will send a request to the targeted url + + * `uri`: The full URI path that the request will be sent to. + + * `http_method`: Which HTTP method to use for the request. + + * `body`: HTTP request body. A request body is allowed only if the HTTP method is POST, PUT, or PATCH. It is an error to set body on a job with an incompatible HttpMethod. + + * `headers`: This map contains the header field names and values. Repeated headers are not supported, but a header value can contain commas. + + * `oauth_token`: Contains information needed for generating an OAuth token. This type of authorization should be used when sending requests to a GCP endpoint. + + * `service_account_email`: Service account email to be used for generating OAuth token. The service account must be within the same project as the job. + + * `scope`: OAuth scope to be used for generating OAuth access token. If not specified, "https://www.googleapis.com/auth/cloud-platform" will be used. + + * `oidc_token`: Contains information needed for generating an OpenID Connect token. This type of authorization should be used when sending requests to third party endpoints or Cloud Run. + + * `service_account_email`: Service account email to be used for generating OAuth token. The service account must be within the same project as the job. + + * `audience`: Audience to be used when generating OIDC token. If not specified, the URI specified in target will be used. + + * `region`: Region where the scheduler job resides + + +## GCP Permissions diff --git a/docs/resources/google_cloud_scheduler_jobs.md b/docs/resources/google_cloud_scheduler_jobs.md new file mode 100644 index 000000000..d420a6a3c --- /dev/null +++ b/docs/resources/google_cloud_scheduler_jobs.md @@ -0,0 +1,42 @@ +--- +title: About the google_cloud_scheduler_jobs resource +platform: gcp +--- + +## Syntax +A `google_cloud_scheduler_jobs` is used to test a Google Job resource + +## Examples +``` +google_cloud_scheduler_jobs(project: 'chef-gcp-inspec', region: ).names.each do |name| + describe google_cloud_scheduler_job(project: 'chef-gcp-inspec', region: us-central1, name: name) do + it { should exist } + + its('description') { should cmp 'A description' } + its('schedule') { should cmp '*/8 * * * *' } + its('time_zone') { should cmp 'America/New_York' } + its('http_target.http_method') { should cmp 'POST' } + its('http_target.uri') { should cmp 'https://example.com/ping' } + end +end +``` + +## Properties +Properties that can be accessed from the `google_cloud_scheduler_jobs` resource: + +See [google_cloud_scheduler_job.md](google_cloud_scheduler_job.md) for more detailed information + * `names`: an array of `google_cloud_scheduler_job` name + * `descriptions`: an array of `google_cloud_scheduler_job` description + * `schedules`: an array of `google_cloud_scheduler_job` schedule + * `time_zones`: an array of `google_cloud_scheduler_job` time_zone + * `retry_configs`: an array of `google_cloud_scheduler_job` retry_config + * `pubsub_targets`: an array of `google_cloud_scheduler_job` pubsub_target + * `app_engine_http_targets`: an array of `google_cloud_scheduler_job` app_engine_http_target + * `http_targets`: an array of `google_cloud_scheduler_job` http_target + * `regions`: an array of `google_cloud_scheduler_job` region + +## Filter Criteria +This resource supports all of the above properties as filter criteria, which can be used +with `where` as a block or a method. + +## GCP Permissions diff --git a/docs/resources/google_compute_backend_service.md b/docs/resources/google_compute_backend_service.md index 3babec57c..8a3350313 100644 --- a/docs/resources/google_compute_backend_service.md +++ b/docs/resources/google_compute_backend_service.md @@ -36,7 +36,7 @@ Properties that can be accessed from the `google_compute_backend_service` resour * `description`: An optional description of this resource. Provide this property when you create the resource. - * `group`: The fully-qualified URL of an Instance Group or Network Endpoint Group resource. In case of instance group this defines the list of instances that serve traffic. Member virtual machine instances from each instance group must live in the same zone as the instance group itself. No two backends in a backend service are allowed to use same Instance Group resource. For Network Endpoint Groups this defines list of endpoints. All endpoints of Network Endpoint Group must be hosted on instances located in the same zone as the Network Endpoint Group. Backend service can not contain mix of Instance Group and Network Endpoint Group backends. Note that you must specify an Instance Group or Network Endpoint Group resource using the fully-qualified URL, rather than a partial URL. + * `group`: The fully-qualified URL of an Instance Group or Network Endpoint Group resource. In case of instance group this defines the list of instances that serve traffic. Member virtual machine instances from each instance group must live in the same zone as the instance group itself. No two backends in a backend service are allowed to use same Instance Group resource. For Network Endpoint Groups this defines list of endpoints. All endpoints of Network Endpoint Group must be hosted on instances located in the same zone as the Network Endpoint Group. Backend services cannot mix Instance Group and Network Endpoint Group backends. Note that you must specify an Instance Group or Network Endpoint Group resource using the fully-qualified URL, rather than a partial URL. * `max_connections`: The max number of simultaneous connections for the group. Can be used with either CONNECTION or UTILIZATION balancing modes. For CONNECTION mode, either maxConnections or one of maxConnectionsPerInstance or maxConnectionsPerEndpoint, as appropriate for group type, must be set. diff --git a/docs/resources/google_compute_region_backend_service.md b/docs/resources/google_compute_region_backend_service.md index ad5d5e92a..2269ed192 100644 --- a/docs/resources/google_compute_region_backend_service.md +++ b/docs/resources/google_compute_region_backend_service.md @@ -24,33 +24,55 @@ end Properties that can be accessed from the `google_compute_region_backend_service` resource: - * `name`: Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. + * `backends`: The set of backends that serve this RegionBackendService. - * `health_checks`: The list of HealthChecks for checking the health of the backend service. Currently at most one health check can be specified, and a health check is required. + * `balancing_mode`: Specifies the balancing mode for this backend. Defaults to CONNECTION. - * `backends`: The list of backends that serve this RegionBackendService. + * `capacity_scaler`: A multiplier applied to the group's maximum servicing capacity (based on UTILIZATION, RATE or CONNECTION). A setting of 0 means the group is completely drained, offering 0% of its available Capacity. Valid range is [0.0,1.0]. * `description`: An optional description of this resource. Provide this property when you create the resource. - * `group`: The fully-qualified URL of an Instance Group. This defines the list of instances that serve traffic. Member virtual machine instances from each instance group must live in the same zone as the instance group itself. No two backends in a backend service are allowed to use same Instance Group resource. Note that you must specify an Instance Group resource using the fully-qualified URL, rather than a partial URL. The instance group must be within the same region as the BackendService. + * `group`: The fully-qualified URL of an Instance Group or Network Endpoint Group resource. In case of instance group this defines the list of instances that serve traffic. Member virtual machine instances from each instance group must live in the same zone as the instance group itself. No two backends in a backend service are allowed to use same Instance Group resource. For Network Endpoint Groups this defines list of endpoints. All endpoints of Network Endpoint Group must be hosted on instances located in the same zone as the Network Endpoint Group. Backend services cannot mix Instance Group and Network Endpoint Group backends. When the `load_balancing_scheme` is INTERNAL, only instance groups are supported. Note that you must specify an Instance Group or Network Endpoint Group resource using the fully-qualified URL, rather than a partial URL. - * `description`: An optional description of this resource. + * `max_connections`: The max number of simultaneous connections for the group. Can be used with either CONNECTION or UTILIZATION balancing modes. For CONNECTION mode, either maxConnections or one of maxConnectionsPerInstance or maxConnectionsPerEndpoint, as appropriate for group type, must be set. - * `fingerprint`: Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking. + * `max_connections_per_instance`: The max number of simultaneous connections that a single backend instance can handle. This is used to calculate the capacity of the group. Can be used in either CONNECTION or UTILIZATION balancing modes. For CONNECTION mode, either maxConnections or maxConnectionsPerInstance must be set. - * `protocol`: The protocol this BackendService uses to communicate with backends. The possible values are TCP and UDP, and the default is TCP. + * `max_connections_per_endpoint`: The max number of simultaneous connections that a single backend network endpoint can handle. This is used to calculate the capacity of the group. Can be used in either CONNECTION or UTILIZATION balancing modes. For CONNECTION mode, either maxConnections or maxConnectionsPerEndpoint must be set. - * `session_affinity`: Type of session affinity to use. The default is NONE. Can be NONE, CLIENT_IP, CLIENT_IP_PROTO, or CLIENT_IP_PORT_PROTO. When the protocol is UDP, this field is not used. + * `max_rate`: The max requests per second (RPS) of the group. Can be used with either RATE or UTILIZATION balancing modes, but required if RATE mode. Either maxRate or one of maxRatePerInstance or maxRatePerEndpoint, as appropriate for group type, must be set. - * `region`: The region where the regional backend service resides. + * `max_rate_per_instance`: The max requests per second (RPS) that a single backend instance can handle. This is used to calculate the capacity of the group. Can be used in either balancing mode. For RATE mode, either maxRate or maxRatePerInstance must be set. - * `timeout_sec`: How many seconds to wait for the backend before considering it a failed request. Default is 30 seconds. Valid range is [1, 86400]. + * `max_rate_per_endpoint`: The max requests per second (RPS) that a single backend network endpoint can handle. This is used to calculate the capacity of the group. Can be used in either balancing mode. For RATE mode, either maxRate or maxRatePerEndpoint must be set. + + * `max_utilization`: Used when balancingMode is UTILIZATION. This ratio defines the CPU utilization target for the group. Valid range is [0.0, 1.0]. * `connection_draining`: Settings for connection draining * `draining_timeout_sec`: Time for which instance will be drained (not accept new connections, but still work to finish started). - * `load_balancing_scheme`: This signifies what the ForwardingRule will be used for and can only be INTERNAL for RegionBackendServices + * `creation_timestamp`: Creation timestamp in RFC3339 text format. + + * `description`: An optional description of this resource. + + * `fingerprint`: Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking. + + * `health_checks`: The set of URLs to HealthCheck resources for health checking this RegionBackendService. Currently at most one health check can be specified, and a health check is required. + + * `id`: The unique identifier for the resource. + + * `load_balancing_scheme`: Indicates what kind of load balancing this regional backend service will be used for. A backend service created for one type of load balancing cannot be used with the other(s). Must be `INTERNAL` or `INTERNAL_MANAGED`. Defaults to `INTERNAL`. + + * `name`: Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash. + + * `protocol`: The protocol this RegionBackendService uses to communicate with backends. Possible values are HTTP, HTTPS, HTTP2, SSL, TCP, and UDP. The default is HTTP. **NOTE**: HTTP2 is only valid for beta HTTP/2 load balancer types and may result in errors if used with the GA API. + + * `session_affinity`: Type of session affinity to use. The default is NONE. Session affinity is not applicable if the protocol is UDP. + + * `timeout_sec`: How many seconds to wait for the backend before considering it a failed request. Default is 30 seconds. Valid range is [1, 86400]. + + * `region`: A reference to the region where the regional backend service resides. ## GCP Permissions diff --git a/docs/resources/google_compute_region_backend_services.md b/docs/resources/google_compute_region_backend_services.md index ddb66832a..6e6a98fba 100644 --- a/docs/resources/google_compute_region_backend_services.md +++ b/docs/resources/google_compute_region_backend_services.md @@ -20,17 +20,19 @@ end Properties that can be accessed from the `google_compute_region_backend_services` resource: See [google_compute_region_backend_service.md](google_compute_region_backend_service.md) for more detailed information - * `names`: an array of `google_compute_region_backend_service` name - * `health_checks`: an array of `google_compute_region_backend_service` health_checks * `backends`: an array of `google_compute_region_backend_service` backends + * `connection_drainings`: an array of `google_compute_region_backend_service` connection_draining + * `creation_timestamps`: an array of `google_compute_region_backend_service` creation_timestamp * `descriptions`: an array of `google_compute_region_backend_service` description * `fingerprints`: an array of `google_compute_region_backend_service` fingerprint + * `health_checks`: an array of `google_compute_region_backend_service` health_checks + * `ids`: an array of `google_compute_region_backend_service` id + * `load_balancing_schemes`: an array of `google_compute_region_backend_service` load_balancing_scheme + * `names`: an array of `google_compute_region_backend_service` name * `protocols`: an array of `google_compute_region_backend_service` protocol * `session_affinities`: an array of `google_compute_region_backend_service` session_affinity - * `regions`: an array of `google_compute_region_backend_service` region * `timeout_secs`: an array of `google_compute_region_backend_service` timeout_sec - * `connection_drainings`: an array of `google_compute_region_backend_service` connection_draining - * `load_balancing_schemes`: an array of `google_compute_region_backend_service` load_balancing_scheme + * `regions`: an array of `google_compute_region_backend_service` region ## Filter Criteria This resource supports all of the above properties as filter criteria, which can be used diff --git a/libraries/google/cloudscheduler/property/job_app_engine_http_target.rb b/libraries/google/cloudscheduler/property/job_app_engine_http_target.rb new file mode 100644 index 000000000..baaf75d9a --- /dev/null +++ b/libraries/google/cloudscheduler/property/job_app_engine_http_target.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +require 'google/cloudscheduler/property/job_app_engine_http_target_app_engine_routing' +module GoogleInSpec + module CloudScheduler + module Property + class JobAppEngineHttpTarget + attr_reader :http_method + + attr_reader :app_engine_routing + + attr_reader :relative_uri + + attr_reader :body + + attr_reader :headers + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @http_method = args['httpMethod'] + @app_engine_routing = GoogleInSpec::CloudScheduler::Property::JobAppEngineHttpTargetAppEngineRouting.new(args['appEngineRouting'], to_s) + @relative_uri = args['relativeUri'] + @body = args['body'] + @headers = args['headers'] + end + + def to_s + "#{@parent_identifier} JobAppEngineHttpTarget" + end + end + end + end +end diff --git a/libraries/google/cloudscheduler/property/job_app_engine_http_target_app_engine_routing.rb b/libraries/google/cloudscheduler/property/job_app_engine_http_target_app_engine_routing.rb new file mode 100644 index 000000000..68774b39a --- /dev/null +++ b/libraries/google/cloudscheduler/property/job_app_engine_http_target_app_engine_routing.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module CloudScheduler + module Property + class JobAppEngineHttpTargetAppEngineRouting + attr_reader :service + + attr_reader :version + + attr_reader :instance + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @service = args['service'] + @version = args['version'] + @instance = args['instance'] + end + + def to_s + "#{@parent_identifier} JobAppEngineHttpTargetAppEngineRouting" + end + end + end + end +end diff --git a/libraries/google/cloudscheduler/property/job_http_target.rb b/libraries/google/cloudscheduler/property/job_http_target.rb new file mode 100644 index 000000000..1724dbf0c --- /dev/null +++ b/libraries/google/cloudscheduler/property/job_http_target.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +require 'google/cloudscheduler/property/job_http_target_oauth_token' +require 'google/cloudscheduler/property/job_http_target_oidc_token' +module GoogleInSpec + module CloudScheduler + module Property + class JobHttpTarget + attr_reader :uri + + attr_reader :http_method + + attr_reader :body + + attr_reader :headers + + attr_reader :oauth_token + + attr_reader :oidc_token + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @uri = args['uri'] + @http_method = args['httpMethod'] + @body = args['body'] + @headers = args['headers'] + @oauth_token = GoogleInSpec::CloudScheduler::Property::JobHttpTargetOauthToken.new(args['oauthToken'], to_s) + @oidc_token = GoogleInSpec::CloudScheduler::Property::JobHttpTargetOidcToken.new(args['oidcToken'], to_s) + end + + def to_s + "#{@parent_identifier} JobHttpTarget" + end + end + end + end +end diff --git a/libraries/google/cloudscheduler/property/job_http_target_oauth_token.rb b/libraries/google/cloudscheduler/property/job_http_target_oauth_token.rb new file mode 100644 index 000000000..69e5a45ea --- /dev/null +++ b/libraries/google/cloudscheduler/property/job_http_target_oauth_token.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module CloudScheduler + module Property + class JobHttpTargetOauthToken + attr_reader :service_account_email + + attr_reader :scope + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @service_account_email = args['serviceAccountEmail'] + @scope = args['scope'] + end + + def to_s + "#{@parent_identifier} JobHttpTargetOauthToken" + end + end + end + end +end diff --git a/libraries/google/cloudscheduler/property/job_http_target_oidc_token.rb b/libraries/google/cloudscheduler/property/job_http_target_oidc_token.rb new file mode 100644 index 000000000..551f768ef --- /dev/null +++ b/libraries/google/cloudscheduler/property/job_http_target_oidc_token.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module CloudScheduler + module Property + class JobHttpTargetOidcToken + attr_reader :service_account_email + + attr_reader :audience + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @service_account_email = args['serviceAccountEmail'] + @audience = args['audience'] + end + + def to_s + "#{@parent_identifier} JobHttpTargetOidcToken" + end + end + end + end +end diff --git a/libraries/google/cloudscheduler/property/job_pubsub_target.rb b/libraries/google/cloudscheduler/property/job_pubsub_target.rb new file mode 100644 index 000000000..0edd9bcb6 --- /dev/null +++ b/libraries/google/cloudscheduler/property/job_pubsub_target.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module CloudScheduler + module Property + class JobPubsubTarget + attr_reader :topic_name + + attr_reader :data + + attr_reader :attributes + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @topic_name = args['topicName'] + @data = args['data'] + @attributes = args['attributes'] + end + + def to_s + "#{@parent_identifier} JobPubsubTarget" + end + end + end + end +end diff --git a/libraries/google/cloudscheduler/property/job_retry_config.rb b/libraries/google/cloudscheduler/property/job_retry_config.rb new file mode 100644 index 000000000..64338beec --- /dev/null +++ b/libraries/google/cloudscheduler/property/job_retry_config.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module CloudScheduler + module Property + class JobRetryConfig + attr_reader :retry_count + + attr_reader :max_retry_duration + + attr_reader :min_backoff_duration + + attr_reader :max_backoff_duration + + attr_reader :max_doublings + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @retry_count = args['retryCount'] + @max_retry_duration = args['maxRetryDuration'] + @min_backoff_duration = args['minBackoffDuration'] + @max_backoff_duration = args['maxBackoffDuration'] + @max_doublings = args['maxDoublings'] + end + + def to_s + "#{@parent_identifier} JobRetryConfig" + end + end + end + end +end diff --git a/libraries/google/compute/property/regionbackendservice_backends.rb b/libraries/google/compute/property/regionbackendservice_backends.rb index f45273875..13d14ef8f 100644 --- a/libraries/google/compute/property/regionbackendservice_backends.rb +++ b/libraries/google/compute/property/regionbackendservice_backends.rb @@ -17,15 +17,42 @@ module GoogleInSpec module Compute module Property class RegionBackendServiceBackends + attr_reader :balancing_mode + + attr_reader :capacity_scaler + attr_reader :description attr_reader :group + attr_reader :max_connections + + attr_reader :max_connections_per_instance + + attr_reader :max_connections_per_endpoint + + attr_reader :max_rate + + attr_reader :max_rate_per_instance + + attr_reader :max_rate_per_endpoint + + attr_reader :max_utilization + def initialize(args = nil, parent_identifier = nil) return if args.nil? @parent_identifier = parent_identifier + @balancing_mode = args['balancingMode'] + @capacity_scaler = args['capacityScaler'] @description = args['description'] @group = args['group'] + @max_connections = args['maxConnections'] + @max_connections_per_instance = args['maxConnectionsPerInstance'] + @max_connections_per_endpoint = args['maxConnectionsPerEndpoint'] + @max_rate = args['maxRate'] + @max_rate_per_instance = args['maxRatePerInstance'] + @max_rate_per_endpoint = args['maxRatePerEndpoint'] + @max_utilization = args['maxUtilization'] end def to_s diff --git a/libraries/google_cloud_scheduler_job.rb b/libraries/google_cloud_scheduler_job.rb new file mode 100644 index 000000000..710aff7bd --- /dev/null +++ b/libraries/google_cloud_scheduler_job.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +require 'gcp_backend' +require 'google/cloudscheduler/property/job_app_engine_http_target' +require 'google/cloudscheduler/property/job_app_engine_http_target_app_engine_routing' +require 'google/cloudscheduler/property/job_http_target' +require 'google/cloudscheduler/property/job_http_target_oauth_token' +require 'google/cloudscheduler/property/job_http_target_oidc_token' +require 'google/cloudscheduler/property/job_pubsub_target' +require 'google/cloudscheduler/property/job_retry_config' + +# A provider to manage Cloud Scheduler resources. +class CloudSchedulerJob < GcpResourceBase + name 'google_cloud_scheduler_job' + desc 'Job' + supports platform: 'gcp' + + attr_reader :params + attr_reader :name + attr_reader :description + attr_reader :schedule + attr_reader :time_zone + attr_reader :retry_config + attr_reader :pubsub_target + attr_reader :app_engine_http_target + attr_reader :http_target + attr_reader :region + + def initialize(params) + super(params.merge({ use_http_transport: true })) + @params = params + @fetched = @connection.fetch(product_url, resource_base_url, params, 'Get') + parse unless @fetched.nil? + end + + def parse + @name = @fetched['name'] + @description = @fetched['description'] + @schedule = @fetched['schedule'] + @time_zone = @fetched['timeZone'] + @retry_config = GoogleInSpec::CloudScheduler::Property::JobRetryConfig.new(@fetched['retryConfig'], to_s) + @pubsub_target = GoogleInSpec::CloudScheduler::Property::JobPubsubTarget.new(@fetched['pubsubTarget'], to_s) + @app_engine_http_target = GoogleInSpec::CloudScheduler::Property::JobAppEngineHttpTarget.new(@fetched['appEngineHttpTarget'], to_s) + @http_target = GoogleInSpec::CloudScheduler::Property::JobHttpTarget.new(@fetched['httpTarget'], to_s) + @region = @fetched['region'] + end + + # Handles parsing RFC3339 time string + def parse_time_string(time_string) + time_string ? Time.parse(time_string) : nil + end + + def exists? + !@fetched.nil? + end + + def to_s + "Job #{@params[:name]}" + end + + private + + def product_url + 'https://cloudscheduler.googleapis.com/v1/' + end + + def resource_base_url + 'projects/{{project}}/locations/{{region}}/jobs/{{name}}' + end +end diff --git a/libraries/google_cloud_scheduler_jobs.rb b/libraries/google_cloud_scheduler_jobs.rb new file mode 100644 index 000000000..5d9e28946 --- /dev/null +++ b/libraries/google_cloud_scheduler_jobs.rb @@ -0,0 +1,100 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +require 'gcp_backend' +class CloudSchedulerJobs < GcpResourceBase + name 'google_cloud_scheduler_jobs' + desc 'Job plural resource' + supports platform: 'gcp' + + attr_reader :table + + filter_table_config = FilterTable.create + + filter_table_config.add(:names, field: :name) + filter_table_config.add(:descriptions, field: :description) + filter_table_config.add(:schedules, field: :schedule) + filter_table_config.add(:time_zones, field: :time_zone) + filter_table_config.add(:retry_configs, field: :retry_config) + filter_table_config.add(:pubsub_targets, field: :pubsub_target) + filter_table_config.add(:app_engine_http_targets, field: :app_engine_http_target) + filter_table_config.add(:http_targets, field: :http_target) + filter_table_config.add(:regions, field: :region) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('jobs') + end + + def fetch_wrapped_resource(wrap_path) + # fetch_resource returns an array of responses (to handle pagination) + result = @connection.fetch_all(product_url, resource_base_url, @params, 'Get') + return if result.nil? + + # Conversion of string -> object hash to symbol -> object hash that InSpec needs + converted = [] + result.each do |response| + next if response.nil? || !response.key?(wrap_path) + response[wrap_path].each do |hash| + hash_with_symbols = {} + hash.each_key do |key| + name, value = transform(key, hash) + hash_with_symbols[name] = value + end + converted.push(hash_with_symbols) + end + end + + converted + end + + def transform(key, value) + return transformers[key].call(value) if transformers.key?(key) + + [key.to_sym, value] + end + + def transformers + { + 'name' => ->(obj) { return :name, obj['name'] }, + 'description' => ->(obj) { return :description, obj['description'] }, + 'schedule' => ->(obj) { return :schedule, obj['schedule'] }, + 'timeZone' => ->(obj) { return :time_zone, obj['timeZone'] }, + 'retryConfig' => ->(obj) { return :retry_config, GoogleInSpec::CloudScheduler::Property::JobRetryConfig.new(obj['retryConfig'], to_s) }, + 'pubsubTarget' => ->(obj) { return :pubsub_target, GoogleInSpec::CloudScheduler::Property::JobPubsubTarget.new(obj['pubsubTarget'], to_s) }, + 'appEngineHttpTarget' => ->(obj) { return :app_engine_http_target, GoogleInSpec::CloudScheduler::Property::JobAppEngineHttpTarget.new(obj['appEngineHttpTarget'], to_s) }, + 'httpTarget' => ->(obj) { return :http_target, GoogleInSpec::CloudScheduler::Property::JobHttpTarget.new(obj['httpTarget'], to_s) }, + 'region' => ->(obj) { return :region, obj['region'] }, + } + end + + # Handles parsing RFC3339 time string + def parse_time_string(time_string) + time_string ? Time.parse(time_string) : nil + end + + private + + def product_url + 'https://cloudscheduler.googleapis.com/v1/' + end + + def resource_base_url + 'projects/{{project}}/locations/{{region}}/jobs' + end +end diff --git a/libraries/google_compute_region_backend_service.rb b/libraries/google_compute_region_backend_service.rb index 7dc7b0b46..d1c355f35 100644 --- a/libraries/google_compute_region_backend_service.rb +++ b/libraries/google_compute_region_backend_service.rb @@ -24,17 +24,19 @@ class ComputeRegionBackendService < GcpResourceBase supports platform: 'gcp' attr_reader :params - attr_reader :name - attr_reader :health_checks attr_reader :backends + attr_reader :connection_draining + attr_reader :creation_timestamp attr_reader :description attr_reader :fingerprint + attr_reader :health_checks + attr_reader :id + attr_reader :load_balancing_scheme + attr_reader :name attr_reader :protocol attr_reader :session_affinity - attr_reader :region attr_reader :timeout_sec - attr_reader :connection_draining - attr_reader :load_balancing_scheme + attr_reader :region def initialize(params) super(params.merge({ use_http_transport: true })) @@ -44,17 +46,19 @@ def initialize(params) end def parse - @name = @fetched['name'] - @health_checks = @fetched['healthChecks'] @backends = GoogleInSpec::Compute::Property::RegionBackendServiceBackendsArray.parse(@fetched['backends'], to_s) + @connection_draining = GoogleInSpec::Compute::Property::RegionBackendServiceConnectionDraining.new(@fetched['connectionDraining'], to_s) + @creation_timestamp = parse_time_string(@fetched['creationTimestamp']) @description = @fetched['description'] @fingerprint = @fetched['fingerprint'] + @health_checks = @fetched['healthChecks'] + @id = @fetched['id'] + @load_balancing_scheme = @fetched['loadBalancingScheme'] + @name = @fetched['name'] @protocol = @fetched['protocol'] @session_affinity = @fetched['sessionAffinity'] - @region = @fetched['region'] @timeout_sec = @fetched['timeoutSec'] - @connection_draining = GoogleInSpec::Compute::Property::RegionBackendServiceConnectionDraining.new(@fetched['connectionDraining'], to_s) - @load_balancing_scheme = @fetched['loadBalancingScheme'] + @region = @fetched['region'] end # Handles parsing RFC3339 time string diff --git a/libraries/google_compute_region_backend_services.rb b/libraries/google_compute_region_backend_services.rb index 4afae5db4..5d0103c3a 100644 --- a/libraries/google_compute_region_backend_services.rb +++ b/libraries/google_compute_region_backend_services.rb @@ -23,17 +23,19 @@ class ComputeRegionBackendServices < GcpResourceBase filter_table_config = FilterTable.create - filter_table_config.add(:names, field: :name) - filter_table_config.add(:health_checks, field: :health_checks) filter_table_config.add(:backends, field: :backends) + filter_table_config.add(:connection_drainings, field: :connection_draining) + filter_table_config.add(:creation_timestamps, field: :creation_timestamp) filter_table_config.add(:descriptions, field: :description) filter_table_config.add(:fingerprints, field: :fingerprint) + filter_table_config.add(:health_checks, field: :health_checks) + filter_table_config.add(:ids, field: :id) + filter_table_config.add(:load_balancing_schemes, field: :load_balancing_scheme) + filter_table_config.add(:names, field: :name) filter_table_config.add(:protocols, field: :protocol) filter_table_config.add(:session_affinities, field: :session_affinity) - filter_table_config.add(:regions, field: :region) filter_table_config.add(:timeout_secs, field: :timeout_sec) - filter_table_config.add(:connection_drainings, field: :connection_draining) - filter_table_config.add(:load_balancing_schemes, field: :load_balancing_scheme) + filter_table_config.add(:regions, field: :region) filter_table_config.connect(self, :table) @@ -73,17 +75,19 @@ def transform(key, value) def transformers { - 'name' => ->(obj) { return :name, obj['name'] }, - 'healthChecks' => ->(obj) { return :health_checks, obj['healthChecks'] }, 'backends' => ->(obj) { return :backends, GoogleInSpec::Compute::Property::RegionBackendServiceBackendsArray.parse(obj['backends'], to_s) }, + 'connectionDraining' => ->(obj) { return :connection_draining, GoogleInSpec::Compute::Property::RegionBackendServiceConnectionDraining.new(obj['connectionDraining'], to_s) }, + 'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) }, 'description' => ->(obj) { return :description, obj['description'] }, 'fingerprint' => ->(obj) { return :fingerprint, obj['fingerprint'] }, + 'healthChecks' => ->(obj) { return :health_checks, obj['healthChecks'] }, + 'id' => ->(obj) { return :id, obj['id'] }, + 'loadBalancingScheme' => ->(obj) { return :load_balancing_scheme, obj['loadBalancingScheme'] }, + 'name' => ->(obj) { return :name, obj['name'] }, 'protocol' => ->(obj) { return :protocol, obj['protocol'] }, 'sessionAffinity' => ->(obj) { return :session_affinity, obj['sessionAffinity'] }, - 'region' => ->(obj) { return :region, obj['region'] }, 'timeoutSec' => ->(obj) { return :timeout_sec, obj['timeoutSec'] }, - 'connectionDraining' => ->(obj) { return :connection_draining, GoogleInSpec::Compute::Property::RegionBackendServiceConnectionDraining.new(obj['connectionDraining'], to_s) }, - 'loadBalancingScheme' => ->(obj) { return :load_balancing_scheme, obj['loadBalancingScheme'] }, + 'region' => ->(obj) { return :region, obj['region'] }, } end diff --git a/test/integration/build/gcp-mm.tf b/test/integration/build/gcp-mm.tf index 21678b63f..94b6f7219 100644 --- a/test/integration/build/gcp-mm.tf +++ b/test/integration/build/gcp-mm.tf @@ -209,6 +209,10 @@ variable "spannerdatabase" { type = "map" } +variable "scheduler_job" { + type = "map" +} + resource "google_compute_ssl_policy" "custom-ssl-policy" { name = "${var.ssl_policy["name"]}" @@ -893,3 +897,17 @@ resource "google_spanner_database" "database" { name = "${var.spannerdatabase["name"]}" ddl = ["${var.spannerdatabase["ddl"]}"] } + +resource "google_cloud_scheduler_job" "job" { + project = var.gcp_project_id + region = var.scheduler_job["region"] + name = var.scheduler_job["name"] + description = var.scheduler_job["description"] + schedule = var.scheduler_job["schedule"] + time_zone = var.scheduler_job["time_zone"] + + http_target { + http_method = var.scheduler_job["http_method"] + uri = var.scheduler_job["http_target_uri"] + } +} diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index f4ed2a05b..6f2ce5025 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -342,3 +342,13 @@ spannerdatabase: name: spdatabase instance: spinstance ddl: "CREATE TABLE test (test STRING(MAX),) PRIMARY KEY (test)" + +scheduler_job: + # region must match where the appengine instance is deployed + region: us-central1 + name: job-name + description: A description + schedule: "*/8 * * * *" + time_zone: America/New_York + http_method: POST + http_target_uri: https://example.com/ping diff --git a/test/integration/verify/controls/google_cloud_scheduler_job.rb b/test/integration/verify/controls/google_cloud_scheduler_job.rb new file mode 100644 index 000000000..9a26404a3 --- /dev/null +++ b/test/integration/verify/controls/google_cloud_scheduler_job.rb @@ -0,0 +1,40 @@ +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- + +title 'Test GCP google_cloud_scheduler_job resource.' + +gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') +scheduler_job = attribute('scheduler_job', default: { + "region": "us-central1", + "name": "job-name", + "description": "A description", + "schedule": "*/8 * * * *", + "time_zone": "America/New_York", + "http_method": "POST", + "http_target_uri": "https://example.com/ping" +}, description: 'Cloud Scheduler Job configuration') +control 'google_cloud_scheduler_job-1.0' do + impact 1.0 + title 'google_cloud_scheduler_job resource test' + + describe google_cloud_scheduler_job(project: gcp_project_id, region: scheduler_job['region'], name: scheduler_job['name']) do + it { should exist } + + its('description') { should cmp scheduler_job['description'] } + its('schedule') { should cmp scheduler_job['schedule'] } + its('time_zone') { should cmp scheduler_job['time_zone'] } + its('http_target.http_method') { should cmp scheduler_job['http_method'] } + its('http_target.uri') { should cmp scheduler_job['http_target_uri'] } + end +end diff --git a/test/integration/verify/controls/google_cloud_scheduler_jobs.rb b/test/integration/verify/controls/google_cloud_scheduler_jobs.rb new file mode 100644 index 000000000..12f7b540c --- /dev/null +++ b/test/integration/verify/controls/google_cloud_scheduler_jobs.rb @@ -0,0 +1,42 @@ +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- + +title 'Test GCP google_cloud_scheduler_jobs resource.' + +gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.') +scheduler_job = attribute('scheduler_job', default: { + "region": "us-central1", + "name": "job-name", + "description": "A description", + "schedule": "*/8 * * * *", + "time_zone": "America/New_York", + "http_method": "POST", + "http_target_uri": "https://example.com/ping" +}, description: 'Cloud Scheduler Job configuration') +control 'google_cloud_scheduler_jobs-1.0' do + impact 1.0 + title 'google_cloud_scheduler_jobs resource test' + + google_cloud_scheduler_jobs(project: gcp_project_id, region: scheduler_job['location']).names.each do |name| + describe google_cloud_scheduler_job(project: gcp_project_id, region: scheduler_job['region'], name: name) do + it { should exist } + + its('description') { should cmp scheduler_job['description'] } + its('schedule') { should cmp scheduler_job['schedule'] } + its('time_zone') { should cmp scheduler_job['time_zone'] } + its('http_target.http_method') { should cmp scheduler_job['http_method'] } + its('http_target.uri') { should cmp scheduler_job['http_target_uri'] } + end + end +end