Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Add cloudbuild trigger InSpec resource
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
slevenick authored and modular-magician committed Jan 22, 2019
1 parent 9d25ef9 commit cfb5715
Show file tree
Hide file tree
Showing 13 changed files with 512 additions and 8 deletions.
65 changes: 65 additions & 0 deletions docs/resources/google_cloudbuild_trigger.md
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.
43 changes: 43 additions & 0 deletions docs/resources/google_cloudbuild_triggers.md
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.
10 changes: 6 additions & 4 deletions docs/resources/google_pubsub_topics.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ A `google_pubsub_topics` is used to test a Google Topic resource
describe google_pubsub_topics(project: 'chef-gcp-inspec') do
it { should exist }
its('names') { should include 'inspec-gcp-topic' }
its('count') { should eq 1 }
its('count') { should eq 2 }
end
google_pubsub_topics(project: 'chef-gcp-inspec').names.each do |topic_name|
describe google_pubsub_topic(project: 'chef-gcp-inspec', name: topic_name) do
its('name') { should eq 'inspec-gcp-topic' }
describe.one do
google_pubsub_topics(project: 'chef-gcp-inspec').names.each do |topic_name|
describe google_pubsub_topic(project: 'chef-gcp-inspec', name: topic_name) do
its('name') { should eq 'inspec-gcp-topic' }
end
end
end
```
Expand Down
36 changes: 36 additions & 0 deletions libraries/google/cloudbuild/property/trigger_build.rb
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
40 changes: 40 additions & 0 deletions libraries/google/cloudbuild/property/trigger_steps.rb
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 libraries/google/cloudbuild/property/trigger_trigger_template.rb
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
72 changes: 72 additions & 0 deletions libraries/google_cloudbuild_trigger.rb
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
Loading

0 comments on commit cfb5715

Please sign in to comment.