Skip to content

Commit

Permalink
Add web security scanner ScanConfig resource to terraform
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
slevenick authored and modular-magician committed May 6, 2019
1 parent e261332 commit 56ab363
Show file tree
Hide file tree
Showing 7 changed files with 1,146 additions and 1 deletion.
1 change: 1 addition & 0 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
// start beta-only products
GeneratedBinaryAuthorizationResourcesMap,
GeneratedContainerAnalysisResourcesMap,
GeneratedSecurityScannerResourcesMap,
// end beta-only products
GeneratedAccessContextManagerResourcesMap,
GeneratedAppEngineResourcesMap,
Expand Down
21 changes: 21 additions & 0 deletions google-beta/provider_security_scanner_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
//
// ----------------------------------------------------------------------------
//
// 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
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package google

import "github.com/hashicorp/terraform/helper/schema"

var GeneratedSecurityScannerResourcesMap = map[string]*schema.Resource{
"google_security_scanner_scan_config": resourceSecurityScannerScanConfig(),
}
71 changes: 71 additions & 0 deletions google-beta/resource_google_security_scanner_scan_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package google

import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccSecurityScannerScanConfig_scanConfigUpdate(t *testing.T) {
t.Parallel()

firstAddressSuffix := acctest.RandString(10)
secondAddressSuffix := acctest.RandString(10)
context := map[string]interface{}{
"random_suffix": firstAddressSuffix,
"random_suffix2": secondAddressSuffix,
"static_address_name": "scanner_static_ip",
"user_agent": "CHROME_LINUX",
"export": "ENABLED",
"max_qps": 10,
}
updateContext := map[string]interface{}{
"random_suffix": firstAddressSuffix,
"random_suffix2": secondAddressSuffix,
"static_address_name": "scanner_static_ip_update",
"user_agent": "CHROME_ANDROID",
"export": "DISABLED",
"max_qps": 20,
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckSecurityScannerScanConfigDestroy,
Steps: []resource.TestStep{
{
Config: testAccSecurityScannerScanConfig(context),
},
{
ResourceName: "google_security_scanner_scan_config.terraform-scan-config",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccSecurityScannerScanConfig(updateContext),
},
},
})
}

func testAccSecurityScannerScanConfig(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_address" "scanner_static_ip" {
name = "scan-static-ip-%{random_suffix}"
}
resource "google_compute_address" "scanner_static_ip_update" {
name = "scan-static-ip-%{random_suffix2}"
}
resource "google_security_scanner_scan_config" "terraform-scan-config" {
display_name = "terraform-scan-config-%{random_suffix}"
max_qps = %{max_qps}
starting_urls = ["http://${google_compute_address.%{static_address_name}.address}"]
target_platforms = ["COMPUTE"]
user_agent = "%{user_agent}"
export_to_security_command_center = "%{export}"
}
`, context)
}
Loading

0 comments on commit 56ab363

Please sign in to comment.