diff --git a/docs/resources/google_orgpolicy_project_policies.md b/docs/resources/google_orgpolicy_project_policies.md new file mode 100644 index 000000000..c207c3c9a --- /dev/null +++ b/docs/resources/google_orgpolicy_project_policies.md @@ -0,0 +1,31 @@ +--- +title: About the google_orgpolicy_project_policies resource +platform: gcp +--- + +## Syntax +A `google_orgpolicy_project_policies` is used to test a Google ProjectPolicy resource + +## Examples +``` + describe google_orgpolicy_project_policies(parent: ' value_parent') do + it { should exist } + end +``` + +## Properties +Properties that can be accessed from the `google_orgpolicy_project_policies` resource: + +See [google_orgpolicy_project_policy.md](google_orgpolicy_project_policy.md) for more detailed information + * `dry_run_specs`: an array of `google_orgpolicy_project_policy` dry_run_spec + * `specs`: an array of `google_orgpolicy_project_policy` spec + * `names`: an array of `google_orgpolicy_project_policy` name + * `alternates`: an array of `google_orgpolicy_project_policy` alternate + +## 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 [None](https://console.cloud.google.com/apis/library/orgpolicy.googleapis.com/) is enabled for the current project. diff --git a/docs/resources/google_orgpolicy_project_policy.md b/docs/resources/google_orgpolicy_project_policy.md new file mode 100644 index 000000000..dc3ff31ae --- /dev/null +++ b/docs/resources/google_orgpolicy_project_policy.md @@ -0,0 +1,136 @@ +--- +title: About the google_orgpolicy_project_policy resource +platform: gcp +--- + +## Syntax +A `google_orgpolicy_project_policy` is used to test a Google ProjectPolicy resource + +## Examples +``` +describe google_orgpolicy_project_policy(name: ' value_name') do + it { should exist } + +end + +describe google_orgpolicy_project_policy(name: "does_not_exit") do + it { should_not exist } +end +``` + +## Properties +Properties that can be accessed from the `google_orgpolicy_project_policy` resource: + + + * `dry_run_spec`: Defines a Google Cloud policy specification which is used to specify constraints for configurations of Google Cloud resources. + + * `update_time`: Output only. The time stamp this was previously updated. This represents the last time a call to `CreatePolicy` or `UpdatePolicy` was made for that policy. + + * `rules`: In policies for boolean constraints, the following requirements apply: - There must be one and only one policy rule where condition is unset. - Boolean policy rules with conditions must set `enforced` to the opposite of the policy rule without a condition. - During policy evaluation, policy rules with conditions that are true for a target resource take precedence. + + * `condition`: Represents a textual expression in the Common Expression Language (CEL) syntax. CEL is a C-like expression language. The syntax and semantics of CEL are documented at https://github.com/google/cel-spec. Example (Comparison): title: "Summary size limit" description: "Determines if a summary is less than 100 chars" expression: "document.summary.size() < 100" Example (Equality): title: "Requestor is owner" description: "Determines if requestor is the document owner" expression: "document.owner == request.auth.claims.email" Example (Logic): title: "Public documents" description: "Determine whether the document should be publicly visible" expression: "document.type != 'private' && document.type != 'internal'" Example (Data Manipulation): title: "Notification string" description: "Create a notification string with a timestamp." expression: "'New message received at ' + string(document.create_time)" The exact variables and functions that may be referenced within an expression are determined by the service that evaluates it. See the service documentation for additional information. + + * `title`: Optional. Title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression. + + * `location`: Optional. String indicating the location of the expression for error reporting, e.g. a file name and a position in the file. + + * `expression`: Textual representation of an expression in Common Expression Language syntax. + + * `description`: Optional. Description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI. + + * `deny_all`: Setting this to true means that all values are denied. This field can be set only in policies for list constraints. + + * `allow_all`: Setting this to true means that all values are allowed. This field can be set only in policies for list constraints. + + * `enforce`: If `true`, then the policy is enforced. If `false`, then any configuration is acceptable. This field can be set only in policies for boolean constraints. + + * `values`: A message that holds specific allowed and denied values. This message can define specific values and subtrees of the Resource Manager resource hierarchy (`Organizations`, `Folders`, `Projects`) that are allowed or denied. This is achieved by using the `under:` and optional `is:` prefixes. The `under:` prefix is used to denote resource subtree values. The `is:` prefix is used to denote specific values, and is required only if the value contains a ":". Values prefixed with "is:" are treated the same as values with no prefix. Ancestry subtrees must be in one of the following formats: - `projects/` (for example, `projects/tokyo-rain-123`) - `folders/` (for example, `folders/1234`) - `organizations/` (for example, `organizations/1234`) The `supports_under` field of the associated `Constraint` defines whether ancestry prefixes can be used. + + * `denied_values`: List of values denied at this resource. + + * `allowed_values`: List of values allowed at this resource. + + * `etag`: An opaque tag indicating the current version of the policySpec, used for concurrency control. This field is ignored if used in a `CreatePolicy` request. When the policy is returned from either a `GetPolicy` or a `ListPolicies` request, this `etag` indicates the version of the current policySpec to use when executing a read-modify-write loop. When the policy is returned from a `GetEffectivePolicy` request, the `etag` will be unset. + + * `reset`: Ignores policies set above this resource and restores the `constraint_default` enforcement behavior of the specific constraint at this resource. This field can be set in policies for either list or boolean constraints. If set, `rules` must be empty and `inherit_from_parent` must be set to false. + + * `inherit_from_parent`: Determines the inheritance behavior for this policy. If `inherit_from_parent` is true, policy rules set higher up in the hierarchy (up to the closest root) are inherited and present in the effective policy. If it is false, then no rules are inherited, and this policy becomes the new root for evaluation. This field can be set only for policies which configure list constraints. + + * `spec`: Defines a Google Cloud policy specification which is used to specify constraints for configurations of Google Cloud resources. + + * `update_time`: Output only. The time stamp this was previously updated. This represents the last time a call to `CreatePolicy` or `UpdatePolicy` was made for that policy. + + * `rules`: In policies for boolean constraints, the following requirements apply: - There must be one and only one policy rule where condition is unset. - Boolean policy rules with conditions must set `enforced` to the opposite of the policy rule without a condition. - During policy evaluation, policy rules with conditions that are true for a target resource take precedence. + + * `condition`: Represents a textual expression in the Common Expression Language (CEL) syntax. CEL is a C-like expression language. The syntax and semantics of CEL are documented at https://github.com/google/cel-spec. Example (Comparison): title: "Summary size limit" description: "Determines if a summary is less than 100 chars" expression: "document.summary.size() < 100" Example (Equality): title: "Requestor is owner" description: "Determines if requestor is the document owner" expression: "document.owner == request.auth.claims.email" Example (Logic): title: "Public documents" description: "Determine whether the document should be publicly visible" expression: "document.type != 'private' && document.type != 'internal'" Example (Data Manipulation): title: "Notification string" description: "Create a notification string with a timestamp." expression: "'New message received at ' + string(document.create_time)" The exact variables and functions that may be referenced within an expression are determined by the service that evaluates it. See the service documentation for additional information. + + * `title`: Optional. Title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression. + + * `location`: Optional. String indicating the location of the expression for error reporting, e.g. a file name and a position in the file. + + * `expression`: Textual representation of an expression in Common Expression Language syntax. + + * `description`: Optional. Description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI. + + * `deny_all`: Setting this to true means that all values are denied. This field can be set only in policies for list constraints. + + * `allow_all`: Setting this to true means that all values are allowed. This field can be set only in policies for list constraints. + + * `enforce`: If `true`, then the policy is enforced. If `false`, then any configuration is acceptable. This field can be set only in policies for boolean constraints. + + * `values`: A message that holds specific allowed and denied values. This message can define specific values and subtrees of the Resource Manager resource hierarchy (`Organizations`, `Folders`, `Projects`) that are allowed or denied. This is achieved by using the `under:` and optional `is:` prefixes. The `under:` prefix is used to denote resource subtree values. The `is:` prefix is used to denote specific values, and is required only if the value contains a ":". Values prefixed with "is:" are treated the same as values with no prefix. Ancestry subtrees must be in one of the following formats: - `projects/` (for example, `projects/tokyo-rain-123`) - `folders/` (for example, `folders/1234`) - `organizations/` (for example, `organizations/1234`) The `supports_under` field of the associated `Constraint` defines whether ancestry prefixes can be used. + + * `denied_values`: List of values denied at this resource. + + * `allowed_values`: List of values allowed at this resource. + + * `etag`: An opaque tag indicating the current version of the policySpec, used for concurrency control. This field is ignored if used in a `CreatePolicy` request. When the policy is returned from either a `GetPolicy` or a `ListPolicies` request, this `etag` indicates the version of the current policySpec to use when executing a read-modify-write loop. When the policy is returned from a `GetEffectivePolicy` request, the `etag` will be unset. + + * `reset`: Ignores policies set above this resource and restores the `constraint_default` enforcement behavior of the specific constraint at this resource. This field can be set in policies for either list or boolean constraints. If set, `rules` must be empty and `inherit_from_parent` must be set to false. + + * `inherit_from_parent`: Determines the inheritance behavior for this policy. If `inherit_from_parent` is true, policy rules set higher up in the hierarchy (up to the closest root) are inherited and present in the effective policy. If it is false, then no rules are inherited, and this policy becomes the new root for evaluation. This field can be set only for policies which configure list constraints. + + * `name`: Immutable. The resource name of the policy. Must be one of the following forms, where `constraint_name` is the name of the constraint which this policy configures: * `projects/{project_number}/policies/{constraint_name}` * `folders/{folder_id}/policies/{constraint_name}` * `organizations/{organization_id}/policies/{constraint_name}` For example, `projects/123/policies/compute.disableSerialPortAccess`. Note: `projects/{project_id}/policies/{constraint_name}` is also an acceptable name for API requests, but responses will return the name using the equivalent project number. + + * `alternate`: Similar to PolicySpec but with an extra 'launch' field for launch reference. The PolicySpec here is specific for dry-run/darklaunch. + + * `launch`: Reference to the launch that will be used while audit logging and to control the launch. Should be set only in the alternate policy. + + * `spec`: Defines a Google Cloud policy specification which is used to specify constraints for configurations of Google Cloud resources. + + * `update_time`: Output only. The time stamp this was previously updated. This represents the last time a call to `CreatePolicy` or `UpdatePolicy` was made for that policy. + + * `rules`: In policies for boolean constraints, the following requirements apply: - There must be one and only one policy rule where condition is unset. - Boolean policy rules with conditions must set `enforced` to the opposite of the policy rule without a condition. - During policy evaluation, policy rules with conditions that are true for a target resource take precedence. + + * `condition`: Represents a textual expression in the Common Expression Language (CEL) syntax. CEL is a C-like expression language. The syntax and semantics of CEL are documented at https://github.com/google/cel-spec. Example (Comparison): title: "Summary size limit" description: "Determines if a summary is less than 100 chars" expression: "document.summary.size() < 100" Example (Equality): title: "Requestor is owner" description: "Determines if requestor is the document owner" expression: "document.owner == request.auth.claims.email" Example (Logic): title: "Public documents" description: "Determine whether the document should be publicly visible" expression: "document.type != 'private' && document.type != 'internal'" Example (Data Manipulation): title: "Notification string" description: "Create a notification string with a timestamp." expression: "'New message received at ' + string(document.create_time)" The exact variables and functions that may be referenced within an expression are determined by the service that evaluates it. See the service documentation for additional information. + + * `title`: Optional. Title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression. + + * `location`: Optional. String indicating the location of the expression for error reporting, e.g. a file name and a position in the file. + + * `expression`: Textual representation of an expression in Common Expression Language syntax. + + * `description`: Optional. Description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI. + + * `deny_all`: Setting this to true means that all values are denied. This field can be set only in policies for list constraints. + + * `allow_all`: Setting this to true means that all values are allowed. This field can be set only in policies for list constraints. + + * `enforce`: If `true`, then the policy is enforced. If `false`, then any configuration is acceptable. This field can be set only in policies for boolean constraints. + + * `values`: A message that holds specific allowed and denied values. This message can define specific values and subtrees of the Resource Manager resource hierarchy (`Organizations`, `Folders`, `Projects`) that are allowed or denied. This is achieved by using the `under:` and optional `is:` prefixes. The `under:` prefix is used to denote resource subtree values. The `is:` prefix is used to denote specific values, and is required only if the value contains a ":". Values prefixed with "is:" are treated the same as values with no prefix. Ancestry subtrees must be in one of the following formats: - `projects/` (for example, `projects/tokyo-rain-123`) - `folders/` (for example, `folders/1234`) - `organizations/` (for example, `organizations/1234`) The `supports_under` field of the associated `Constraint` defines whether ancestry prefixes can be used. + + * `denied_values`: List of values denied at this resource. + + * `allowed_values`: List of values allowed at this resource. + + * `etag`: An opaque tag indicating the current version of the policySpec, used for concurrency control. This field is ignored if used in a `CreatePolicy` request. When the policy is returned from either a `GetPolicy` or a `ListPolicies` request, this `etag` indicates the version of the current policySpec to use when executing a read-modify-write loop. When the policy is returned from a `GetEffectivePolicy` request, the `etag` will be unset. + + * `reset`: Ignores policies set above this resource and restores the `constraint_default` enforcement behavior of the specific constraint at this resource. This field can be set in policies for either list or boolean constraints. If set, `rules` must be empty and `inherit_from_parent` must be set to false. + + * `inherit_from_parent`: Determines the inheritance behavior for this policy. If `inherit_from_parent` is true, policy rules set higher up in the hierarchy (up to the closest root) are inherited and present in the effective policy. If it is false, then no rules are inherited, and this policy becomes the new root for evaluation. This field can be set only for policies which configure list constraints. + + +## GCP Permissions + +Ensure the [None](https://console.cloud.google.com/apis/library/orgpolicy.googleapis.com/) is enabled for the current project. diff --git a/libraries/google/orgpolicy/property/projectpolicy_alternate.rb b/libraries/google/orgpolicy/property/projectpolicy_alternate.rb new file mode 100644 index 000000000..0849b37dc --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_alternate.rb @@ -0,0 +1,39 @@ +# 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 'google/orgpolicy/property/projectpolicy_alternate_spec' +require 'google/orgpolicy/property/projectpolicy_alternate_spec_rules' +module GoogleInSpec + module Orgpolicy + module Property + class ProjectPolicyAlternate + attr_reader :launch + + attr_reader :spec + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @launch = args['launch'] + @spec = GoogleInSpec::Orgpolicy::Property::ProjectPolicyAlternateSpec.new(args['spec'], to_s) + end + + def to_s + "#{@parent_identifier} ProjectPolicyAlternate" + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_alternate_spec.rb b/libraries/google/orgpolicy/property/projectpolicy_alternate_spec.rb new file mode 100644 index 000000000..48f4af3ca --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_alternate_spec.rb @@ -0,0 +1,47 @@ +# 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 'google/orgpolicy/property/projectpolicy_alternate_spec_rules' +module GoogleInSpec + module Orgpolicy + module Property + class ProjectPolicyAlternateSpec + attr_reader :update_time + + attr_reader :rules + + attr_reader :etag + + attr_reader :reset + + attr_reader :inherit_from_parent + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @update_time = args['updateTime'] + @rules = GoogleInSpec::Orgpolicy::Property::ProjectPolicyAlternateSpecRulesArray.parse(args['rules'], to_s) + @etag = args['etag'] + @reset = args['reset'] + @inherit_from_parent = args['inheritFromParent'] + end + + def to_s + "#{@parent_identifier} ProjectPolicyAlternateSpec" + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_alternate_spec_rules.rb b/libraries/google/orgpolicy/property/projectpolicy_alternate_spec_rules.rb new file mode 100644 index 000000000..626e48f18 --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_alternate_spec_rules.rb @@ -0,0 +1,56 @@ +# 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 'google/orgpolicy/property/projectpolicy_alternate_spec_rules_condition' +require 'google/orgpolicy/property/projectpolicy_alternate_spec_rules_values' +module GoogleInSpec + module Orgpolicy + module Property + class ProjectPolicyAlternateSpecRules + attr_reader :condition + + attr_reader :deny_all + + attr_reader :allow_all + + attr_reader :enforce + + attr_reader :values + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @condition = GoogleInSpec::Orgpolicy::Property::ProjectPolicyAlternateSpecRulesCondition.new(args['condition'], to_s) + @deny_all = args['denyAll'] + @allow_all = args['allowAll'] + @enforce = args['enforce'] + @values = GoogleInSpec::Orgpolicy::Property::ProjectPolicyAlternateSpecRulesValues.new(args['values'], to_s) + end + + def to_s + "#{@parent_identifier} ProjectPolicyAlternateSpecRules" + end + end + + class ProjectPolicyAlternateSpecRulesArray + def self.parse(value, parent_identifier) + return if value.nil? + return ProjectPolicyAlternateSpecRules.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| ProjectPolicyAlternateSpecRules.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_alternate_spec_rules_condition.rb b/libraries/google/orgpolicy/property/projectpolicy_alternate_spec_rules_condition.rb new file mode 100644 index 000000000..2f562041d --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_alternate_spec_rules_condition.rb @@ -0,0 +1,43 @@ +# 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 Orgpolicy + module Property + class ProjectPolicyAlternateSpecRulesCondition + attr_reader :title + + attr_reader :location + + attr_reader :expression + + attr_reader :description + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @title = args['title'] + @location = args['location'] + @expression = args['expression'] + @description = args['description'] + end + + def to_s + "#{@parent_identifier} ProjectPolicyAlternateSpecRulesCondition" + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_alternate_spec_rules_values.rb b/libraries/google/orgpolicy/property/projectpolicy_alternate_spec_rules_values.rb new file mode 100644 index 000000000..f9155c92b --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_alternate_spec_rules_values.rb @@ -0,0 +1,37 @@ +# 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 Orgpolicy + module Property + class ProjectPolicyAlternateSpecRulesValues + attr_reader :denied_values + + attr_reader :allowed_values + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @denied_values = args['deniedValues'] + @allowed_values = args['allowedValues'] + end + + def to_s + "#{@parent_identifier} ProjectPolicyAlternateSpecRulesValues" + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec.rb b/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec.rb new file mode 100644 index 000000000..27c521a2d --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec.rb @@ -0,0 +1,47 @@ +# 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 'google/orgpolicy/property/projectpolicy_dry_run_spec_rules' +module GoogleInSpec + module Orgpolicy + module Property + class ProjectPolicyDryRunSpec + attr_reader :update_time + + attr_reader :rules + + attr_reader :etag + + attr_reader :reset + + attr_reader :inherit_from_parent + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @update_time = args['updateTime'] + @rules = GoogleInSpec::Orgpolicy::Property::ProjectPolicyDryRunSpecRulesArray.parse(args['rules'], to_s) + @etag = args['etag'] + @reset = args['reset'] + @inherit_from_parent = args['inheritFromParent'] + end + + def to_s + "#{@parent_identifier} ProjectPolicyDryRunSpec" + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec_rules.rb b/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec_rules.rb new file mode 100644 index 000000000..ce081f6b4 --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec_rules.rb @@ -0,0 +1,56 @@ +# 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 'google/orgpolicy/property/projectpolicy_dry_run_spec_rules_condition' +require 'google/orgpolicy/property/projectpolicy_dry_run_spec_rules_values' +module GoogleInSpec + module Orgpolicy + module Property + class ProjectPolicyDryRunSpecRules + attr_reader :condition + + attr_reader :deny_all + + attr_reader :allow_all + + attr_reader :enforce + + attr_reader :values + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @condition = GoogleInSpec::Orgpolicy::Property::ProjectPolicyDryRunSpecRulesCondition.new(args['condition'], to_s) + @deny_all = args['denyAll'] + @allow_all = args['allowAll'] + @enforce = args['enforce'] + @values = GoogleInSpec::Orgpolicy::Property::ProjectPolicyDryRunSpecRulesValues.new(args['values'], to_s) + end + + def to_s + "#{@parent_identifier} ProjectPolicyDryRunSpecRules" + end + end + + class ProjectPolicyDryRunSpecRulesArray + def self.parse(value, parent_identifier) + return if value.nil? + return ProjectPolicyDryRunSpecRules.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| ProjectPolicyDryRunSpecRules.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec_rules_condition.rb b/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec_rules_condition.rb new file mode 100644 index 000000000..477e1548a --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec_rules_condition.rb @@ -0,0 +1,43 @@ +# 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 Orgpolicy + module Property + class ProjectPolicyDryRunSpecRulesCondition + attr_reader :title + + attr_reader :location + + attr_reader :expression + + attr_reader :description + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @title = args['title'] + @location = args['location'] + @expression = args['expression'] + @description = args['description'] + end + + def to_s + "#{@parent_identifier} ProjectPolicyDryRunSpecRulesCondition" + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec_rules_values.rb b/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec_rules_values.rb new file mode 100644 index 000000000..dc21eb4bb --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_dry_run_spec_rules_values.rb @@ -0,0 +1,37 @@ +# 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 Orgpolicy + module Property + class ProjectPolicyDryRunSpecRulesValues + attr_reader :denied_values + + attr_reader :allowed_values + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @denied_values = args['deniedValues'] + @allowed_values = args['allowedValues'] + end + + def to_s + "#{@parent_identifier} ProjectPolicyDryRunSpecRulesValues" + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_spec.rb b/libraries/google/orgpolicy/property/projectpolicy_spec.rb new file mode 100644 index 000000000..3d5d711ff --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_spec.rb @@ -0,0 +1,47 @@ +# 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 'google/orgpolicy/property/projectpolicy_spec_rules' +module GoogleInSpec + module Orgpolicy + module Property + class ProjectPolicySpec + attr_reader :update_time + + attr_reader :rules + + attr_reader :etag + + attr_reader :reset + + attr_reader :inherit_from_parent + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @update_time = args['updateTime'] + @rules = GoogleInSpec::Orgpolicy::Property::ProjectPolicySpecRulesArray.parse(args['rules'], to_s) + @etag = args['etag'] + @reset = args['reset'] + @inherit_from_parent = args['inheritFromParent'] + end + + def to_s + "#{@parent_identifier} ProjectPolicySpec" + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_spec_rules.rb b/libraries/google/orgpolicy/property/projectpolicy_spec_rules.rb new file mode 100644 index 000000000..edd9aca66 --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_spec_rules.rb @@ -0,0 +1,56 @@ +# 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 'google/orgpolicy/property/projectpolicy_spec_rules_condition' +require 'google/orgpolicy/property/projectpolicy_spec_rules_values' +module GoogleInSpec + module Orgpolicy + module Property + class ProjectPolicySpecRules + attr_reader :condition + + attr_reader :deny_all + + attr_reader :allow_all + + attr_reader :enforce + + attr_reader :values + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @condition = GoogleInSpec::Orgpolicy::Property::ProjectPolicySpecRulesCondition.new(args['condition'], to_s) + @deny_all = args['denyAll'] + @allow_all = args['allowAll'] + @enforce = args['enforce'] + @values = GoogleInSpec::Orgpolicy::Property::ProjectPolicySpecRulesValues.new(args['values'], to_s) + end + + def to_s + "#{@parent_identifier} ProjectPolicySpecRules" + end + end + + class ProjectPolicySpecRulesArray + def self.parse(value, parent_identifier) + return if value.nil? + return ProjectPolicySpecRules.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| ProjectPolicySpecRules.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_spec_rules_condition.rb b/libraries/google/orgpolicy/property/projectpolicy_spec_rules_condition.rb new file mode 100644 index 000000000..510be6d18 --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_spec_rules_condition.rb @@ -0,0 +1,43 @@ +# 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 Orgpolicy + module Property + class ProjectPolicySpecRulesCondition + attr_reader :title + + attr_reader :location + + attr_reader :expression + + attr_reader :description + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @title = args['title'] + @location = args['location'] + @expression = args['expression'] + @description = args['description'] + end + + def to_s + "#{@parent_identifier} ProjectPolicySpecRulesCondition" + end + end + end + end +end diff --git a/libraries/google/orgpolicy/property/projectpolicy_spec_rules_values.rb b/libraries/google/orgpolicy/property/projectpolicy_spec_rules_values.rb new file mode 100644 index 000000000..4933786ce --- /dev/null +++ b/libraries/google/orgpolicy/property/projectpolicy_spec_rules_values.rb @@ -0,0 +1,37 @@ +# 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 Orgpolicy + module Property + class ProjectPolicySpecRulesValues + attr_reader :denied_values + + attr_reader :allowed_values + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @denied_values = args['deniedValues'] + @allowed_values = args['allowedValues'] + end + + def to_s + "#{@parent_identifier} ProjectPolicySpecRulesValues" + end + end + end + end +end diff --git a/libraries/google_orgpolicy_project_policies.rb b/libraries/google_orgpolicy_project_policies.rb new file mode 100644 index 000000000..b62e51591 --- /dev/null +++ b/libraries/google_orgpolicy_project_policies.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 OrgpolicyProjectPolicys < GcpResourceBase + name 'google_orgpolicy_project_policies' + desc 'ProjectPolicy plural resource' + supports platform: 'gcp' + + attr_reader :table + + filter_table_config = FilterTable.create + + filter_table_config.add(:dry_run_specs, field: :dry_run_spec) + filter_table_config.add(:specs, field: :spec) + filter_table_config.add(:names, field: :name) + filter_table_config.add(:alternates, field: :alternate) + + filter_table_config.connect(self, :table) + + def initialize(params = {}) + super(params.merge({ use_http_transport: true })) + @params = params + @table = fetch_wrapped_resource('projectPolicies') + 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 + { + 'dryRunSpec' => ->(obj) { return :dry_run_spec, GoogleInSpec::Orgpolicy::Property::ProjectPolicyDryRunSpec.new(obj['dryRunSpec'], to_s) }, + 'spec' => ->(obj) { return :spec, GoogleInSpec::Orgpolicy::Property::ProjectPolicySpec.new(obj['spec'], to_s) }, + 'name' => ->(obj) { return :name, obj['name'] }, + 'alternate' => ->(obj) { return :alternate, GoogleInSpec::Orgpolicy::Property::ProjectPolicyAlternate.new(obj['alternate'], to_s) }, + } + end + + private + + def product_url(_ = nil) + 'None/v1/' + end + + def resource_base_url + 'v2/{{parent}}/policies' + end +end diff --git a/libraries/google_orgpolicy_project_policy.rb b/libraries/google_orgpolicy_project_policy.rb new file mode 100644 index 000000000..71fea7abe --- /dev/null +++ b/libraries/google_orgpolicy_project_policy.rb @@ -0,0 +1,68 @@ +# 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' +require 'google/orgpolicy/property/projectpolicy_alternate' +require 'google/orgpolicy/property/projectpolicy_alternate_spec' +require 'google/orgpolicy/property/projectpolicy_alternate_spec_rules' +require 'google/orgpolicy/property/projectpolicy_dry_run_spec' +require 'google/orgpolicy/property/projectpolicy_dry_run_spec_rules' +require 'google/orgpolicy/property/projectpolicy_spec' +require 'google/orgpolicy/property/projectpolicy_spec_rules' + +# A provider to manage orgpolicy resources. +class OrgpolicyProjectPolicy < GcpResourceBase + name 'google_orgpolicy_project_policy' + desc 'ProjectPolicy' + supports platform: 'gcp' + + attr_reader :params + attr_reader :dry_run_spec + attr_reader :spec + attr_reader :name + attr_reader :alternate + + 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 + @dry_run_spec = GoogleInSpec::Orgpolicy::Property::ProjectPolicyDryRunSpec.new(@fetched['dryRunSpec'], to_s) + @spec = GoogleInSpec::Orgpolicy::Property::ProjectPolicySpec.new(@fetched['spec'], to_s) + @name = @fetched['name'] + @alternate = GoogleInSpec::Orgpolicy::Property::ProjectPolicyAlternate.new(@fetched['alternate'], to_s) + end + + def exists? + !@fetched.nil? + end + + def to_s + "ProjectPolicy #{@params[:name]}" + end + + private + + def product_url(_ = nil) + 'None/v1/' + end + + def resource_base_url + 'v2/{{name}}' + end +end diff --git a/test/integration/verify/controls/google_orgpolicy_project_policies.rb b/test/integration/verify/controls/google_orgpolicy_project_policies.rb new file mode 100644 index 000000000..2b91711b9 --- /dev/null +++ b/test/integration/verify/controls/google_orgpolicy_project_policies.rb @@ -0,0 +1,30 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_orgpolicy_project_policies resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + project_policy = input('project_policy', value: { + "name": "value_name", + "parent": "value_parent" +}, description: 'project_policy description') +control 'google_orgpolicy_project_policies-1.0' do + impact 1.0 + title 'google_orgpolicy_project_policies resource test' + + describe google_orgpolicy_project_policies(parent: project_policy['parent']) do + it { should exist } + end +end diff --git a/test/integration/verify/controls/google_orgpolicy_project_policy.rb b/test/integration/verify/controls/google_orgpolicy_project_policy.rb new file mode 100644 index 000000000..9e582cc83 --- /dev/null +++ b/test/integration/verify/controls/google_orgpolicy_project_policy.rb @@ -0,0 +1,35 @@ +# ---------------------------------------------------------------------------- +# +# *** 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_orgpolicy_project_policy resource.' + +gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.') + + project_policy = input('project_policy', value: { + "name": "value_name", + "parent": "value_parent" +}, description: 'project_policy description') +control 'google_orgpolicy_project_policy-1.0' do + impact 1.0 + title 'google_orgpolicy_project_policy resource test' + + describe google_orgpolicy_project_policy(name: project_policy['name']) do + it { should exist } + + end + + describe google_orgpolicy_project_policy(name: "does_not_exit") do + it { should_not exist } + end +end