This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
generated from crossplane-contrib/provider-jet-template
-
Notifications
You must be signed in to change notification settings - Fork 21
Finalize config for API group/kind calculation #25
Merged
turkenh
merged 5 commits into
crossplane-contrib:main
from
turkenh:finalize-kinds-and-groups
Jan 4, 2022
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
31ce86e
Update config for groups until DataProc
turkenh 502fac5
Update terrajet to latest
turkenh 804e36d
Update config for all groups
turkenh 161001f
Refactor group/kind override
turkenh 07c8435
Add IdP and OAuth as GCP specific Acronyms
turkenh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package bigtable | ||
|
||
import "github.com/crossplane/terrajet/pkg/config" | ||
|
||
// Configure configures individual resources by adding custom | ||
// ResourceConfigurators. | ||
func Configure(p *config.Provider) { | ||
p.AddResourceConfigurator("google_bigtable_gc_policy", func(r *config.Resource) { | ||
r.Kind = "GarbageCollectionPolicy" | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package identityplatform | ||
|
||
import "github.com/crossplane/terrajet/pkg/config" | ||
|
||
// Configure configures individual resources by adding custom | ||
// ResourceConfigurators. | ||
func Configure(p *config.Provider) { | ||
p.AddResourceConfigurator("google_identity_platform_default_supported_idp_config", func(r *config.Resource) { | ||
r.Kind = "DefaultSupportedIdPConfig" | ||
}) | ||
p.AddResourceConfigurator("google_identity_platform_oauth_idp_config", func(r *config.Resource) { | ||
r.Kind = "OAuthIdPConfig" | ||
}) | ||
p.AddResourceConfigurator("google_identity_platform_tenant_default_supported_idp_config", func(r *config.Resource) { | ||
r.Kind = "TenantDefaultSupportedIdPConfig" | ||
}) | ||
p.AddResourceConfigurator("google_identity_platform_tenant_oauth_idp_config", func(r *config.Resource) { | ||
r.Kind = "TenantOAuthIdPConfig" | ||
}) | ||
} |
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 |
---|---|---|
@@ -1,61 +1,114 @@ | ||
package config | ||
|
||
import ( | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/iancoleman/strcase" | ||
|
||
tjconfig "github.com/crossplane/terrajet/pkg/config" | ||
|
||
"github.com/crossplane-contrib/provider-jet-gcp/config/accessapproval" | ||
"github.com/crossplane-contrib/provider-jet-gcp/config/cloudplatform" | ||
"github.com/crossplane/terrajet/pkg/types/name" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func groupOverrides() tjconfig.ResourceOption { //nolint: gocyclo | ||
// Note(turkenh): The todo below will fix this linter error, disabling until | ||
// then | ||
// GroupKindCalculator returns the correct group and kind name for given TF | ||
// resource. | ||
type GroupKindCalculator func(resource string) (string, string) | ||
|
||
func externalNameConfig() tjconfig.ResourceOption { | ||
return func(r *tjconfig.Resource) { | ||
// Todo(turkenh): Use an single map for all resource => group mapping | ||
words := strings.Split(r.Name, "_") | ||
if _, ok := cloudplatform.Resources[r.Name]; ok { | ||
r.ShortGroup = "cloudplatform" | ||
} else if _, ok := accessapproval.Resources[r.Name]; ok { //nolint: gocritic | ||
// Todo(turkenh): Check how to fix linter "ifElseChain: rewrite if-else" | ||
// to switch statement that covers all checks here. | ||
r.ShortGroup = "accessapproval" | ||
} else if strings.HasPrefix(r.Name, "google_access_context_manager") || | ||
strings.HasPrefix(r.Name, "google_data_loss_prevention") { | ||
r.ShortGroup = words[1] + words[2] + words[3] | ||
r.Kind = strcase.ToCamel(strings.Join(words[4:], "_")) | ||
} else if strings.HasPrefix(r.Name, "google_active_directory") || | ||
strings.HasPrefix(r.Name, "google_app_engine") || | ||
strings.HasPrefix(r.Name, "google_assured_workloads") || | ||
strings.HasPrefix(r.Name, "google_binary_authorization") || | ||
strings.HasPrefix(r.Name, "google_deployment_manager") || | ||
strings.HasPrefix(r.Name, "google_essential_contacts") || | ||
strings.HasPrefix(r.Name, "google_game_services") || | ||
strings.HasPrefix(r.Name, "google_gke_hub") || | ||
strings.HasPrefix(r.Name, "google_identity_platform") || | ||
strings.HasPrefix(r.Name, "google_ml_engine") || | ||
strings.HasPrefix(r.Name, "google_network_management") || | ||
strings.HasPrefix(r.Name, "google_network_services") || | ||
strings.HasPrefix(r.Name, "google_service_networking") || | ||
strings.HasPrefix(r.Name, "google_resource_manager") || | ||
strings.HasPrefix(r.Name, "google_secret_manager") || | ||
strings.HasPrefix(r.Name, "google_org_policy") || | ||
strings.HasPrefix(r.Name, "google_vpc_access_connector") || | ||
// Examples: google_cloud_identity, google_cloud_run, | ||
// google_cloud_asset, google_data_fusion, google_data_source... | ||
strings.HasPrefix(r.Name, "google_cloud_") || strings.HasPrefix(r.Name, "google_data_") { | ||
|
||
r.ShortGroup = words[1] + words[2] | ||
r.Kind = strcase.ToCamel(strings.Join(words[3:], "_")) | ||
} | ||
r.ExternalName = tjconfig.IdentifierFromProvider | ||
} | ||
} | ||
|
||
func externalNameConfig() tjconfig.ResourceOption { | ||
func groupOverrides() tjconfig.ResourceOption { | ||
return func(r *tjconfig.Resource) { | ||
r.ExternalName = tjconfig.IdentifierFromProvider | ||
for k, v := range groupMap { | ||
ok, err := regexp.MatchString(k, r.Name) | ||
if err != nil { | ||
panic(errors.Wrap(err, "cannot match regular expression")) | ||
} | ||
if ok { | ||
r.ShortGroup, r.Kind = v(r.Name) | ||
return | ||
} | ||
} | ||
} | ||
} | ||
|
||
var groupMap = map[string]GroupKindCalculator{ | ||
// Note(turkenh): The following resources are listed under "Cloud Platform" | ||
// section in Terraform Documentation. | ||
"google_billing_subaccount$": ReplaceGroupWords("cloudplatform", 0), | ||
"google_folder$": ReplaceGroupWords("cloudplatform", 0), | ||
"google_folder_iam.*": ReplaceGroupWords("cloudplatform", 0), | ||
"google_folder_organization.*": ReplaceGroupWords("cloudplatform", 0), | ||
"google_organization_iam.*": ReplaceGroupWords("cloudplatform", 0), | ||
"google_organization_policy.*": ReplaceGroupWords("cloudplatform", 0), | ||
"google_project$": ReplaceGroupWords("cloudplatform", 0), | ||
"google_project_iam.*": ReplaceGroupWords("cloudplatform", 0), | ||
"google_project_service.*": ReplaceGroupWords("cloudplatform", 0), | ||
"google_project_default_service_accounts$": ReplaceGroupWords("cloudplatform", 0), | ||
"google_project_organization_policy$": ReplaceGroupWords("cloudplatform", 0), | ||
"google_project_usage_export_bucket$": ReplaceGroupWords("cloudplatform", 0), | ||
"google_service_account.*": ReplaceGroupWords("cloudplatform", 0), | ||
"google_service_networking_peered_dns_domain$": ReplaceGroupWords("cloudplatform", 0), | ||
|
||
// Resources in "Access Approval" group. | ||
// Note(turkenh): The following resources are listed under "Access Approval" | ||
// section in Terraform Documentation. | ||
"google_.+_approval_settings$": ReplaceGroupWords("accessapproval", 0), | ||
|
||
"google_access_context_manager.+": ReplaceGroupWords("", 3), | ||
"google_data_loss_prevention.+": ReplaceGroupWords("", 3), | ||
|
||
"google_service_networking_connection$": ReplaceGroupWords("", 2), | ||
"google_active_directory.+": ReplaceGroupWords("", 2), | ||
"google_app_engine.+": ReplaceGroupWords("", 2), | ||
"google_assured_workloads.+": ReplaceGroupWords("", 2), | ||
"google_binary_authorization.+": ReplaceGroupWords("", 2), | ||
"google_container_analysis.+": ReplaceGroupWords("", 2), | ||
"google_deployment_manager.+": ReplaceGroupWords("", 2), | ||
"google_dialogflow_cx.+": ReplaceGroupWords("", 2), | ||
"google_essential_contacts.+": ReplaceGroupWords("", 2), | ||
"google_game_services.+": ReplaceGroupWords("", 2), | ||
"google_gke_hub.+": ReplaceGroupWords("", 2), | ||
"google_identity_platform.+": ReplaceGroupWords("", 2), | ||
"google_ml_engine.+": ReplaceGroupWords("", 2), | ||
"google_network_management.+": ReplaceGroupWords("", 2), | ||
"google_network_services.+": ReplaceGroupWords("", 2), | ||
"google_resource_manager.+": ReplaceGroupWords("", 2), | ||
"google_secret_manager.+": ReplaceGroupWords("", 2), | ||
"google_storage_transfer.+": ReplaceGroupWords("", 2), | ||
"google_org_policy.+": ReplaceGroupWords("", 2), | ||
"google_vertex_ai.+": ReplaceGroupWords("", 2), | ||
"google_vpc_access.+": ReplaceGroupWords("", 2), | ||
|
||
"google_cloud_asset.+": ReplaceGroupWords("", 2), | ||
"google_cloud_build.+": ReplaceGroupWords("", 2), | ||
"google_cloud_functions.+": ReplaceGroupWords("", 2), | ||
"google_cloud_identity.+": ReplaceGroupWords("", 2), | ||
"google_cloud_iot.+": ReplaceGroupWords("", 2), | ||
"google_cloud_tasks.+": ReplaceGroupWords("", 2), | ||
"google_cloud_scheduler.+": ReplaceGroupWords("", 2), | ||
"google_cloud_run.+": ReplaceGroupWords("", 2), | ||
|
||
"google_data_catalog.+": ReplaceGroupWords("", 2), | ||
"google_data_flow.+": ReplaceGroupWords("", 2), | ||
"google_data_fusion.+": ReplaceGroupWords("", 2), | ||
|
||
"google_os_config.+": ReplaceGroupWords("", 2), | ||
"google_os_login.+": ReplaceGroupWords("", 2), | ||
} | ||
|
||
// ReplaceGroupWords uses given group as the group of the resource and removes | ||
// a number of words in resource name before calculating the kind of the resource. | ||
func ReplaceGroupWords(group string, count int) GroupKindCalculator { | ||
return func(resource string) (string, string) { | ||
// "google_cloud_run_domain_mapping": "cloudrun" -> (cloudrun, DomainMapping) | ||
words := strings.Split(strings.TrimPrefix(resource, "google_"), "_") | ||
if group == "" { | ||
group = strings.Join(words[:count], "") | ||
} | ||
snakeKind := strings.Join(words[count:], "_") | ||
return group, name.NewFromSnake(snakeKind).Camel | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can add
idp
asIdP
in acronym list if that's how it appears. FWIW, we can callAddAcronym
in this repo as well since the list is global.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, added them (IdP and OAuth) as GCP specific acronyms for now. We can consider migration them to terrajet later.