Skip to content

Commit

Permalink
Merge branch 'master' into compute-typo
Browse files Browse the repository at this point in the history
  • Loading branch information
drebes authored Nov 9, 2018
2 parents 93d4223 + 9360ce3 commit f73f8e1
Show file tree
Hide file tree
Showing 54 changed files with 1,159 additions and 277 deletions.
73 changes: 73 additions & 0 deletions .ci/acceptance-tests/inspec-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

set -e
set -x

function cleanup {
cd $TF_PATH
./terraform destroy -auto-approve
}

# Service account credentials for GCP to allow terraform to work
export GOOGLE_CLOUD_KEYFILE_JSON="/tmp/google-account.json"
# Setup GOPATH
export GOPATH=${PWD}/go

# CI sets the contents of our json account secret in our environment; dump it
# to disk for use in tests.
echo "${TERRAFORM_KEY}" > /tmp/google-account.json

git clone https://github.com/slevenick/inspec-gcp.git

# new train plugin not published yet, install locally for now
pushd inspec-gcp
bundle
inspec plugin install train-gcp2/lib/train-gcp2.rb

popd

pushd inspec-gcp/test/integration

# Generate tfvars
pushd attributes
ruby compile_vars.rb > terraform.tfvars
mv terraform.tfvars ../terraform
popd

# Run terraform
pushd terraform
wget https://releases.hashicorp.com/terraform/0.11.10/terraform_0.11.10_linux_amd64.zip
apt-get install unzip
unzip terraform_0.11.10_linux_amd64.zip
./terraform init
./terraform plan

export TF_PATH=${PWD}
trap cleanup EXIT
./terraform apply -auto-approve
export GOOGLE_APPLICATION_CREDENTIALS="${PWD}/inspec.json"
inspec detect -t gcp2://
popd

# Copy inspec resources
pushd inspec-mm
cp -r ../../../libraries libraries
popd

# Run inspec
bundle

# Service accounts take several minutes to be authorized everywhere
set +e

for i in {1..50}
do
inspec exec inspec-mm --attrs=attributes/attributes.yaml -t gcp2://
if [ "$?" -eq "0" ]; then
exit 0
fi
done
set -e

popd
exit 100
13 changes: 13 additions & 0 deletions .ci/acceptance-tests/inspec-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
platform: linux

inputs:
- name: magic-modules-new-prs

image_resource:
type: docker-image
source:
repository: nmckinley/go-ruby-python
tag: '1.11-2.5.1-2.7'

run:
path: magic-modules-new-prs/.ci/acceptance-tests/inspec-integration.sh
7 changes: 7 additions & 0 deletions .ci/ci.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,10 @@ jobs:
merge:
method: squash
commit_msg: mm-output/commit_message
- name: inspec-integration-test
plan:
- get: magic-modules-new-prs
- task: inspec-integration
file: magic-modules-new-prs/.ci/acceptance-tests/inspec-integration.yml
params:
TERRAFORM_KEY: ((terraform-key))
2 changes: 1 addition & 1 deletion build/inspec
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
8 changes: 4 additions & 4 deletions products/compute/inspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ overrides: !ruby/object:Provider::ResourceOverrides
HttpsHealthCheck: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
Image: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
exclude: false
InstanceGroup: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
InstanceGroupManager: !ruby/object:Provider::Inspec::ResourceOverride
Expand All @@ -64,9 +64,9 @@ overrides: !ruby/object:Provider::ResourceOverrides
MachineType: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
Network: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
exclude: false
Region: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
exclude: false
RegionAutoscaler: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
RegionDisk: !ruby/object:Provider::Inspec::ResourceOverride
Expand All @@ -84,7 +84,7 @@ overrides: !ruby/object:Provider::ResourceOverrides
SslPolicy: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
Subnetwork: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
exclude: false
TargetHttpProxy: !ruby/object:Provider::Inspec::ResourceOverride
exclude: true
TargetHttpsProxy: !ruby/object:Provider::Inspec::ResourceOverride
Expand Down
3 changes: 0 additions & 3 deletions products/pubsub/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
# This is where custom code would be defined eventually.
objects: !ruby/object:Api::Resource::HashArray

# This is for a list of example files.
examples: !ruby/object:Api::Resource::HashArray

# This is for copying files over
files: !ruby/object:Provider::Config::Files
# All of these files will be copied verbatim.
Expand Down
5 changes: 4 additions & 1 deletion products/redis/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ objects:
description: Resource labels to represent user provided metadata.
- !ruby/object:Api::Type::KeyValuePairs
name: 'redisConfigs'
description: Redis configuration parameters, according to http://redis.io/topics/config.
description: |
Redis configuration parameters, according to http://redis.io/topics/config.
Currently, the only supported parameters are maxmemory-policy and notify-keyspace-events
(https://cloud.google.com/memorystore/docs/redis/reference/rest/v1/projects.locations.instances#Instance.FIELDS.redis_configs).
- !ruby/object:Api::Type::String
name: locationId
description: |
Expand Down
1 change: 0 additions & 1 deletion products/resourcemanager/ansible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ overrides: !ruby/object:Provider::ResourceOverrides
Project: !ruby/object:Provider::Ansible::ResourceOverride
return_if_object: |
<%= lines(indent(compile('products/resourcemanager/helpers/ansible/return_if_object.py'), 6)) -%>
examples: !ruby/object:Api::Resource::HashArray
files: !ruby/object:Provider::Config::Files
copy:
<%= lines(indent(compile('provider/ansible/common~copy.yaml'), 4)) -%>
Expand Down
1 change: 0 additions & 1 deletion provider/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class Config < Api::Object
attr_reader :overrides
# Overrides for datasources
attr_reader :datasources
attr_reader :examples
attr_reader :properties # TODO(nelsonjr): Remove this once bug 193 is fixed.
attr_reader :tests
attr_reader :files
Expand Down
21 changes: 0 additions & 21 deletions provider/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def generate(output_folder, types, version_name)
generate_objects(output_folder, types, version_name)
copy_files(output_folder) \
unless @config.files.nil? || @config.files.copy.nil?
compile_examples(output_folder) unless @config.examples.nil?
compile_changelog(output_folder) unless @config.changelog.nil?
# Compilation has to be the last step, as some files (e.g.
# CONTRIBUTING.md) may depend on the list of all files previously copied
Expand Down Expand Up @@ -127,26 +126,6 @@ def apply_file_acls(output_folder)
end
end

def compile_file_map(output_folder, section, mapper)
create_object_list(section, mapper).each do |o|
compile_file_list(
output_folder,
o
)
end
end

# Creates an object list by calling a lambda
# This can be useful for converting a list of config values to something
# less human-centric.
def create_object_list(section, mapper)
@api.objects
.select { |o| section.key?(o.name) }
.map do |o|
Hash[section[o.name].map { |file| mapper.call(o, file) }]
end
end

def compile_file_list(output_folder, files, data = {})
files.each do |target, source|
Google::LOGGER.debug "Compiling #{source} => #{target}"
Expand Down
4 changes: 2 additions & 2 deletions provider/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def format_url(url)
url.split("\n").join('')
end

# Copies InSpec unit tests to build folder
# Copies InSpec tests to build folder
def generate_resource_tests(data)
target_folder = File.join(data[:output_folder], 'test/unit')
target_folder = File.join(data[:output_folder], 'test')
FileUtils.mkpath target_folder
FileUtils.cp_r 'templates/inspec/tests/.', target_folder
end
Expand Down
90 changes: 90 additions & 0 deletions provider/overrides/resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright 2018 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'google/yaml_validator'

module Provider
module Overrides
# All overrides act as a Hash under-the-hood.
# This class allows them to get access to
# Hash functions + lets the YAML parser import them.
class OverrideResource < Google::YamlValidator
# Used for testing.
def initialize(hash = {})
hash.each { |k, v| instance_variable_set("@#{k}", v) }
end

# All keys in this "hash" are actually instance_variables with
# the @name notation.
# We're abstracting away the @name notation and allowing
# for @name or `name` to be valid.
def [](key)
if key.to_s[0] == '@'
instance_variable_get(key.to_sym)
else
instance_variable_get("@#{key}")
end
end

def empty?
instance_variables.empty?
end

# This allows OverrideResource to take advantage of
# the YAMLValidator's validation without being tied down
# to it.
def validate
instance_variables.each do |var_name|
var = instance_variable_get(var_name)
var.validate if var.respond_to?(:validate)
end
end
end

# A hash of Provider::ResourceOverride objects where the key is the api name
# for that object.
#
# Example usage in a provider.yaml file where you want to extend a resource
# description:
#
# overrides: !ruby/object:Provider::ResourceOverrides
# SomeResource: !ruby/object:Provider::MyProvider::ResourceOverride
# description: '{{description}} A tool-specific description complement'
# parameters:
# someParameter: !ruby/object:Provider::MyProvider::PropertyOverride
# description: 'foobar' # replaces description
# properties:
# someProperty: !ruby/object:Provider::MyProvider::PropertyOverride
# description: 'foobar' # replaces description
# anotherProperty.someNestedProperty:
# !ruby/object:Provider::MyProvider::PropertyOverride
# description: 'baz'
# ...
class ResourceOverrides < OverrideResource
end

# Override to an Api::Resource in api.yaml
class ResourceOverride < OverrideResource
def apply(_resource)
self
end
end

# Override to a Api::Type in api.yaml
class PropertyOverride < OverrideResource
def apply(_resource)
self
end
end
end
end
Loading

0 comments on commit f73f8e1

Please sign in to comment.