Skip to content

Commit

Permalink
Added tag product and tagkey resource (hashicorp#4565) (hashicorp#3062)
Browse files Browse the repository at this point in the history
* Added tag product and tagkey resource

* Skipped vcr tests and added id_format and import_format

vcr tests don't work due to randomness

* Added self_link definition

* Added tag key update test

* Re-added id_format and import_format

* Marked error code 10 as retryable

See https://github.com/googleapis/googleapis/blob/8f117308d5bb55816953a0d6ad1a7d27a69a7d3f/google/rpc/code.proto#L130

* Added additional logging of potentially-retriable errors

* Switched to custom import

generated imports can't handle slashes in ids

* Removed error code 10 from retry errors

TLDR if an operation returns error code 10, we can't actually retry the operation itself; we would have to retry the original POST, which would take a larger modification to creating an object

* Added mutex for tagkey operations

* Removed logging line for manual testing

* Run tags resource tests sequentially due to concurrency issues

* Switched tagkey mutex to use parent field directly

* Made tagkey tests eligible for VCR and non-parallel

* Switched to self_link/id_format/import_format using name_from_self_link

* Cleaned up docs

* Removed etag field

* Corrected id/import formats to match self link

* Removed custom import

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Mar 17, 2021
1 parent 59f6b71 commit fb0ff2c
Show file tree
Hide file tree
Showing 11 changed files with 930 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/4565.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_tags_tag_key`
```
3 changes: 3 additions & 0 deletions google-beta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ type Config struct {
SpannerBasePath string
SQLBasePath string
StorageBasePath string
TagsBasePath string
TPUBasePath string
VPCAccessBasePath string
WorkflowsBasePath string
Expand Down Expand Up @@ -245,6 +246,7 @@ var SourceRepoDefaultBasePath = "https://sourcerepo.googleapis.com/v1/"
var SpannerDefaultBasePath = "https://spanner.googleapis.com/v1/"
var SQLDefaultBasePath = "https://sqladmin.googleapis.com/sql/v1beta4/"
var StorageDefaultBasePath = "https://storage.googleapis.com/storage/v1/"
var TagsDefaultBasePath = "https://cloudresourcemanager.googleapis.com/v3/"
var TPUDefaultBasePath = "https://tpu.googleapis.com/v1/"
var VPCAccessDefaultBasePath = "https://vpcaccess.googleapis.com/v1beta1/"
var WorkflowsDefaultBasePath = "https://workflows.googleapis.com/v1beta/"
Expand Down Expand Up @@ -1011,6 +1013,7 @@ func ConfigureBasePaths(c *Config) {
c.SpannerBasePath = SpannerDefaultBasePath
c.SQLBasePath = SQLDefaultBasePath
c.StorageBasePath = StorageDefaultBasePath
c.TagsBasePath = TagsDefaultBasePath
c.TPUBasePath = TPUDefaultBasePath
c.VPCAccessBasePath = VPCAccessDefaultBasePath
c.WorkflowsBasePath = WorkflowsDefaultBasePath
Expand Down
29 changes: 29 additions & 0 deletions google-beta/error_retry_predicates_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package google

import (
"strconv"
"testing"

"google.golang.org/api/googleapi"
Expand Down Expand Up @@ -49,3 +50,31 @@ func TestIsAppEngineRetryableError_serverError(t *testing.T) {
t.Errorf("Error incorrectly detected as retryable")
}
}

func TestIsCommonRetryableErrorCode_retryableErrorCode(t *testing.T) {
codes := []int{429, 500, 502, 503}
for _, code := range codes {
code := code
t.Run(strconv.Itoa(code), func(t *testing.T) {
err := googleapi.Error{
Code: code,
Body: "some text describing error",
}
isRetryable, _ := isCommonRetryableErrorCode(&err)
if !isRetryable {
t.Errorf("Error not detected as retryable")
}
})
}
}

func TestIsCommonRetryableErrorCode_otherError(t *testing.T) {
err := googleapi.Error{
Code: 404,
Body: "Some unretryable issue",
}
isRetryable, _ := isCommonRetryableErrorCode(&err)
if isRetryable {
t.Errorf("Error incorrectly detected as retryable")
}
}
14 changes: 12 additions & 2 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,14 @@ func Provider() *schema.Provider {
"GOOGLE_STORAGE_CUSTOM_ENDPOINT",
}, StorageDefaultBasePath),
},
"tags_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_TAGS_CUSTOM_ENDPOINT",
}, TagsDefaultBasePath),
},
"tpu_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -825,9 +833,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 214
// Generated resources: 215
// Generated IAM resources: 108
// Total generated resources: 322
// Total generated resources: 323
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1155,6 +1163,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_storage_object_access_control": resourceStorageObjectAccessControl(),
"google_storage_default_object_access_control": resourceStorageDefaultObjectAccessControl(),
"google_storage_hmac_key": resourceStorageHmacKey(),
"google_tags_tag_key": resourceTagsTagKey(),
"google_tpu_node": resourceTPUNode(),
"google_vpc_access_connector": resourceVPCAccessConnector(),
"google_workflows_workflow": resourceWorkflowsWorkflow(),
Expand Down Expand Up @@ -1423,6 +1432,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.SpannerBasePath = d.Get("spanner_custom_endpoint").(string)
config.SQLBasePath = d.Get("sql_custom_endpoint").(string)
config.StorageBasePath = d.Get("storage_custom_endpoint").(string)
config.TagsBasePath = d.Get("tags_custom_endpoint").(string)
config.TPUBasePath = d.Get("tpu_custom_endpoint").(string)
config.VPCAccessBasePath = d.Get("vpc_access_custom_endpoint").(string)
config.WorkflowsBasePath = d.Get("workflows_custom_endpoint").(string)
Expand Down
2 changes: 1 addition & 1 deletion google-beta/resource_dataflow_flex_template_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"google.golang.org/api/compute/v1"
compute "google.golang.org/api/compute/v1"
)

func TestAccDataflowFlexTemplateJob_basic(t *testing.T) {
Expand Down
Loading

0 comments on commit fb0ff2c

Please sign in to comment.