Skip to content

Commit

Permalink
Add Cloud SCC Source resource
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
rileykarson authored and modular-magician committed Aug 13, 2019
1 parent ae68ac5 commit 773214f
Show file tree
Hide file tree
Showing 219 changed files with 1,580 additions and 1,925 deletions.
2 changes: 1 addition & 1 deletion google/access_context_manager_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (w *AccessContextManagerOperationWaiter) QueryOp() (interface{}, error) {
}
// Returns the proper get.
url := fmt.Sprintf("https://accesscontextmanager.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", "", url, nil)
return sendRequest(w.Config, "GET", url, nil)
}

func accessContextManagerOperationWaitTime(config *Config, op map[string]interface{}, activity string, timeoutMinutes int) error {
Expand Down
16 changes: 8 additions & 8 deletions google/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ import (
// Config is the configuration structure used to instantiate the Google
// provider.
type Config struct {
Credentials string
AccessToken string
Project string
Region string
Zone string
Scopes []string
BatchingConfig *batchingConfig
UserProjectOverride bool
Credentials string
AccessToken string
Project string
Region string
Zone string
Scopes []string
BatchingConfig *batchingConfig

client *http.Client
userAgent string
Expand All @@ -85,6 +84,7 @@ type Config struct {
PubsubBasePath string
RedisBasePath string
ResourceManagerBasePath string
SecurityCenterBasePath string
SourceRepoBasePath string
SpannerBasePath string
SqlBasePath string
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_google_client_openid_userinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func dataSourceGoogleClientOpenIDUserinfoRead(d *schema.ResourceData, meta inter

// See https://github.com/golang/oauth2/issues/306 for a recommendation to do this from a Go maintainer
// URL retrieved from https://accounts.google.com/.well-known/openid-configuration
res, err := sendRequest(config, "GET", "", "https://openidconnect.googleapis.com/v1/userinfo", nil)
res, err := sendRequest(config, "GET", "https://openidconnect.googleapis.com/v1/userinfo", nil)
if err != nil {
return fmt.Errorf("error retrieving userinfo for your provider credentials; have you enabled the 'https://www.googleapis.com/auth/userinfo.email' scope? error: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_google_composer_image_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func dataSourceGoogleComposerImageVersionsRead(d *schema.ResourceData, meta inte
return err
}

versions, err := paginatedListRequest(project, url, config, flattenGoogleComposerImageVersions)
versions, err := paginatedListRequest(url, config, flattenGoogleComposerImageVersions)
if err != nil {
return fmt.Errorf("Error listing Composer image versions: %s", err)
}
Expand Down
11 changes: 3 additions & 8 deletions google/data_source_google_kms_crypto_key_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ func dataSourceGoogleKmsCryptoKeyVersionRead(d *schema.ResourceData, meta interf
}

log.Printf("[DEBUG] Getting attributes for CryptoKeyVersion: %#v", url)

cryptoKeyId, err := parseKmsCryptoKeyId(d.Get("crypto_key").(string), config)
if err != nil {
return err
}
res, err := sendRequest(config, "GET", cryptoKeyId.KeyRingId.Project, url, nil)
res, err := sendRequest(config, "GET", url, nil)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("KmsCryptoKeyVersion %q", d.Id()))
}
Expand All @@ -94,7 +89,7 @@ func dataSourceGoogleKmsCryptoKeyVersionRead(d *schema.ResourceData, meta interf
}

log.Printf("[DEBUG] Getting purpose of CryptoKey: %#v", url)
res, err = sendRequest(config, "GET", cryptoKeyId.KeyRingId.Project, url, nil)
res, err = sendRequest(config, "GET", url, nil)
if err != nil {
return handleNotFoundError(err, d, fmt.Sprintf("KmsCryptoKey %q", d.Id()))
}
Expand All @@ -105,7 +100,7 @@ func dataSourceGoogleKmsCryptoKeyVersionRead(d *schema.ResourceData, meta interf
return err
}
log.Printf("[DEBUG] Getting public key of CryptoKeyVersion: %#v", url)
res, _ = sendRequest(config, "GET", cryptoKeyId.KeyRingId.Project, url, nil)
res, _ = sendRequest(config, "GET", url, nil)

if err := d.Set("public_key", flattenKmsCryptoKeyVersionPublicKey(res, d)); err != nil {
return fmt.Errorf("Error reading CryptoKeyVersion public key: %s", err)
Expand Down
3 changes: 1 addition & 2 deletions google/data_source_google_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package google

import (
"fmt"

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

Expand Down Expand Up @@ -45,7 +44,7 @@ func datasourceGoogleProjectsRead(d *schema.ResourceData, meta interface{}) erro
return err
}

res, err := sendRequest(config, "GET", "", url, nil)
res, err := sendRequest(config, "GET", url, nil)
if err != nil {
return fmt.Errorf("Error retrieving projects: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_google_storage_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func dataSourceGoogleStorageBucketObjectRead(d *schema.ResourceData, meta interf
// Using REST apis because the storage go client doesn't support folders
url := fmt.Sprintf("https://www.googleapis.com/storage/v1/b/%s/o/%s", bucket, name)

res, err := sendRequest(config, "GET", "", url, nil)
res, err := sendRequest(config, "GET", url, nil)
if err != nil {
return fmt.Errorf("Error retrieving storage bucket object: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_tpu_tensorflow_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func dataSourceTpuTensorFlowVersionsRead(d *schema.ResourceData, meta interface{
return err
}

versionsRaw, err := paginatedListRequest(project, url, config, flattenTpuTensorflowVersions)
versionsRaw, err := paginatedListRequest(url, config, flattenTpuTensorflowVersions)
if err != nil {
return fmt.Errorf("Error listing TPU Tensorflow versions: %s", err)
}
Expand Down
8 changes: 3 additions & 5 deletions google/filestore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
)

type FilestoreOperationWaiter struct {
Config *Config
Project string
Config *Config
CommonOperationWaiter
}

Expand All @@ -29,7 +28,7 @@ func (w *FilestoreOperationWaiter) QueryOp() (interface{}, error) {
}
// Returns the proper get.
url := fmt.Sprintf("https://file.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", w.Project, url, nil)
return sendRequest(w.Config, "GET", url, nil)
}

func filestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
Expand All @@ -38,8 +37,7 @@ func filestoreOperationWaitTime(config *Config, op map[string]interface{}, proje
return nil
}
w := &FilestoreOperationWaiter{
Config: config,
Project: project,
Config: config,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return err
Expand Down
8 changes: 3 additions & 5 deletions google/firestore_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (
)

type FirestoreOperationWaiter struct {
Config *Config
Project string
Config *Config
CommonOperationWaiter
}

Expand All @@ -29,7 +28,7 @@ func (w *FirestoreOperationWaiter) QueryOp() (interface{}, error) {
}
// Returns the proper get.
url := fmt.Sprintf("https://firestore.googleapis.com/v1/%s", w.CommonOperationWaiter.Op.Name)
return sendRequest(w.Config, "GET", w.Project, url, nil)
return sendRequest(w.Config, "GET", url, nil)
}

func firestoreOperationWaitTime(config *Config, op map[string]interface{}, project, activity string, timeoutMinutes int) error {
Expand All @@ -38,8 +37,7 @@ func firestoreOperationWaitTime(config *Config, op map[string]interface{}, proje
return nil
}
w := &FirestoreOperationWaiter{
Config: config,
Project: project,
Config: config,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return err
Expand Down
14 changes: 2 additions & 12 deletions google/iam_pubsub_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ func PubsubTopicIdParseFunc(d *schema.ResourceData, config *Config) error {
func (u *PubsubTopicIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url := u.qualifyTopicUrl("getIamPolicy")

project, err := getProject(u.d, u.Config)
if err != nil {
return nil, err
}

policy, err := sendRequest(u.Config, "GET", project, url, nil)
policy, err := sendRequest(u.Config, "GET", url, nil)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand All @@ -126,12 +121,7 @@ func (u *PubsubTopicIamUpdater) SetResourceIamPolicy(policy *cloudresourcemanage

url := u.qualifyTopicUrl("setIamPolicy")

project, err := getProject(u.d, u.Config)
if err != nil {
return err
}

_, err = sendRequestWithTimeout(u.Config, "POST", project, url, obj, u.d.Timeout(schema.TimeoutCreate))
_, err = sendRequestWithTimeout(u.Config, "POST", url, obj, u.d.Timeout(schema.TimeoutCreate))
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand Down
14 changes: 2 additions & 12 deletions google/iam_source_repo_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,7 @@ func SourceRepoRepositoryIdParseFunc(d *schema.ResourceData, config *Config) err
func (u *SourceRepoRepositoryIamUpdater) GetResourceIamPolicy() (*cloudresourcemanager.Policy, error) {
url := u.qualifyRepositoryUrl("getIamPolicy")

project, err := getProject(u.d, u.Config)
if err != nil {
return nil, err
}

policy, err := sendRequest(u.Config, "GET", project, url, nil)
policy, err := sendRequest(u.Config, "GET", url, nil)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Error retrieving IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand All @@ -126,12 +121,7 @@ func (u *SourceRepoRepositoryIamUpdater) SetResourceIamPolicy(policy *cloudresou

url := u.qualifyRepositoryUrl("setIamPolicy")

project, err := getProject(u.d, u.Config)
if err != nil {
return err
}

_, err = sendRequestWithTimeout(u.Config, "POST", project, url, obj, u.d.Timeout(schema.TimeoutCreate))
_, err = sendRequestWithTimeout(u.Config, "POST", url, obj, u.d.Timeout(schema.TimeoutCreate))
if err != nil {
return errwrap.Wrapf(fmt.Sprintf("Error setting IAM policy for %s: {{err}}", u.DescribeResource()), err)
}
Expand Down
16 changes: 7 additions & 9 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ func Provider() terraform.ResourceProvider {
},
},

"user_project_override": {
Type: schema.TypeBool,
Optional: true,
},

// Generated Products
AccessContextManagerCustomEndpointEntryKey: AccessContextManagerCustomEndpointEntry,
AppEngineCustomEndpointEntryKey: AppEngineCustomEndpointEntry,
Expand All @@ -119,6 +114,7 @@ func Provider() terraform.ResourceProvider {
PubsubCustomEndpointEntryKey: PubsubCustomEndpointEntry,
RedisCustomEndpointEntryKey: RedisCustomEndpointEntry,
ResourceManagerCustomEndpointEntryKey: ResourceManagerCustomEndpointEntry,
SecurityCenterCustomEndpointEntryKey: SecurityCenterCustomEndpointEntry,
SourceRepoCustomEndpointEntryKey: SourceRepoCustomEndpointEntry,
SpannerCustomEndpointEntryKey: SpannerCustomEndpointEntry,
SqlCustomEndpointEntryKey: SqlCustomEndpointEntry,
Expand Down Expand Up @@ -233,6 +229,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
GeneratedPubsubResourcesMap,
GeneratedRedisResourcesMap,
GeneratedResourceManagerResourcesMap,
GeneratedSecurityCenterResourcesMap,
GeneratedSourceRepoResourcesMap,
GeneratedSpannerResourcesMap,
GeneratedSqlResourcesMap,
Expand Down Expand Up @@ -362,10 +359,9 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config := Config{
Project: d.Get("project").(string),
Region: d.Get("region").(string),
Zone: d.Get("zone").(string),
UserProjectOverride: d.Get("user_project_override").(bool),
Project: d.Get("project").(string),
Region: d.Get("region").(string),
Zone: d.Get("zone").(string),
}

// Add credential source
Expand Down Expand Up @@ -406,6 +402,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config.PubsubBasePath = d.Get(PubsubCustomEndpointEntryKey).(string)
config.RedisBasePath = d.Get(RedisCustomEndpointEntryKey).(string)
config.ResourceManagerBasePath = d.Get(ResourceManagerCustomEndpointEntryKey).(string)
config.SecurityCenterBasePath = d.Get(SecurityCenterCustomEndpointEntryKey).(string)
config.SourceRepoBasePath = d.Get(SourceRepoCustomEndpointEntryKey).(string)
config.SpannerBasePath = d.Get(SpannerCustomEndpointEntryKey).(string)
config.SqlBasePath = d.Get(SqlCustomEndpointEntryKey).(string)
Expand Down Expand Up @@ -464,6 +461,7 @@ func ConfigureBasePaths(c *Config) {
c.PubsubBasePath = PubsubDefaultBasePath
c.RedisBasePath = RedisDefaultBasePath
c.ResourceManagerBasePath = ResourceManagerDefaultBasePath
c.SecurityCenterBasePath = SecurityCenterDefaultBasePath
c.SourceRepoBasePath = SourceRepoDefaultBasePath
c.SpannerBasePath = SpannerDefaultBasePath
c.SqlBasePath = SqlDefaultBasePath
Expand Down
34 changes: 34 additions & 0 deletions google/provider_security_center_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// ----------------------------------------------------------------------------
//
// *** 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"

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
var SecurityCenterDefaultBasePath = "https://securitycenter.googleapis.com/v1/"
var SecurityCenterCustomEndpointEntryKey = "security_center_custom_endpoint"
var SecurityCenterCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_SECURITY_CENTER_CUSTOM_ENDPOINT",
}, SecurityCenterDefaultBasePath),
}

var GeneratedSecurityCenterResourcesMap = map[string]*schema.Resource{
"google_scc_source": resourceSecurityCenterSource(),
}
Loading

0 comments on commit 773214f

Please sign in to comment.