Skip to content

Commit

Permalink
Merge pull request #539 from inspec/CHEF-7356-MAGIC-MODULE-apigee-Org…
Browse files Browse the repository at this point in the history
…anizations__envgroup

CHEF-7356-MAGIC-MODULE-apigee-Organizations__envgroup - Resource Implementation
  • Loading branch information
sa-progress authored Dec 8, 2023
2 parents caee738 + a140029 commit 33d3c7a
Show file tree
Hide file tree
Showing 9 changed files with 333 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ The following resources are available in the InSpec GCP Profile
| [google_access_context_manager_access_level](docs/resources/google_access_context_manager_access_level.md) | [google_access_context_manager_access_levels](docs/resources/google_access_context_manager_access_levels.md) |
| [google_access_context_manager_access_policy](docs/resources/google_access_context_manager_access_policy.md) | [google_access_context_manager_access_policies](docs/resources/google_access_context_manager_access_policies.md) |
| [google_access_context_manager_service_perimeter](docs/resources/google_access_context_manager_service_perimeter.md) | [google_access_context_manager_service_perimeters](docs/resources/google_access_context_manager_service_perimeters.md) |
| [google_apigeegoogle_apigee_organization_envgroup](docs/resources/google_apigee_organization_envgroup.md) | [google_apigee_organization_envgroups](docs/resources/google_apigee_organization_envgroups.md) |
| [google_appengine_standard_app_version](docs/resources/google_appengine_standard_app_version.md) | [google_appengine_standard_app_versions](docs/resources/google_appengine_standard_app_versions.md) |
| [google_bigquery_dataset](docs/resources/google_bigquery_dataset.md) | [google_bigquery_datasets](docs/resources/google_bigquery_datasets.md) |
| [google_bigquery_table](docs/resources/google_bigquery_table.md) | [google_bigquery_tables](docs/resources/google_bigquery_tables.md) |
Expand Down
50 changes: 50 additions & 0 deletions docs/resources/google_apigee_organization_envgroup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: About the google_apigee_organization_envgroup resource
platform: gcp
---

## Syntax

A `google_apigee_organization_envgroup` is used to test a Google OrganizationEnvgroup resource

## Examples

```
describe google_apigee_organization_envgroup(name: ' value_name') do
it { should exist }
its('name') { should cmp 'value_name' }
its('hostnames') { should include 'value_hostname' }
its('last_modified_at') { should cmp 'value_lastmodifiedat' }
its('state') { should cmp 'value_state' }
its('created_at') { should cmp 'value_createdat' }
end
describe google_apigee_organization_envgroup(name: "does_not_exit") do
it { should_not exist }
end
```

## Properties

Properties that can be accessed from the `google_apigee_organization_envgroup` resource:

* `name`: ID of the environment group.

* `last_modified_at`: The time at which the environment group was last updated as milliseconds since epoch.

* `hostnames`: Host names for this environment group.

* `state`: State of the environment group. Values other than ACTIVE means the resource is not ready to use.

Possible values:
* STATE_UNSPECIFIED
* CREATING
* ACTIVE
* DELETING
* UPDATING

* `created_at`: The time at which the environment group was created as milliseconds since epoch.

## GCP Permissions

Ensure the [Apigee API](https://console.cloud.google.com/apis/library/apigee.googleapis.com/) is enabled for the current project.
36 changes: 36 additions & 0 deletions docs/resources/google_apigee_organization_envgroups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: About the google_apigee_organization_envgroups resource
platform: gcp
---

## Syntax

A `google_apigee_organization_envgroups` is used to test a Google OrganizationEnvgroup resource

## Examples

```
describe google_apigee_organization_envgroups(parent: 'value_parent') do
it { should exist }
end
```

## Properties

Properties that can be accessed from the `google_apigee_organization_envgroups` resource:

See [google_apigee_organization_envgroup.md](google_apigee_organization_envgroup.md) for more detailed information
* `names`: an array of `google_apigee_organization_envgroup` name
* `last_modified_ats`: an array of `google_apigee_organization_envgroup` last_modified_at
* `hostnames`: an array of `google_apigee_organization_envgroup` hostnames
* `states`: an array of `google_apigee_organization_envgroup` state
* `created_ats`: an array of `google_apigee_organization_envgroup` created_at

## Filter Criteria

This resource supports all of the above properties as filter criteria, which can be used
with `where` as a block or a method.

## GCP Permissions

Ensure the [Apigee API](https://console.cloud.google.com/apis/library/apigee.googleapis.com/) is enabled for the current project.
63 changes: 63 additions & 0 deletions libraries/google_apigee_organization_envgroup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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.
#
# ----------------------------------------------------------------------------
require 'gcp_backend'

# A provider to manage Apigee resources.
class ApigeeOrganizationEnvgroup < GcpResourceBase
name 'google_apigee_organization_envgroup'
desc 'OrganizationEnvgroup'
supports platform: 'gcp'

attr_reader :params
attr_reader :name
attr_reader :last_modified_at
attr_reader :hostnames
attr_reader :state
attr_reader :created_at

def initialize(params)
super(params.merge({ use_http_transport: true }))
@params = params
@fetched = @connection.fetch(product_url(params[:beta]), resource_base_url, params, 'Get')
parse unless @fetched.nil?
end

def parse
@name = @fetched['name']
@last_modified_at = @fetched['lastModifiedAt']
@hostnames = @fetched['hostnames']
@state = @fetched['state']
@created_at = @fetched['createdAt']
end

def exists?
!@fetched.nil?
end

def to_s
"OrganizationEnvgroup #{@params[:name]}"
end

private

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

def resource_base_url
'{{name}}'
end
end
87 changes: 87 additions & 0 deletions libraries/google_apigee_organization_envgroups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# 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.
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
class ApigeeOrganizationEnvgroups < GcpResourceBase
name 'google_apigee_organization_envgroups'
desc 'OrganizationEnvgroup plural resource'
supports platform: 'gcp'

attr_reader :table

filter_table_config = FilterTable.create

filter_table_config.add(:names, field: :name)
filter_table_config.add(:last_modified_ats, field: :last_modified_at)
filter_table_config.add(:hostnames, field: :hostnames)
filter_table_config.add(:states, field: :state)
filter_table_config.add(:created_ats, field: :created_at)

filter_table_config.connect(self, :table)

def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('environmentGroups')
end

def fetch_wrapped_resource(wrap_path)
# fetch_resource returns an array of responses (to handle pagination)
result = @connection.fetch_all(product_url, resource_base_url, @params, 'Get')
return if result.nil?

# Conversion of string -> object hash to symbol -> object hash that InSpec needs
converted = []
result.each do |response|
next if response.nil? || !response.key?(wrap_path)
response[wrap_path].each do |hash|
hash_with_symbols = {}
hash.each_key do |key|
name, value = transform(key, hash)
hash_with_symbols[name] = value
end
converted.push(hash_with_symbols)
end
end

converted
end

def transform(key, value)
return transformers[key].call(value) if transformers.key?(key)

[key.to_sym, value]
end

def transformers
{
'name' => ->(obj) { [:name, obj['name']] },
'lastModifiedAt' => ->(obj) { [:last_modified_at, obj['lastModifiedAt']] },
'hostnames' => ->(obj) { [:hostnames, obj['hostnames']] },
'state' => ->(obj) { [:state, obj['state']] },
'createdAt' => ->(obj) { [:created_at, obj['createdAt']] },
}
end

private

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

def resource_base_url
'{{parent}}/envgroups'
end
end
10 changes: 10 additions & 0 deletions test/integration/build/gcp-mm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ variable "cloud_composer_v1" {
type = any
}

variable "organization_envgroup" {
type = any
}

resource "google_compute_ssl_policy" "custom-ssl-policy" {
name = var.ssl_policy["name"]
min_tls_version = var.ssl_policy["min_tls_version"]
Expand Down Expand Up @@ -1576,3 +1580,9 @@ resource "google_composer_v1_environment" "test" {
}
}
}

resource "google_apigee_envgroup" "env_grp" {
name = var.organization_envgroup.name
hostnames = var.organization_envgroup.hostnames
org_id = var.organization_envgroup.project
}
8 changes: 8 additions & 0 deletions test/integration/configuration/mm-attributes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -570,3 +570,11 @@ cloud_composer_v1:
name : "example-composer-env"
region : "us-central1"
image_version : "composer-1.20.12-airflow-2.4.3"

organization_envgroup:
project: "organizations/ppradhan"
name : "test-env-group"
hostnames: ["34.95.97.227.nip.io"]
parent : "organizations/ppradhan/envgroups"
state : "ACTIVE"
created_at : "1698227493454"
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ----------------------------------------------------------------------------
#
# *** 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.
#
# ----------------------------------------------------------------------------

title 'Test GCP google_apigee_organization_envgroup resource.'

organization_envgroup = input('organization_envgroup', value: {
"name": "test-env-group",
"parent": "organizations/ppradhan/envgroups",
"hostname": "34.95.97.227.nip.io",
"state": "ACTIVE",
"created_at": "1698227493454"
}, description: 'organization_envgroup description')
control 'google_apigee_organization_envgroup-1.0' do
impact 1.0
title 'google_apigee_organization_envgroup resource test'

describe google_apigee_organization_envgroup(name: "#{organization_envgroup['parent']}/#{organization_envgroup['name']}") do
it { should exist }
its('name') { should cmp organization_envgroup['name'] }
its('hostnames') { should include organization_envgroup['hostname'] }
its('state') { should cmp organization_envgroup['state'] }
its('created_at') { should cmp organization_envgroup['created_at'] }
end

describe google_apigee_organization_envgroup(name: "does_not_exit") do
it { should_not exist }
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# ----------------------------------------------------------------------------
#
# *** 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.
#
# ----------------------------------------------------------------------------

title 'Test GCP google_apigee_organization_envgroups resource.'

organization_envgroup = input("organization_envgroup", value: {
"name": "test-env-group",
"parent": "organizations/ppradhan",
"hostname": "34.95.97.227.nip.io",
"state": "ACTIVE"
}, description: "organization_envgroup description")

control 'google_apigee_organization_envgroups-1.0' do
impact 1.0
title 'google_apigee_organization_envgroups resource test'

describe google_apigee_organization_envgroups(parent: organization_envgroup["parent"]) do
it { should exist }
its("names") { should include organization_envgroup["name"] }
end

describe google_apigee_organization_envgroups(parent: organization_envgroup["parent"]).where(name: organization_envgroup["name"]) do
it { should exist }
its("names") { should include organization_envgroup["name"] }
its("hostnames") { should include [organization_envgroup["hostname"]] }
its("states") { should include organization_envgroup["state"] }
end
end

0 comments on commit 33d3c7a

Please sign in to comment.