Skip to content

Commit

Permalink
Use vars for resource ids in SecurityPosture (GoogleCloudPlatform#10475)
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson authored and balanaguharsha committed May 2, 2024
1 parent 1680533 commit 31e9752
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,12 @@ references: !ruby/object:Api::Resource::ReferenceLinks
'Create and deploy a posture': 'https://cloud.google.com/security-command-center/docs/how-to-use-security-posture'
import_format: ['{{%parent}}/locations/{{location}}/postures/{{posture_id}}']
base_url: '{{parent}}/locations/{{location}}/postures'

self_link: '{{parent}}/locations/{{location}}/postures/{{posture_id}}'

create_url: '{{parent}}/locations/{{location}}/postures?postureId={{posture_id}}'

update_url: '{{parent}}/locations/{{location}}/postures/{{posture_id}}?revisionId={{revision_id}}'
update_verb: :PATCH

update_mask: true

delete_url: '{{parent}}/locations/{{location}}/postures/{{posture_id}}'

autogen_async: true
# Sets parameters for handling operations returned by the API.
async: !ruby/object:Api::OpAsync
Expand All @@ -49,9 +43,10 @@ examples:
- !ruby/object:Provider::Terraform::Examples
name: 'securityposture_posture_basic'
primary_resource_id: 'posture1'
vars:
posture_id: "posture_example"
test_env_vars:
org_id: :ORG_ID

parameters:
- !ruby/object:Api::Type::String
name: 'parent'
Expand Down
8 changes: 3 additions & 5 deletions mmv1/products/securityposture/PostureDeployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ references: !ruby/object:Api::Resource::ReferenceLinks
import_format: ['{{%parent}}/locations/{{location}}/postureDeployments/{{posture_deployment_id}}']
base_url: '{{parent}}/locations/{{location}}/postureDeployments'
self_link: '{{parent}}/locations/{{location}}/postureDeployments/{{posture_deployment_id}}'

create_url: '{{parent}}/locations/{{location}}/postureDeployments?postureDeploymentId={{posture_deployment_id}}'
update_verb: :PATCH
update_mask: true


autogen_async: true
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
Expand All @@ -39,10 +36,12 @@ examples:
- !ruby/object:Provider::Terraform::Examples
name: 'securityposture_posture_deployment_basic'
primary_resource_id: 'postureDeployment'
vars:
posture_id: "posture_1"
deployment_id: "posture_deployment_1"
test_env_vars:
org_id: :ORG_ID
project_number: :PROJECT_NUMBER

parameters:
- !ruby/object:Api::Type::String
name: parent
Expand All @@ -65,7 +64,6 @@ parameters:
immutable: true
required: true
url_param_only: true

properties:
- !ruby/object:Api::Type::String
name: 'name'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "google_securityposture_posture" "<%= ctx[:primary_resource_id] %>"{
posture_id = "posture_example"
posture_id = "<%= ctx[:vars]['posture_id'] %>"
parent = "organizations/<%= ctx[:test_env_vars]['org_id'] %>"
location = "global"
state = "ACTIVE"
Expand All @@ -16,8 +16,8 @@ resource "google_securityposture_posture" "<%= ctx[:primary_resource_id] %>"{
enforce = true
condition {
description = "condition description"
expression = "resource.matchTag('org_id/tag_key_short_name,'tag_value_short_name')"
title = "a CEL condition"
expression = "resource.matchTag('org_id/tag_key_short_name,'tag_value_short_name')"
title = "a CEL condition"
}
}
}
Expand All @@ -28,9 +28,9 @@ resource "google_securityposture_posture" "<%= ctx[:primary_resource_id] %>"{
constraint {
org_policy_constraint_custom {
custom_constraint {
name = "organizations/<%= ctx[:test_env_vars]['org_id'] %>/customConstraints/custom.disableGkeAutoUpgrade"
display_name = "Disable GKE auto upgrade"
description = "Only allow GKE NodePool resource to be created or updated if AutoUpgrade is not enabled where this custom constraint is enforced."
name = "organizations/<%= ctx[:test_env_vars]['org_id'] %>/customConstraints/custom.disableGkeAutoUpgrade"
display_name = "Disable GKE auto upgrade"
description = "Only allow GKE NodePool resource to be created or updated if AutoUpgrade is not enabled where this custom constraint is enforced."
action_type = "ALLOW"
condition = "resource.management.autoUpgrade == false"
method_types = ["CREATE", "UPDATE"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
resource "google_securityposture_posture" "posture_1" {
posture_id = "posture_1"
parent = "organizations/<%= ctx[:test_env_vars]['org_id'] %>"
location = "global"
state = "ACTIVE"
posture_id = "<%= ctx[:vars]['posture_id'] %>"
parent = "organizations/<%= ctx[:test_env_vars]['org_id'] %>"
location = "global"
state = "ACTIVE"
description = "a new posture"
policy_sets {
policy_set_id = "org_policy_set"
description = "set of org policies"
description = "set of org policies"
policies {
policy_id = "policy_1"
constraint {
Expand All @@ -22,11 +22,11 @@ resource "google_securityposture_posture" "posture_1" {
}

resource "google_securityposture_posture_deployment" "<%= ctx[:primary_resource_id] %>" {
posture_deployment_id = "posture_deployment_1"
parent = "organizations/<%= ctx[:test_env_vars]['org_id'] %>"
location = "global"
description = "a new posture deployment"
target_resource = "projects/<%= ctx[:test_env_vars]['project_number'] %>"
posture_id = google_securityposture_posture.posture_1.name
posture_revision_id = google_securityposture_posture.posture_1.revision_id
}
posture_deployment_id = "<%= ctx[:vars]['deployment_id'] %>"
parent = "organizations/<%= ctx[:test_env_vars]['org_id'] %>"
location = "global"
description = "a new posture deployment"
target_resource = "projects/<%= ctx[:test_env_vars]['project_number'] %>"
posture_id = google_securityposture_posture.posture_1.name
posture_revision_id = google_securityposture_posture.posture_1.revision_id
}

0 comments on commit 31e9752

Please sign in to comment.