This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
forked from inspec/inspec-gcp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cloudbuild trigger InSpec resource
Signed-off-by: Modular Magician <magic-modules@google.com>
- Loading branch information
1 parent
9d25ef9
commit cfb5715
Showing
13 changed files
with
512 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
title: About the Trigger resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_cloudbuild_trigger` is used to test a Google Trigger resource | ||
|
||
## Examples | ||
``` | ||
describe google_cloudbuild_triggers(project: 'chef-gcp-inspec') do | ||
its('count') { should eq 1 } | ||
end | ||
google_cloudbuild_triggers(project: 'chef-gcp-inspec').ids.each do |id| | ||
describe google_cloudbuild_trigger(project: 'chef-gcp-inspec', id: id) do | ||
its('filename') { should eq 'cloudbuild.yaml' } | ||
its('trigger_template.branch_name') { should eq 'trigger-branch' } | ||
its('trigger_template.repo_name') { should eq 'trigger-repo' } | ||
its('trigger_template.project_id') { should eq 'trigger-project' } | ||
end | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_cloudbuild_trigger` resource: | ||
|
||
* `id`: The unique identifier for the trigger. | ||
|
||
* `description`: Human-readable description of the trigger. | ||
|
||
* `disabled`: Whether the trigger is disabled or not. If true, the trigger will never result in a build. | ||
|
||
* `create_time`: Time when the trigger was created. | ||
|
||
* `substitutions`: Substitutions data for Build resource. | ||
|
||
* `filename`: Path, from the source root, to a file whose contents is used for the template. | ||
|
||
* `ignored_files`: ignoredFiles and includedFiles are file glob matches using http://godoc/pkg/path/filepath#Match extended with support for `**`. If ignoredFiles and changed files are both empty, then they are not used to determine whether or not to trigger a build. If ignoredFiles is not empty, then we ignore any files that match any of the ignored_file globs. If the change has no files that are outside of the ignoredFiles globs, then we do not trigger a build. | ||
|
||
* `included_files`: ignoredFiles and includedFiles are file glob matches using http://godoc/pkg/path/filepath#Match extended with support for `**`. If any of the files altered in the commit pass the ignoredFiles filter and includedFiles is empty, then as far as this filter is concerned, we should trigger the build. If any of the files altered in the commit pass the ignoredFiles filter and includedFiles is not empty, then we make sure that at least one of those files matches a includedFiles glob. If not, then we do not trigger a build. | ||
|
||
* `trigger_template`: Template describing the types of source changes to trigger a build. Branch and tag names in trigger templates are interpreted as regular expressions. Any branch or tag change that matches that regular expression will trigger a build. | ||
|
||
* `projectId`: ID of the project that owns the Cloud Source Repository. If omitted, the project ID requesting the build is assumed. | ||
|
||
* `repoName`: Name of the Cloud Source Repository. If omitted, the name "default" is assumed. | ||
|
||
* `dir`: Directory, relative to the source root, in which to run the build. This must be a relative path. If a step's dir is specified and is an absolute path, this value is ignored for that step's execution. | ||
|
||
* `branchName`: Name of the branch to build. | ||
|
||
* `tagName`: Name of the tag to build. | ||
|
||
* `commitSha`: Explicit commit SHA to build. | ||
|
||
* `build`: Contents of the build template. | ||
|
||
* `tags`: Tags for annotation of a Build. These are not docker tags. | ||
|
||
* `images`: A list of images to be pushed upon the successful completion of all build steps. The images are pushed using the builder service account's credentials. The digests of the pushed images will be stored in the Build resource's results field. If any of the images fail to be pushed, the build status is marked FAILURE. | ||
|
||
* `steps`: The operations to be performed on the workspace. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: About the Trigger resource | ||
platform: gcp | ||
--- | ||
|
||
|
||
## Syntax | ||
A `google_cloudbuild_triggers` is used to test a Google Trigger resource | ||
|
||
## Examples | ||
``` | ||
describe google_cloudbuild_triggers(project: 'chef-gcp-inspec') do | ||
its('count') { should eq 1 } | ||
end | ||
google_cloudbuild_triggers(project: 'chef-gcp-inspec').ids.each do |id| | ||
describe google_cloudbuild_trigger(project: 'chef-gcp-inspec', id: id) do | ||
its('filename') { should eq 'cloudbuild.yaml' } | ||
its('trigger_template.branch_name') { should eq 'trigger-branch' } | ||
its('trigger_template.repo_name') { should eq 'trigger-repo' } | ||
its('trigger_template.project_id') { should eq 'trigger-project' } | ||
end | ||
end | ||
``` | ||
|
||
## Properties | ||
Properties that can be accessed from the `google_cloudbuild_triggers` resource: | ||
|
||
See [google_cloudbuild_trigger.md](google_cloudbuild_trigger.md) for more detailed information | ||
* `ids`: an array of `google_cloudbuild_trigger` id | ||
* `descriptions`: an array of `google_cloudbuild_trigger` description | ||
* `disableds`: an array of `google_cloudbuild_trigger` disabled | ||
* `create_times`: an array of `google_cloudbuild_trigger` create_time | ||
* `substitutions`: an array of `google_cloudbuild_trigger` substitutions | ||
* `filenames`: an array of `google_cloudbuild_trigger` filename | ||
* `ignored_files`: an array of `google_cloudbuild_trigger` ignored_files | ||
* `included_files`: an array of `google_cloudbuild_trigger` included_files | ||
* `trigger_templates`: an array of `google_cloudbuild_trigger` trigger_template | ||
* `builds`: an array of `google_cloudbuild_trigger` build | ||
|
||
## 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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/cloudbuild/property/trigger_steps' | ||
module GoogleInSpec | ||
module CloudBuild | ||
module Property | ||
class TriggerBuild | ||
attr_reader :tags | ||
|
||
attr_reader :images | ||
|
||
attr_reader :steps | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@tags = args['tags'] | ||
@images = args['images'] | ||
@steps = GoogleInSpec::CloudBuild::Property::TriggerStepsArray.parse(args['steps']) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 CloudBuild | ||
module Property | ||
class TriggerSteps | ||
attr_reader :name | ||
|
||
attr_reader :args | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@name = args['name'] | ||
@args = args['args'] | ||
end | ||
end | ||
|
||
class TriggerStepsArray | ||
def self.parse(value) | ||
return if value.nil? | ||
return TriggerSteps.new(value) unless value.is_a?(::Array) | ||
value.map { |v| TriggerSteps.new(v) } | ||
end | ||
end | ||
end | ||
end | ||
end |
44 changes: 44 additions & 0 deletions
44
libraries/google/cloudbuild/property/trigger_trigger_template.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# 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 CloudBuild | ||
module Property | ||
class TriggerTriggertemplate | ||
attr_reader :project_id | ||
|
||
attr_reader :repo_name | ||
|
||
attr_reader :dir | ||
|
||
attr_reader :branch_name | ||
|
||
attr_reader :tag_name | ||
|
||
attr_reader :commit_sha | ||
|
||
def initialize(args = nil) | ||
return if args.nil? | ||
@project_id = args['projectId'] | ||
@repo_name = args['repoName'] | ||
@dir = args['dir'] | ||
@branch_name = args['branchName'] | ||
@tag_name = args['tagName'] | ||
@commit_sha = args['commitSha'] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# 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/cloudbuild/property/trigger_build' | ||
require 'google/cloudbuild/property/trigger_steps' | ||
require 'google/cloudbuild/property/trigger_trigger_template' | ||
|
||
# A provider to manage Cloud build resources. | ||
class Trigger < GcpResourceBase | ||
name 'google_cloudbuild_trigger' | ||
desc 'Trigger' | ||
supports platform: 'gcp' | ||
|
||
attr_reader :id | ||
attr_reader :description | ||
attr_reader :disabled | ||
attr_reader :create_time | ||
attr_reader :substitutions | ||
attr_reader :filename | ||
attr_reader :ignored_files | ||
attr_reader :included_files | ||
attr_reader :trigger_template | ||
attr_reader :build | ||
def base | ||
'https://cloudbuild.googleapis.com/v1/' | ||
end | ||
|
||
def url | ||
'projects/{{project}}/triggers/{{id}}' | ||
end | ||
|
||
def initialize(params) | ||
super(params.merge({ use_http_transport: true })) | ||
@fetched = @connection.fetch(base, url, params) | ||
parse unless @fetched.nil? | ||
end | ||
|
||
def parse | ||
@id = @fetched['id'] | ||
@description = @fetched['description'] | ||
@disabled = @fetched['disabled'] | ||
@create_time = parse_time_string(@fetched['createTime']) | ||
@substitutions = @fetched['substitutions'] | ||
@filename = @fetched['filename'] | ||
@ignored_files = @fetched['ignoredFiles'] | ||
@included_files = @fetched['includedFiles'] | ||
@trigger_template = GoogleInSpec::CloudBuild::Property::TriggerTriggertemplate.new(@fetched['triggerTemplate']) | ||
@build = GoogleInSpec::CloudBuild::Property::TriggerBuild.new(@fetched['build']) | ||
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 | ||
end |
Oops, something went wrong.