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.
Signed-off-by: Modular Magician <[email protected]>
- Loading branch information
1 parent
6b0cd67
commit bca9641
Showing
3 changed files
with
123 additions
and
0 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,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 |
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,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 |
29 changes: 29 additions & 0 deletions
29
test/integration/verify/controls/google_billing_project_billing_info.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,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 |