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

Commit

Permalink
Inspec cloudbilling support
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
slevenick authored and modular-magician committed Nov 13, 2019
1 parent 6b0cd67 commit bca9641
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
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
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ----------------------------------------------------------------------------
#
# *** 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.')
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

0 comments on commit bca9641

Please sign in to comment.