-
Notifications
You must be signed in to change notification settings - Fork 68
/
overrides.go
139 lines (120 loc) · 5.92 KB
/
overrides.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package config
import (
"regexp"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pkg/errors"
tjconfig "github.com/upbound/upjet/pkg/config"
"github.com/upbound/upjet/pkg/types/name"
)
// VersionV1Beta1 is used to signify that the resource has been tested and external name configured
const VersionV1Beta1 = "v1beta1"
// 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) {
r.ExternalName = tjconfig.IdentifierFromProvider
}
}
func groupOverrides() tjconfig.ResourceOption {
return func(r *tjconfig.Resource) {
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_container_aws.+": ReplaceGroupWords("", 2),
"google_container_azure.+": 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_network_connectivity.+": 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_functions.+": ReplaceGroupWords("", 2),
"google_cloud_identity.+": 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),
"google_certificate_manager.+": ReplaceGroupWords("", 2),
"google_document_ai.+": ReplaceGroupWords("", 2),
"google_essential_contacts_contact$": 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
}
}
func defaultVersion() tjconfig.ResourceOption {
return func(r *tjconfig.Resource) {
r.Version = VersionV1Beta1
}
}
func descriptionOverrides() tjconfig.ResourceOption {
return func(r *tjconfig.Resource) {
tjconfig.ManipulateEveryField(r.TerraformResource, func(sch *schema.Schema) {
sch.Description = ""
})
}
}