-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add Cloud SCC Source resource #2167
Merged
modular-magician
merged 1 commit into
GoogleCloudPlatform:master
from
rileykarson:scc-source
Aug 14, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2019 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Api::Product | ||
name: SecurityCenter | ||
display_name: Cloud Security Command Center | ||
versions: | ||
- !ruby/object:Api::Product::Version | ||
name: ga | ||
base_url: https://securitycenter.googleapis.com/v1/ | ||
scopes: | ||
- https://www.googleapis.com/auth/cloud-platform | ||
objects: | ||
- !ruby/object:Api::Resource | ||
name: 'Source' | ||
base_url: organizations/{{organization}}/sources | ||
self_link: '{{name}}' | ||
update_verb: :PATCH | ||
update_mask: true | ||
description: | | ||
A Cloud Security Command Center's (Cloud SCC) finding source. A finding | ||
source is an entity or a mechanism that can produce a finding. A source is | ||
like a container of findings that come from the same scanner, logger, | ||
monitor, etc. | ||
references: !ruby/object:Api::Resource::ReferenceLinks | ||
guides: | ||
'Official Documentation': | ||
'https://cloud.google.com/binary-authorization/' | ||
api: 'https://cloud.google.com/security-command-center/docs/reference/rest/v1beta1/organizations.sources' | ||
parameters: | ||
- !ruby/object:Api::Type::String | ||
name: organization | ||
required: true | ||
input: true | ||
url_param_only: true | ||
description: | | ||
The organization whose Cloud Security Command Center the Source | ||
lives in. | ||
properties: | ||
- !ruby/object:Api::Type::String | ||
name: name | ||
output: true | ||
description: | | ||
The resource name of this source, in the format | ||
`organizations/{{organization}}/sources/{{source}}`. | ||
- !ruby/object:Api::Type::String | ||
name: description | ||
description: | | ||
The description of the source (max of 1024 characters). | ||
- !ruby/object:Api::Type::String | ||
name: displayName | ||
required: true | ||
description: | | ||
The source’s display name. A source’s display name must be unique | ||
amongst its siblings, for example, two sources with the same parent | ||
can't share the same display name. The display name must start and end | ||
with a letter or digit, may contain letters, digits, spaces, hyphens, | ||
and underscores, and can be no longer than 32 characters. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2019 Google Inc. | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
--- !ruby/object:Provider::Terraform::Config | ||
legacy_name: scc | ||
overrides: !ruby/object:Overrides::ResourceOverrides | ||
Source: !ruby/object:Overrides::Terraform::ResourceOverride | ||
examples: | ||
- !ruby/object:Provider::Terraform::Examples | ||
name: "scc_source_basic" | ||
# resource can't be destroyed, so checkdestroy fails unnecessarily | ||
skip_test: true | ||
primary_resource_id: "custom_source" | ||
vars: | ||
source_display_name: "My Source" | ||
test_env_vars: | ||
org_id: :ORG_ID | ||
properties: | ||
description: !ruby/object:Overrides::Terraform::PropertyOverride | ||
validation: !ruby/object:Provider::Terraform::Validation | ||
function: 'validation.StringLenBetween(0, 1024)' | ||
displayName: !ruby/object:Overrides::Terraform::PropertyOverride | ||
validation: !ruby/object:Provider::Terraform::Validation | ||
regex: '[\p{L}\p{N}]({\p{L}\p{N}_- ]{0,30}[\p{L}\p{N}])?' | ||
custom_code: !ruby/object:Provider::Terraform::CustomCode | ||
custom_delete: templates/terraform/custom_delete/skip_delete.go.erb | ||
custom_import: templates/terraform/custom_import/scc_source_self_link_as_name_set_organization.go.erb | ||
post_create: templates/terraform/post_create/set_computed_name.erb | ||
# This is for copying files over | ||
files: !ruby/object:Provider::Config::Files | ||
# These files have templating (ERB) code that will be run. | ||
# This is usually to add licensing info, autogeneration notices, etc. | ||
compile: | ||
<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
log.Printf("[WARNING] <%= object.__product.name + " " + object.name %> resources" + | ||
" cannot be deleted from GCP. The resource %s will be removed from Terraform" + | ||
" state, but will still be present on the server.", d.Id()) | ||
d.SetId("") | ||
|
||
return nil |
18 changes: 18 additions & 0 deletions
18
templates/terraform/custom_import/scc_source_self_link_as_name_set_organization.go.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
config := meta.(*Config) | ||
|
||
// current import_formats can't import fields with forward slashes in their value | ||
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
stringParts := strings.Split(d.Get("name").(string), "/") | ||
if len(stringParts) != 4 { | ||
return nil, fmt.Errorf( | ||
"Saw %s when the name is expected to have shape %s", | ||
d.Get("name"), | ||
"organizations/{{organization}}/sources/{{source}}", | ||
) | ||
} | ||
|
||
d.Set("organization", fmt.Sprintf("%s", stringParts[1])) | ||
return []*schema.ResourceData{d}, nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
resource "google_scc_source" "<%= ctx[:primary_resource_id] %>" { | ||
display_name = "<%= ctx[:vars]['source_display_name'] %>" | ||
organization = "<%= ctx[:test_env_vars]['org_id'] %>" | ||
description = "My custom Cloud Security Command Center Finding Source" | ||
} |
49 changes: 49 additions & 0 deletions
49
third_party/terraform/tests/resource_security_center_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccSecurityCenterSource_basic(t *testing.T) { | ||
t.Parallel() | ||
|
||
orgId := getTestOrgFromEnv(t) | ||
suffix := acctest.RandString(10) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSecurityCenterSource_sccSourceBasicExample(orgId, suffix, "My description"), | ||
}, | ||
{ | ||
ResourceName: "google_scc_source.custom_source", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
{ | ||
Config: testAccSecurityCenterSource_sccSourceBasicExample(orgId, suffix, ""), | ||
}, | ||
{ | ||
ResourceName: "google_scc_source.custom_source", | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccSecurityCenterSource_sccSourceBasicExample(orgId, suffix, description string) string { | ||
return fmt.Sprintf(` | ||
resource "google_scc_source" "custom_source" { | ||
display_name = "TFSrc %s" | ||
organization = "%s" | ||
description = "%s" | ||
} | ||
`, suffix, orgId, description) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This renaming matches the service name used throughout the product documentation ("Cloud SCC") and the
gcloud
commandgcloud scc
.I think it'll match user expectations better than
security_center
, but if you feel otherwise let me know!