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

Add paused attribute to cloud_scheduler_job resource #430

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions docs/resources/google_cloud_scheduler_job.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Properties that can be accessed from the `google_cloud_scheduler_job` resource:

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

* `state`: State of the job.

* `paused`: Sets the job to a paused state. Jobs default to being enabled when this property is not set.

* `attempt_deadline`: The deadline for job attempts. If the request handler does not respond by this deadline then the request is cancelled and the attempt is marked as a DEADLINE_EXCEEDED failure. The failed attempt can be viewed in execution logs. Cloud Scheduler will retry the job according to the RetryConfig. The allowed duration for this deadline is: * For HTTP targets, between 15 seconds and 30 minutes. * For App Engine HTTP targets, between 15 seconds and 24 hours. * **Note**: For PubSub targets, this field is ignored - setting it will introduce an unresolvable diff. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s"

* `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
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/google_cloud_scheduler_jobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ See [google_cloud_scheduler_job.md](google_cloud_scheduler_job.md) for more deta
* `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
* `states`: an array of `google_cloud_scheduler_job` state
* `pauseds`: an array of `google_cloud_scheduler_job` paused
* `attempt_deadlines`: an array of `google_cloud_scheduler_job` attempt_deadline
* `retry_configs`: an array of `google_cloud_scheduler_job` retry_config
* `pubsub_targets`: an array of `google_cloud_scheduler_job` pubsub_target
Expand Down
4 changes: 4 additions & 0 deletions libraries/google_cloud_scheduler_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class CloudSchedulerJob < GcpResourceBase
attr_reader :description
attr_reader :schedule
attr_reader :time_zone
attr_reader :state
attr_reader :paused
attr_reader :attempt_deadline
attr_reader :retry_config
attr_reader :pubsub_target
Expand All @@ -52,6 +54,8 @@ def parse
@description = @fetched['description']
@schedule = @fetched['schedule']
@time_zone = @fetched['timeZone']
@state = @fetched['state']
@paused = @fetched['paused']
Copy link
Contributor

Choose a reason for hiding this comment

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

here paused is an enum value under state.
so when you will try to access @fetched['paused'] it will fail.

Please see the response of the api below:

{
"name": string,
"description": string,
"schedule": string,
"timeZone": string,
"userUpdateTime": string,
"state": enum ([State](https://cloud.google.com/scheduler/docs/reference/rest/v1beta1/projects.locations.jobs#State)),
"status": {
object (Status)
},
"scheduleTime": string,
"lastAttemptTime": string,
"retryConfig": {
object (RetryConfig)
},
"attemptDeadline": string,
"legacyAppEngineCron": boolean,

// Union field target can be only one of the following:
"pubsubTarget": {
object (PubsubTarget)
},
"appEngineHttpTarget": {
object (AppEngineHttpTarget)
},
"httpTarget": {
object (HttpTarget)
}
// End of list of possible types for union field target.
}
api -
response api

state enum has below values:
Enum values

Copy link
Author

Choose a reason for hiding this comment

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

Got it. So if I pull out the stuff related to paused completely, this should work because we'll be able to test if state is equal to PAUSED (in the case of a paused job), right?

Copy link
Author

Choose a reason for hiding this comment

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

Or, since paused is a top level attribute in Terraform itself, should the interface here stay the same, but we should just populate it from @fetched['state']?

Copy link
Author

Choose a reason for hiding this comment

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

If this is something we should implement by making an adjustment in inspec's fork of magic-modules, happy to work on trying to implement it that way too (I didn't know it existed at the time I created this).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes! That is correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes You can contribute to Magic module that will be the right thing to do.

Copy link
Author

@wyardley wyardley Dec 7, 2022

Choose a reason for hiding this comment

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

@sa-progress I think we basically want
GoogleCloudPlatform/magic-modules#6304

I have cherry-picked that in with attribution to the original author (@SarahFrench) as inspec/magic-modules#6

Because the original commit is also under a license that should be compatible, I've signed off on the commit, which I think is all Ok / allowed?

@attempt_deadline = @fetched['attemptDeadline']
@retry_config = GoogleInSpec::CloudScheduler::Property::JobRetryConfig.new(@fetched['retryConfig'], to_s)
@pubsub_target = GoogleInSpec::CloudScheduler::Property::JobPubsubTarget.new(@fetched['pubsubTarget'], to_s)
Expand Down
4 changes: 4 additions & 0 deletions libraries/google_cloud_scheduler_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class CloudSchedulerJobs < GcpResourceBase
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(:states, field: :state)
filter_table_config.add(:pauseds, field: :paused)
filter_table_config.add(:attempt_deadlines, field: :attempt_deadline)
filter_table_config.add(:retry_configs, field: :retry_config)
filter_table_config.add(:pubsub_targets, field: :pubsub_target)
Expand Down Expand Up @@ -76,6 +78,8 @@ def transformers
'description' => ->(obj) { return :description, obj['description'] },
'schedule' => ->(obj) { return :schedule, obj['schedule'] },
'timeZone' => ->(obj) { return :time_zone, obj['timeZone'] },
'state' => ->(obj) { return :state, obj['state'] },
'paused' => ->(obj) { return :paused, obj['paused'] },
'attemptDeadline' => ->(obj) { return :attempt_deadline, obj['attemptDeadline'] },
'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) },
Expand Down