Skip to content
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

fix documentai so eu region is supported #6229

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mmv1/products/documentai/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ display_name: Essential Contacts
versions:
- !ruby/object:Api::Product::Version
name: ga
base_url: https://documentai.googleapis.com/v1/
base_url: https://{{location}}-documentai.googleapis.com/v1/
scopes:
- https://www.googleapis.com/auth/cloud-platform
apis_required:
Expand All @@ -27,9 +27,7 @@ apis_required:
objects:
- !ruby/object:Api::Resource
name: 'Processor'
create_url: 'projects/{{project}}/locations/{{location}}/processors'
self_link: '{{name}}'
base_url: '{{name}}'
base_url: 'projects/{{project}}/locations/{{location}}/processors'
input: true
references: !ruby/object:Api::Resource::ReferenceLinks
guides:
Expand Down
17 changes: 16 additions & 1 deletion mmv1/products/documentai/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,40 @@
--- !ruby/object:Provider::Terraform::Config
overrides: !ruby/object:Overrides::ResourceOverrides
Processor: !ruby/object:Overrides::Terraform::ResourceOverride
import_format: ["{{%name}}"]
examples:
- !ruby/object:Provider::Terraform::Examples
name: "documentai_processor"
primary_resource_id: "processor"
vars:
processor_name: "test-processor"
- !ruby/object:Provider::Terraform::Examples
name: "documentai_processor_eu"
primary_resource_id: "processor"
skip_docs: true
vars:
processor_name: "test-processor"
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
custom_flatten: templates/terraform/custom_flatten/name_from_self_link.erb
ProcessorDefaultVersion: !ruby/object:Overrides::Terraform::ResourceOverride
skip_delete: true
import_format: ["{{%processor}}"]
properties:
processor: !ruby/object:Overrides::Terraform::PropertyOverride
ignore_read: true
version: !ruby/object:Overrides::Terraform::PropertyOverride
diff_suppress_func: projectNumberDiffSupress
examples:
- !ruby/object:Provider::Terraform::Examples
name: "documentai_default_version"
primary_resource_id: "processor"
vars:
processor_name: "test-processor"
custom_code: !ruby/object:Provider::Terraform::CustomCode
pre_create: templates/terraform/pre_create/document_ai_processor_default_version_interpolate_location.go.erb
pre_update: templates/terraform/pre_create/document_ai_processor_default_version_interpolate_location.go.erb
pre_delete: templates/terraform/pre_create/document_ai_processor_default_version_interpolate_location.go.erb
pre_read: templates/terraform/pre_create/document_ai_processor_default_version_interpolate_location.go.erb

# This is for copying files over
files: !ruby/object:Provider::Config::Files
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "google_document_ai_processor" "<%= ctx[:primary_resource_id] %>" {
location = "eu"
display_name = "<%= ctx[:vars]['processor_name'] %>"
type = "OCR_PROCESSOR"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if strings.Contains(url,"https://-"){
location := GetRegionFromRegionalSelfLink(url)
url = strings.TrimPrefix(url, "https://")
url = "https://" + location + url
}
13 changes: 13 additions & 0 deletions mmv1/third_party/terraform/utils/common_diff_suppress.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"encoding/hex"
"net"
"regexp"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -226,4 +227,16 @@ func lastSlashDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
old = old[:last]
}
return new == old
}

// Suppress diffs when the value read from api
// has the project number instead of the project name
func projectNumberDiffSupress(_, old, new string, _ *schema.ResourceData) bool {
var a2, b2 string
reN := regexp.MustCompile("projects/\\d+")
re := regexp.MustCompile("projects/[^/]+")
replacement := []byte("projects/equal")
a2 = string(reN.ReplaceAll([]byte(old), replacement))
b2 = string(re.ReplaceAll([]byte(new), replacement))
return a2 == b2
}