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

CHEF-7190-MAGIC-MODULE-compute-PublicDelegatedPrefix - Resource Implementation #471

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions build/inspec/test/integration/build/gcp-mm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1345,42 +1345,3 @@ resource "google_data_loss_prevention_stored_info_type" "basic" {
group_indexes = [2]
}
}







































14 changes: 9 additions & 5 deletions build/inspec/test/integration/configuration/mm-attributes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ssl_policy:
custom_feature: 'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384'
custom_feature2: 'TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384'

topic:
topic:
name: 'inspec-gcp-topic'

subscription:
Expand Down Expand Up @@ -232,7 +232,7 @@ standardappversion:
runtime: nodejs10
entrypoint: "node ./app.js"
port: "8080"

ml_model:
name: ml_model
region: us-central1
Expand Down Expand Up @@ -338,7 +338,7 @@ spannerinstance:
spannerdatabase:
name: spdatabase
instance: spinstance
ddl: "CREATE TABLE test (test STRING(MAX),) PRIMARY KEY (test)"
ddl: "CREATE TABLE test (test STRING(MAX),) PRIMARY KEY (test)"

scheduler_job:
# region must match where the appengine instance is deployed
Expand Down Expand Up @@ -437,7 +437,7 @@ logging_metric:
compute_image:
name: inspec-image
source: https://storage.googleapis.com/bosh-gce-raw-stemcells/bosh-stemcell-97.98-google-kvm-ubuntu-xenial-go_agent-raw-1557960142.tar.gz

security_policy:
name: sec-policy
action: deny(403)
Expand Down Expand Up @@ -492,7 +492,7 @@ sql_database_flag:
applies_to: MYSQL_5_6
allowed_string_values: ON
requires_restart: true

sql_connect:
region: us-central1
database_version: POSTGRES_13
Expand Down Expand Up @@ -536,6 +536,10 @@ dlp:
job_trigger_name: "name1"
job_trigger_display_name: "dp"
job_trigger_description: "description"
deidentify_templates:
name: "dlp-template-inspec"
location: "europe-west2"
type: "Infotype"



Expand Down
48 changes: 36 additions & 12 deletions docs/resources/google_compute_public_delegated_prefix.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,62 @@ A `google_compute_public_delegated_prefix` is used to test a Google PublicDelega

## Examples
```
describe google_compute_public_delegated_prefix(project: 'chef-gcp-inspec', region: 'us-east1-b', name: 'test') do
it { should exist }
end
describe google_compute_public_delegated_prefix(project: 'chef-gcp-inspec', region: ' ', publicDelegatedPrefix: ' ') do
it { should exist }
end
```

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


* `creation_timestamp`: Creation timestamp in RFC3339 text format.This field is deprecated.
* `kind`: Type of the resource. Always compute#publicDelegatedPrefix for public delegated prefixes.

* `description`: An optional description of this resource. Provide this property when you create the resource.
* `id`: string (uint64 format) The unique identifier for the resource type. The server generates this identifier.

* `id`: The unique identifier for the resource.
* `creation_timestamp`: Creation timestamp in RFC3339 text format.

* `name`: Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.
* `name`: Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression [a-z]([-a-z0-9]*[a-z0-9])? which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

* `ip_cidr_range`: The IPv4 address range, in CIDR format, represented by this public delegated prefix.
* `description`: An optional description of this resource. Provide this property when you create the resource.

* `parent_prefix`: The value of requestId if you provided it in the request. Not present otherwise.
* `self_link`: Server-defined URL for the resource.

* `is_live_migration`: If true, the prefix will be live migrated.
* `region`: URL of the region where the public delegated prefix resides. This field applies only to the region resource. You must specify this field as part of the HTTP request URL. It is not settable as a field in the request body.

* `fingerprint`: Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking. This field will be ignored when inserting a new PublicDelegatedPrefix. An up-to-date fingerprint must be provided in order to update the PublicDelegatedPrefix, otherwise the request will fail with error 412 conditionNotMet. To see the latest fingerprint, make a get() request to retrieve a PublicDelegatedPrefix. A base64-encoded string.
* `ip_cidr_range`: The IP address range, in CIDR format, represented by this public delegated prefix.

* `status`: The status of the public delegated prefix, which can be one of following values: * INITIALIZING The public delegated prefix is being initialized and addresses cannot be created yet. * READY_TO_ANNOUNCE The public delegated prefix is a live migration prefix and is active. * ANNOUNCED The public delegated prefix is active. * DELETING The public delegated prefix is being deprovsioned.
* `status`: The status of the public delegated prefix, which can be one of following values: INITIALIZING The public delegated prefix is being initialized and addresses cannot be created yet. READY_TO_ANNOUNCE The public delegated prefix is a live migration prefix and is active. ANNOUNCED The public delegated prefix is active. DELETING The public delegated prefix is being deprovsioned.
Possible values:
* INITIALIZING
* READY_TO_ANNOUNCE
* ANNOUNCED
* DELETING

* `parent_prefix`: The URL of parent prefix. Either PublicAdvertisedPrefix or PublicDelegatedPrefix.

* `public_delegated_sub_prefixs`: object The list of sub public delegated prefixes that exist for this public delegated prefix.

* `name`: The name of the sub public delegated prefix.

* `description`: An optional description of this resource. Provide this property when you create the resource.

* `region`: The region of the sub public delegated prefix if it is regional. If absent, the sub prefix is global.

* `status`: The status of the sub public delegated prefix.
Possible values:
* VALUE_1

* `ip_cidr_range`: The IP address range, in CIDR format, represented by this sub public delegated prefix.

* `delegatee_project`: Name of the project scoping this PublicDelegatedSubPrefix.

* `is_address`: boolean Whether the sub prefix is delegated to create Address resources in the delegatee project.

* `is_live_migration`: boolean If true, the prefix will be live migrated.

* `fingerprint`: string (bytes format) Fingerprint of this resource. A hash of the contents stored in this object. This field is used in optimistic locking. This field will be ignored when inserting a new PublicDelegatedPrefix. An up-to-date fingerprint must be provided in order to update the PublicDelegatedPrefix, otherwise the request will fail with error 412 conditionNotMet. To see the latest fingerprint, make a get() request to retrieve a PublicDelegatedPrefix. A base64-encoded string.


## GCP Permissions

Expand Down
16 changes: 10 additions & 6 deletions docs/resources/google_compute_public_delegated_prefixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ A `google_compute_public_delegated_prefixes` is used to test a Google PublicDele

## Examples
```
describe google_compute_public_delegated_prefixes(project: 'chef-gcp-inspec', region: 'us-east1-b') do
it { should exist }
end
describe google_compute_public_delegated_prefix(project: 'chef-gcp-inspec', region: ' ') do
it { should exist }
end
```

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

See [google_compute_public_delegated_prefix.md](google_compute_public_delegated_prefix.md) for more detailed information
* `creation_timestamps`: an array of `google_compute_public_delegated_prefix` creation_timestamp
* `descriptions`: an array of `google_compute_public_delegated_prefix` description
* `kinds`: an array of `google_compute_public_delegated_prefix` kind
* `ids`: an array of `google_compute_public_delegated_prefix` id
* `creation_timestamps`: an array of `google_compute_public_delegated_prefix` creation_timestamp
* `names`: an array of `google_compute_public_delegated_prefix` name
* `descriptions`: an array of `google_compute_public_delegated_prefix` description
* `self_links`: an array of `google_compute_public_delegated_prefix` self_link
* `regions`: an array of `google_compute_public_delegated_prefix` region
* `ip_cidr_ranges`: an array of `google_compute_public_delegated_prefix` ip_cidr_range
* `statuses`: an array of `google_compute_public_delegated_prefix` status
* `parent_prefixes`: an array of `google_compute_public_delegated_prefix` parent_prefix
* `public_delegated_sub_prefixs`: an array of `google_compute_public_delegated_prefix` public_delegated_sub_prefixs
* `is_live_migrations`: an array of `google_compute_public_delegated_prefix` is_live_migration
* `fingerprints`: an array of `google_compute_public_delegated_prefix` fingerprint
* `statuses`: an array of `google_compute_public_delegated_prefix` status

## Filter Criteria
This resource supports all of the above properties as filter criteria, which can be used
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# frozen_string_literal: false

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# 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 Compute
module Property
class PublicDelegatedPrefixPublicDelegatedSubPrefixs
attr_reader :name

attr_reader :description

attr_reader :region

attr_reader :status

attr_reader :ip_cidr_range

attr_reader :delegatee_project

attr_reader :is_address

def initialize(args = nil, parent_identifier = nil)
return if args.nil?
@parent_identifier = parent_identifier
@name = args['name']
@description = args['description']
@region = args['region']
@status = args['status']
@ip_cidr_range = args['ipCidrRange']
@delegatee_project = args['delegateeProject']
@is_address = args['isAddress']
end

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

class PublicDelegatedPrefixPublicDelegatedSubPrefixsArray
def self.parse(value, parent_identifier)
return if value.nil?
return PublicDelegatedPrefixPublicDelegatedSubPrefixs.new(value, parent_identifier) unless value.is_a?(::Array)
value.map { |v| PublicDelegatedPrefixPublicDelegatedSubPrefixs.new(v, parent_identifier) }
end
end
end
end
end
28 changes: 16 additions & 12 deletions libraries/google_compute_public_delegated_prefix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
require 'google/compute/property/publicdelegatedprefix_public_delegated_sub_prefixs'

# A provider to manage Compute Engine resources.
class ComputePublicDelegatedPrefix < GcpResourceBase
Expand All @@ -22,15 +23,19 @@ class ComputePublicDelegatedPrefix < GcpResourceBase
supports platform: 'gcp'

attr_reader :params
attr_reader :creation_timestamp
attr_reader :description
attr_reader :kind
attr_reader :id
attr_reader :creation_timestamp
attr_reader :name
attr_reader :description
attr_reader :self_link
attr_reader :region
attr_reader :ip_cidr_range
attr_reader :status
attr_reader :parent_prefix
attr_reader :public_delegated_sub_prefixs
attr_reader :is_live_migration
attr_reader :fingerprint
attr_reader :status

def initialize(params)
super(params.merge({ use_http_transport: true }))
Expand All @@ -40,20 +45,19 @@ def initialize(params)
end

def parse
@creation_timestamp = parse_time_string(@fetched['creationTimestamp'])
@description = @fetched['description']
@kind = @fetched['kind']
@id = @fetched['id']
@creation_timestamp = @fetched['creationTimestamp']
@name = @fetched['name']
@description = @fetched['description']
@self_link = @fetched['selfLink']
@region = @fetched['region']
@ip_cidr_range = @fetched['ipCidrRange']
@status = @fetched['status']
@parent_prefix = @fetched['parentPrefix']
@public_delegated_sub_prefixs = GoogleInSpec::Compute::Property::PublicDelegatedPrefixPublicDelegatedSubPrefixsArray.parse(@fetched['publicDelegatedSubPrefixs'], to_s)
@is_live_migration = @fetched['isLiveMigration']
@fingerprint = @fetched['fingerprint']
@status = @fetched['status']
end

# Handles parsing RFC3339 time string
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end

def exists?
Expand All @@ -71,6 +75,6 @@ def product_url(_ = nil)
end

def resource_base_url
'projects/{{project}}/regions/{{region}}/publicDelegatedPrefixes/{{name}}'
'projects/{{project}}/regions/{{region}}/publicDelegatedPrefixes/{{public_delegated_prefix}}/{{name}}'
end
end
27 changes: 15 additions & 12 deletions libraries/google_compute_public_delegated_prefixes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ class ComputePublicDelegatedPrefixs < GcpResourceBase

filter_table_config = FilterTable.create

filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
filter_table_config.add(:descriptions, field: :description)
filter_table_config.add(:kinds, field: :kind)
filter_table_config.add(:ids, field: :id)
filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
filter_table_config.add(:names, field: :name)
filter_table_config.add(:descriptions, field: :description)
filter_table_config.add(:self_links, field: :self_link)
filter_table_config.add(:regions, field: :region)
filter_table_config.add(:ip_cidr_ranges, field: :ip_cidr_range)
filter_table_config.add(:statuses, field: :status)
filter_table_config.add(:parent_prefixes, field: :parent_prefix)
filter_table_config.add(:public_delegated_sub_prefixs, field: :public_delegated_sub_prefixs)
filter_table_config.add(:is_live_migrations, field: :is_live_migration)
filter_table_config.add(:fingerprints, field: :fingerprint)
filter_table_config.add(:statuses, field: :status)

filter_table_config.connect(self, :table)

Expand Down Expand Up @@ -71,30 +75,29 @@ def transform(key, value)

def transformers
{
'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) },
'description' => ->(obj) { return :description, obj['description'] },
'kind' => ->(obj) { return :kind, obj['kind'] },
'id' => ->(obj) { return :id, obj['id'] },
'creationTimestamp' => ->(obj) { return :creation_timestamp, obj['creationTimestamp'] },
'name' => ->(obj) { return :name, obj['name'] },
'description' => ->(obj) { return :description, obj['description'] },
'selfLink' => ->(obj) { return :self_link, obj['selfLink'] },
'region' => ->(obj) { return :region, obj['region'] },
'ipCidrRange' => ->(obj) { return :ip_cidr_range, obj['ipCidrRange'] },
'status' => ->(obj) { return :status, obj['status'] },
'parentPrefix' => ->(obj) { return :parent_prefix, obj['parentPrefix'] },
'publicDelegatedSubPrefixs' => ->(obj) { return :public_delegated_sub_prefixs, GoogleInSpec::Compute::Property::PublicDelegatedPrefixPublicDelegatedSubPrefixsArray.parse(obj['publicDelegatedSubPrefixs'], to_s) },
'isLiveMigration' => ->(obj) { return :is_live_migration, obj['isLiveMigration'] },
'fingerprint' => ->(obj) { return :fingerprint, obj['fingerprint'] },
'status' => ->(obj) { return :status, obj['status'] },
}
end

# Handles parsing RFC3339 time string
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end

private

def product_url(_ = nil)
'https://compute.googleapis.com/compute/v1/'
end

def resource_base_url
'projects/{{project}}/regions/{{region}}/publicDelegatedPrefixes'
'projects/{{project}}/regions/{{region}}/publicDelegatedPrefixes/{{publicDelegatedPrefix}}'
end
end
Loading