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 support for project billing info #205

Merged
merged 10 commits into from
Nov 18, 2019
30 changes: 30 additions & 0 deletions docs/resources/google_billing_project_billing_info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: About the google_billing_project_billing_info resource
platform: gcp
---

## Syntax
A `google_billing_project_billing_info` is used to test a Google ProjectBillingInfo resource

## Examples
```
describe google_billing_project_billing_info(project_id: 'chef-gcp-inspec') do
it { should exist }

its('billing_account_name') { should eq 'billingAccounts/012345-567890-ABCDEF'}
its('billing_enabled') { should eq true }
end
```

## Properties
Properties that can be accessed from the `google_billing_project_billing_info` resource:


* `project_id`: The project id to retrieve billing info for.

* `billing_account_name`: The resource name of the billing account associated with the project, if any. For example, `billingAccounts/012345-567890-ABCDEF`.

* `billing_enabled`: True if the project is associated with an open billing account, to which usage on the project is charged. False if the project is associated with a closed billing account, or no billing account at all, and therefore cannot use paid services.


## GCP Permissions
2 changes: 1 addition & 1 deletion docs/resources/google_compute_backend_bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Properties that can be accessed from the `google_compute_backend_bucket` resourc

* `cdn_policy`: Cloud CDN configuration for this Backend Bucket.

* `signed_url_cache_max_age_sec`: Maximum number of seconds the response to a signed URL request will be considered fresh. Defaults to 1hr (3600s). After this time period, the response will be revalidated before being served. When serving responses to signed URL requests, Cloud CDN will internally behave as though all responses from this backend had a "Cache-Control: public, max-age=[TTL]" header, regardless of any existing Cache-Control header. The actual headers served in responses will not be altered.
* `signed_url_cache_max_age_sec`: Maximum number of seconds the response to a signed URL request will be considered fresh. After this time period, the response will be revalidated before being served. When serving responses to signed URL requests, Cloud CDN will internally behave as though all responses from this backend had a "Cache-Control: public, max-age=[TTL]" header, regardless of any existing Cache-Control header. The actual headers served in responses will not be altered.

* `creation_timestamp`: Creation timestamp in RFC3339 text format.

Expand Down
16 changes: 15 additions & 1 deletion docs/resources/google_project_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,24 @@ Properties that can be accessed from the `google_project_service` resource:

* `name`: The resource name of the service

* `parent`: The name of the parent of this service. For example: `projects/123`
* `parent`: The name of the parent of this service. For example 'projects/123'

* `state`: Whether or not the service has been enabled for use by the consumer.

* `disable_dependent_services`: Indicates if dependent services should also be disabled. Can only be turned on if service is disabled.

* `config`: The service configuration of the available service.

* `name`: The DNS address at which this service is available.

* `title`: The product title for this service

* `apis`: The list of API interfaces exported by this service.

* `name`: Name of the API

* `version`: The version of the API


## GCP Permissions

Expand Down
2 changes: 2 additions & 0 deletions docs/resources/google_project_services.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ See [google_project_service.md](google_project_service.md) for more detailed inf
* `names`: an array of `google_project_service` name
* `parents`: an array of `google_project_service` parent
* `states`: an array of `google_project_service` state
* `disable_dependent_services`: an array of `google_project_service` disable_dependent_services
* `configs`: an array of `google_project_service` config

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/google_pubsub_subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Properties that can be accessed from the `google_pubsub_subscription` resource:

* `retain_acked_messages`: Indicates whether to retain acknowledged messages. If `true`, then messages are not expunged from the subscription's backlog, even if they are acknowledged, until they fall out of the messageRetentionDuration window.

* `expiration_policy`: A policy that specifies the conditions for this subscription's expiration. A subscription is considered active as long as any connected subscriber is successfully consuming messages from the subscription or is issuing operations on the subscription. If expirationPolicy is not set, a default policy with ttl of 31 days will be used. If it is set but left empty, the resource never expires. The minimum allowed value for expirationPolicy.ttl is 1 day.
* `expiration_policy`: A policy that specifies the conditions for this subscription's expiration. A subscription is considered active as long as any connected subscriber is successfully consuming messages from the subscription or is issuing operations on the subscription. If expirationPolicy is not set, a default policy with ttl of 31 days will be used. If it is set but ttl is "", the resource never expires. The minimum allowed value for expirationPolicy.ttl is 1 day.

* `ttl`: Specifies the "time-to-live" duration for an associated resource. The resource expires if it is not active for a period of ttl. If ttl is not set, the associated resource never expires. A duration in seconds with up to nine fractional digits, terminated by 's'. Example - "3.5s".

Expand Down
41 changes: 41 additions & 0 deletions libraries/google/serviceusage/property/service_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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/serviceusage/property/service_config_apis'
module GoogleInSpec
module ServiceUsage
module Property
class ServiceConfig
attr_reader :name

attr_reader :title

attr_reader :apis

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@name = args['name']
@title = args['title']
@apis = GoogleInSpec::ServiceUsage::Property::ServiceConfigApisArray.parse(args['apis'], to_s)
end

def to_s
"#{@parent_identifier} ServiceConfig"
end
end
end
end
end
45 changes: 45 additions & 0 deletions libraries/google/serviceusage/property/service_config_apis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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 ServiceUsage
module Property
class ServiceConfigApis
attr_reader :name

attr_reader :version

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@name = args['name']
@version = args['version']
end

def to_s
"#{@parent_identifier} ServiceConfigApis"
end
end

class ServiceConfigApisArray
def self.parse(value, parent_identifier)
return if value.nil?
return ServiceConfigApis.new(value, parent_identifier) unless value.is_a?(::Array)
value.map { |v| ServiceConfigApis.new(v, parent_identifier) }
end
end
end
end
end
64 changes: 64 additions & 0 deletions libraries/google_billing_project_billing_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 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'

# A provider to manage Cloud Billing resources.
class BillingProjectBillingInfo < GcpResourceBase
name 'google_billing_project_billing_info'
desc 'ProjectBillingInfo'
supports platform: 'gcp'

attr_reader :params
attr_reader :project_id
attr_reader :billing_account_name
attr_reader :billing_enabled

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
@project_id = @fetched['projectId']
@billing_account_name = @fetched['billingAccountName']
@billing_enabled = @fetched['billingEnabled']
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
"ProjectBillingInfo #{@params[:projectId]}"
end

private

def product_url
'https://cloudbilling.googleapis.com/v1/'
end

def resource_base_url
'projects/{{project_id}}/billingInfo'
end
end
6 changes: 6 additions & 0 deletions libraries/google_project_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
require 'google/serviceusage/property/service_config'
require 'google/serviceusage/property/service_config_apis'

# A provider to manage Service Usage resources.
class ServiceUsageService < GcpResourceBase
Expand All @@ -25,6 +27,8 @@ class ServiceUsageService < GcpResourceBase
attr_reader :name
attr_reader :parent
attr_reader :state
attr_reader :disable_dependent_services
attr_reader :config

def initialize(params)
super(params.merge({ use_http_transport: true }))
Expand All @@ -37,6 +41,8 @@ def parse
@name = @fetched['name']
@parent = @fetched['parent']
@state = @fetched['state']
@disable_dependent_services = @fetched['disableDependentServices']
@config = GoogleInSpec::ServiceUsage::Property::ServiceConfig.new(@fetched['config'], to_s)
end

# Handles parsing RFC3339 time string
Expand Down
4 changes: 4 additions & 0 deletions libraries/google_project_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class ServiceUsageServices < GcpResourceBase
filter_table_config.add(:names, field: :name)
filter_table_config.add(:parents, field: :parent)
filter_table_config.add(:states, field: :state)
filter_table_config.add(:disable_dependent_services, field: :disable_dependent_services)
filter_table_config.add(:configs, field: :config)

filter_table_config.connect(self, :table)

Expand Down Expand Up @@ -68,6 +70,8 @@ def transformers
'name' => ->(obj) { return :name, obj['name'] },
'parent' => ->(obj) { return :parent, obj['parent'] },
'state' => ->(obj) { return :state, obj['state'] },
'disableDependentServices' => ->(obj) { return :disable_dependent_services, obj['disableDependentServices'] },
'config' => ->(obj) { return :config, GoogleInSpec::ServiceUsage::Property::ServiceConfig.new(obj['config'], to_s) },
}
end

Expand Down
2 changes: 1 addition & 1 deletion test/integration/build/gcp-mm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ resource "google_cloudfunctions_function" "function" {
trigger_http = "${var.cloudfunction["trigger_http"]}"
timeout = "${var.cloudfunction["timeout"]}"
entry_point = "${var.cloudfunction["entry_point"]}"
runtime = "nodejs6"
runtime = "nodejs8"

environment_variables = {
MY_ENV_VAR = "${var.cloudfunction["env_var_value"]}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ----------------------------------------------------------------------------
#
# *** 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_billing_project_billing_info resource.'

gcp_project_id = attribute(:gcp_project_id, default: 'gcp_project_id', description: 'The GCP project identifier.')
gcp_enable_privileged_resources = attribute(:gcp_enable_privileged_resources, default:0, description:'Flag to enable privileged resources requiring elevated privileges in GCP.')
control 'google_billing_project_billing_info-1.0' do
impact 1.0
title 'google_billing_project_billing_info resource test'

only_if { gcp_enable_privileged_resources.to_i == 1 && gcp_organization_id != ''}
describe google_billing_project_billing_info(project_id: gcp_project_id) do
it { should exist }

its('billing_account_name') { should eq 'billingAccounts/012345-567890-ABCDEF'}
its('billing_enabled') { should eq true }
end
end