diff --git a/README.md b/README.md index dbf359229..fa1392260 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ The following resources are available in the InSpec GCP Profile | [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_apigee_organization_envgroup_attachment](docs/resources/google_apigee_organization_envgroup_attachment.md) | [google_apigee_organization_envgroup_attachments](docs/resources/google_apigee_organization_envgroup_attachments.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) | @@ -374,7 +375,6 @@ The following resources are available in the InSpec GCP Profile | [google_vertex_ai_tensorboard_experiment_run](docs/resources/google_vertex_ai_tensorboard_experiment_run.md) | [google_vertex_ai_tensorboard_experiment_runs](docs/resources/google_vertex_ai_tensorboard_experiment_runs.md) | | [google_vertex_ai_tensorboard_experiment_run_time_series_resource](docs/resources/google_vertex_ai_tensorboard_experiment_run_time_series_resource.md) | [google_vertex_ai_tensorboard_experiment_run_time_series_resources](docs/resources/google_vertex_ai_tensorboard_experiment_run_time_series_resources.md) | | [google_vertex_ai_training_pipeline](docs/resources/google_vertex_ai_training_pipeline.md) | [google_vertex_ai_training_pipelines](docs/resources/google_vertex_ai_training_pipelines.md) | -| [google_artifactregistry_project_location_repository](docs/resources/google_artifactregistry_project_location_repository.md) | [google_artifactregistry_project_location_repositories](docs/resources/google_artifactregistry_project_location_repositories.md) | | [google_composer_project_location_environment](docs/resources/google_composer_project_location_environment.md) | [google_composer_project_location_environments](docs/resources/google_composer_project_location_environment.md) | ## Examples diff --git a/docs/resources/google_apigee_organization_envgroup_attachment.md b/docs/resources/google_apigee_organization_envgroup_attachment.md new file mode 100644 index 000000000..2269b54d0 --- /dev/null +++ b/docs/resources/google_apigee_organization_envgroup_attachment.md @@ -0,0 +1,43 @@ +--- +title: About the google_apigee_organization_envgroup_attachment resource +platform: gcp +--- + +## Syntax + +A `google_apigee_organization_envgroup_attachment` is used to test a Google OrganizationEnvgroupAttachment resource + +## Examples + +``` +describe google_apigee_organization_envgroup_attachment(name: ' value_name') do + it { should exist } + its('created_at') { should cmp 'value_createdat' } + its('environment') { should cmp 'value_environment' } + its('environment_group_id') { should cmp 'value_environmentgroupid' } + its('name') { should cmp 'value_name' } + +end + +describe google_apigee_organization_envgroup_attachment(name: "does_not_exit") do + it { should_not exist } +end +``` + +## Properties + +Properties that can be accessed from the `google_apigee_organization_envgroup_attachment` resource: + + + * `created_at`: The time at which the environment group attachment was created as milliseconds since epoch. + + * `environment`: ID of the attached environment. + + * `environment_group_id`: ID of the environment group. + + * `name`: ID of the environment group attachment. + + +## GCP Permissions + +Ensure the [Apigee API](https://console.cloud.google.com/apis/library/apigee.googleapis.com/) is enabled for the current project. diff --git a/docs/resources/google_apigee_organization_envgroup_attachments.md b/docs/resources/google_apigee_organization_envgroup_attachments.md new file mode 100644 index 000000000..283d0132a --- /dev/null +++ b/docs/resources/google_apigee_organization_envgroup_attachments.md @@ -0,0 +1,35 @@ +--- +title: About the google_apigee_organization_envgroup_attachments resource +platform: gcp +--- + +## Syntax + +A `google_apigee_organization_envgroup_attachments` is used to test a Google OrganizationEnvgroupAttachment resource + +## Examples + +``` + describe google_apigee_organization_envgroup_attachments(parent: ' value_parent') do + it { should exist } + end +``` + +## Properties + +Properties that can be accessed from the `google_apigee_organization_envgroup_attachments` resource: + +See [google_apigee_organization_envgroup_attachment.md](google_apigee_organization_envgroup_attachment.md) for more detailed information + * `created_ats`: an array of `google_apigee_organization_envgroup_attachment` created_at + * `environments`: an array of `google_apigee_organization_envgroup_attachment` environment + * `environment_group_ids`: an array of `google_apigee_organization_envgroup_attachment` environment_group_id + * `names`: an array of `google_apigee_organization_envgroup_attachment` name + +## 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. diff --git a/libraries/google_apigee_organization_envgroup_attachment.rb b/libraries/google_apigee_organization_envgroup_attachment.rb new file mode 100644 index 000000000..705deb58f --- /dev/null +++ b/libraries/google_apigee_organization_envgroup_attachment.rb @@ -0,0 +1,61 @@ +# 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 ApigeeOrganizationEnvgroupAttachment < GcpResourceBase + name 'google_apigee_organization_envgroup_attachment' + desc 'OrganizationEnvgroupAttachment' + supports platform: 'gcp' + + attr_reader :params + attr_reader :created_at + attr_reader :environment + attr_reader :environment_group_id + attr_reader :name + + 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 + @created_at = @fetched['createdAt'] + @environment = @fetched['environment'] + @environment_group_id = @fetched['environmentGroupId'] + @name = @fetched['name'] + end + + def exists? + !@fetched.nil? + end + + def to_s + "OrganizationEnvgroupAttachment #{@params[:name]}" + end + + private + + def product_url(_ = nil) + 'https://apigee.googleapis.com/v1/' + end + + def resource_base_url + '{{name}}' + end +end diff --git a/libraries/google_apigee_organization_envgroup_attachments.rb b/libraries/google_apigee_organization_envgroup_attachments.rb new file mode 100644 index 000000000..d61e48d26 --- /dev/null +++ b/libraries/google_apigee_organization_envgroup_attachments.rb @@ -0,0 +1,85 @@ +# 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 ApigeeOrganizationEnvgroupAttachments < GcpResourceBase + name 'google_apigee_organization_envgroup_attachments' + desc 'OrganizationEnvgroupAttachment plural resource' + supports platform: 'gcp' + + attr_reader :table + + filter_table_config = FilterTable.create + + filter_table_config.add(:created_ats, field: :created_at) + filter_table_config.add(:environments, field: :environment) + filter_table_config.add(:environment_group_ids, field: :environment_group_id) + filter_table_config.add(:names, field: :name) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('environmentGroupAttachments') + 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 + { + 'createdAt' => ->(obj) { [:created_at, obj['createdAt']] }, + 'environment' => ->(obj) { [:environment, obj['environment']] }, + 'environmentGroupId' => ->(obj) { [:environment_group_id, obj['environmentGroupId']] }, + 'name' => ->(obj) { [:name, obj['name']] }, + } + end + + private + + def product_url(_ = nil) + 'https://apigee.googleapis.com/v1/' + end + + def resource_base_url + '{{parent}}/attachments' + end +end diff --git a/test/integration/build/gcp-mm.tf b/test/integration/build/gcp-mm.tf index 0dfa6e481..77db56629 100644 --- a/test/integration/build/gcp-mm.tf +++ b/test/integration/build/gcp-mm.tf @@ -224,6 +224,10 @@ variable "cloud_composer_v1" { type = any } +variable "apigee_organization_envgroup_attachment" { + type = any +} + variable "organization_envgroup" { type = any } @@ -1574,7 +1578,7 @@ resource "google_artifact_registry_repository" "example" { resource "google_composer_v1_environment" "test" { name = var.cloud_composer_v1["name"] region = var.cloud_composer_v1["region"] - config { + config { software_config { image_version = var.cloud_composer_v1["image_version"] } @@ -1585,4 +1589,8 @@ resource "google_apigee_envgroup" "env_grp" { name = var.organization_envgroup.name hostnames = var.organization_envgroup.hostnames org_id = var.organization_envgroup.project -} \ No newline at end of file +} +resource "google_apigee_envgroup_attachment" "engroup_attachment" { + envgroup_id = var.apigee_organization_envgroup_attachment.envgroup_id + environment = var.apigee_organization_envgroup_attachment.environment +} diff --git a/test/integration/configuration/mm-attributes.yml b/test/integration/configuration/mm-attributes.yml index 7b3f4ad48..5305c8b39 100644 --- a/test/integration/configuration/mm-attributes.yml +++ b/test/integration/configuration/mm-attributes.yml @@ -578,3 +578,7 @@ organization_envgroup: parent : "organizations/ppradhan/envgroups" state : "ACTIVE" created_at : "1698227493454" + +apigee_organization_envgroup_attachment: + envgroup_id: "organizations/ppradhan/envgroups/test-env-group" + environment: "test-env" diff --git a/test/integration/verify/controls/google_apigee_organization_envgroup_attachment.rb b/test/integration/verify/controls/google_apigee_organization_envgroup_attachment.rb new file mode 100644 index 000000000..1d0117ab4 --- /dev/null +++ b/test/integration/verify/controls/google_apigee_organization_envgroup_attachment.rb @@ -0,0 +1,40 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_attachment resource.' + +organization_envgroup_attachment = input('organization_envgroup_attachment', value: { + "name": "6741d6ad-1307-4f03-b02a-9fb4562c0ff3", + "parent": "organizations/ppradhan/envgroups/test-env-group/attachments", + "created_at": "1698227493793", + "environment": "test-env", + "environment_group_id": "test-env-group" +}, description: 'organization_envgroup_attachment description') + +control 'google_apigee_organization_envgroup_attachment-1.0' do + impact 1.0 + title 'google_apigee_organization_envgroup_attachment resource test' + + describe google_apigee_organization_envgroup_attachment(name: "#{organization_envgroup_attachment['parent']}/#{organization_envgroup_attachment['name']}") do + it { should exist } + its('created_at') { should cmp organization_envgroup_attachment['created_at'] } + its('environment') { should cmp organization_envgroup_attachment['environment'] } + its('environment_group_id') { should cmp organization_envgroup_attachment['environment_group_id'] } + its('name') { should cmp organization_envgroup_attachment['name'] } + end + + describe google_apigee_organization_envgroup_attachment(name: "does_not_exit") do + it { should_not exist } + end +end diff --git a/test/integration/verify/controls/google_apigee_organization_envgroup_attachments.rb b/test/integration/verify/controls/google_apigee_organization_envgroup_attachments.rb new file mode 100644 index 000000000..2c3a380c6 --- /dev/null +++ b/test/integration/verify/controls/google_apigee_organization_envgroup_attachments.rb @@ -0,0 +1,38 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_attachments resource.' + +organization_envgroup_attachment = input('organization_envgroup_attachment', value: { + "name": "6741d6ad-1307-4f03-b02a-9fb4562c0ff3", + "parent": "organizations/ppradhan/envgroups/test-env-group", + "created_at": "1698227493793", + "environment": "test-env", + "environment_group_id": "test-env-group" +}, description: 'organization_envgroup_attachment description') + +control 'google_apigee_organization_envgroup_attachments-1.0' do + impact 1.0 + title 'google_apigee_organization_envgroup_attachments resource test' + + describe google_apigee_organization_envgroup_attachments(parent: organization_envgroup_attachment['parent']) do + it { should exist } + end + + describe google_apigee_organization_envgroup_attachments(parent: organization_envgroup_attachment['parent']).where(name: organization_envgroup_attachment['name']) do + it { should exist } + its("environment_group_ids") { should include organization_envgroup_attachment['environment_group_id'] } + its("environments") { should include organization_envgroup_attachment['environment'] } + end +end