forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create SCC Mute config resource (GoogleCloudPlatform#7332)
- Loading branch information
1 parent
84a5d96
commit f631ed5
Showing
4 changed files
with
125 additions
and
1 deletion.
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
34 changes: 34 additions & 0 deletions
34
mmv1/templates/terraform/custom_import/scc_mute_config.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,34 @@ | ||
config := meta.(*Config) | ||
|
||
if err := parseImportId([]string{"(?P<name>.+)"}, d, config); err != nil { | ||
return nil, err | ||
} | ||
|
||
// current import_formats can't import fields with forward slashes in their value | ||
name := d.Get("name").(string) | ||
|
||
matched, err := regexp.MatchString("(organizations|folders|projects)/.+/muteConfigs/.+", name) | ||
if err != nil { | ||
return nil, fmt.Errorf("error validating import name: %s", err) | ||
} | ||
|
||
if !matched { | ||
return nil, fmt.Errorf("error validating import name: %s does not fit naming for muteConfigs. Expected %s", | ||
name, "organizations/{organization}/muteConfigs/{configId}, folders/{folder}/muteConfigs/{configId} or projects/{project}/muteConfigs/{configId}") | ||
} | ||
|
||
if err := d.Set("name", name); err != nil { | ||
return nil, fmt.Errorf("Error setting name: %s", err) | ||
} | ||
|
||
// mute_config_id and parent are not returned by the API and therefore need to be set manually | ||
stringParts := strings.Split(d.Get("name").(string), "/") | ||
if err := d.Set("mute_config_id", stringParts[3]); err != nil { | ||
return nil, fmt.Errorf("Error setting mute_config_id: %s", err) | ||
} | ||
|
||
if err := d.Set("parent", fmt.Sprintf("%s/%s", stringParts[0], stringParts[1])); err != nil { | ||
return nil, fmt.Errorf("Error setting mute_config_id: %s", err) | ||
} | ||
|
||
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,6 @@ | ||
resource "google_scc_mute_config" "<%= ctx[:primary_resource_id] %>" { | ||
mute_config_id = "<%= ctx[:vars]['mute_config_id'] %>" | ||
parent = "organizations/<%= ctx[:test_env_vars]['org_id'] %>" | ||
filter = "category: \"OS_VULNERABILITY\"" | ||
description = "My Mute Config" | ||
} |