-
Notifications
You must be signed in to change notification settings - Fork 156
/
0030-Optimize-startup-performance.patch
150 lines (141 loc) · 4.74 KB
/
0030-Optimize-startup-performance.patch
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
140
141
142
143
144
145
146
147
148
149
150
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Anton Tayanovskyy <[email protected]>
Date: Thu, 30 Nov 2023 14:28:37 -0500
Subject: [PATCH] Optimize startup performance
diff --git a/internal/provider/provider.go b/internal/provider/provider.go
index 92763850ac..ef67582664 100644
--- a/internal/provider/provider.go
+++ b/internal/provider/provider.go
@@ -312,7 +312,7 @@ func New(ctx context.Context) (*schema.Provider, error) {
interceptors := interceptorItems{}
if v.Tags != nil {
- schema := r.SchemaMap()
+ schema := schemaMapForTagsChecking(ctx, r, true)
// The data source has opted in to transparent tagging.
// Ensure that the schema look OK.
@@ -389,7 +389,7 @@ func New(ctx context.Context) (*schema.Provider, error) {
interceptors := interceptorItems{}
if v.Tags != nil {
- schema := r.SchemaMap()
+ schema := schemaMapForTagsChecking(ctx, r, false)
// The resource has opted in to transparent tagging.
// Ensure that the schema look OK.
diff --git a/internal/provider/provider_tagcheck.go b/internal/provider/provider_tagcheck.go
new file mode 100644
index 0000000000..35202ebd58
--- /dev/null
+++ b/internal/provider/provider_tagcheck.go
@@ -0,0 +1,28 @@
+package provider
+
+import (
+ "context"
+
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
+ "github.com/hashicorp/terraform-provider-aws/names"
+)
+
+type disableTagsSchemaCheckKey struct{}
+
+func DisableTagSchemaCheck(ctx context.Context) context.Context {
+ return context.WithValue(ctx, disableTagsSchemaCheckKey{}, true)
+}
+
+func schemaMapForTagsChecking(ctx context.Context, r *schema.Resource, tagsComputed bool) map[string]*schema.Schema {
+ flag := ctx.Value(disableTagsSchemaCheckKey{})
+ switch flag := flag.(type) {
+ case bool:
+ if flag {
+ return map[string]*schema.Schema{
+ names.AttrTags: &schema.Schema{Computed: tagsComputed},
+ names.AttrTagsAll: &schema.Schema{Computed: true},
+ }
+ }
+ }
+ return r.SchemaMap()
+}
diff --git a/shim/shim.go b/shim/shim.go
index e24e53fe17..3378f955bb 100644
--- a/shim/shim.go
+++ b/shim/shim.go
@@ -17,7 +17,7 @@ type UpstreamProvider struct {
}
func NewUpstreamProvider(ctx context.Context) (UpstreamProvider, error) {
- primary, err := provider.New(ctx)
+ primary, err := provider.New(provider.DisableTagSchemaCheck(ctx))
if err != nil {
return UpstreamProvider{}, err
}
@@ -44,44 +44,42 @@ func NewTagConfig(ctx context.Context, i interface{}) TagConfig {
// rationale for this is that Pulumi copies tags to tags_all before it hits the TF layer, so these
// attributes must match in schema.
func markTagsAllNotComputedForResources(sdkV2Provider *schema.Provider) {
-
- updateSchema := func(rn string, s map[string]*schema.Schema) map[string]*schema.Schema {
- updatedSchema := map[string]*schema.Schema{}
- for k, v := range s {
- if k == "tags_all" {
- if tagsSchema, ok := s["tags"]; ok {
- tagsAll := *tagsSchema
- updatedSchema[k] = &tagsAll
- } else {
- panic(fmt.Sprintf("Unable to edit tagsAll schema for %q", rn))
- }
- } else {
- updatedSchema[k] = v
- }
- }
- return updatedSchema
+ updatedResourcesMap := map[string]*schema.Resource{}
+ for rn, r := range sdkV2Provider.ResourcesMap {
+ updatedResourcesMap[rn] = markTagsAllNotComputedForResource(rn, r)
}
+ sdkV2Provider.ResourcesMap = updatedResourcesMap
+}
- updatedResource := func(rn string, r *schema.Resource) *schema.Resource {
- if _, ok := r.SchemaMap()["tags_all"]; !ok {
- return r
+func markTagsAllNotComputedForResource(rn string, r *schema.Resource) *schema.Resource {
+ u := *r
+ if r.SchemaFunc != nil {
+ old := r.SchemaFunc
+ u.SchemaFunc = func() map[string]*schema.Schema {
+ return markTagsAllNotComputedForSchema(rn, old())
}
+ } else {
+ u.Schema = markTagsAllNotComputedForSchema(rn, r.Schema)
+ }
+ return &u
+}
- u := *r
- if r.SchemaFunc != nil {
- old := r.SchemaFunc
- u.SchemaFunc = func() map[string]*schema.Schema {
- return updateSchema(rn, old())
+func markTagsAllNotComputedForSchema(rn string, s map[string]*schema.Schema) map[string]*schema.Schema {
+ if _, ok := s["tags_all"]; !ok {
+ return s
+ }
+ updatedSchema := map[string]*schema.Schema{}
+ for k, v := range s {
+ if k == "tags_all" {
+ if tagsSchema, ok := s["tags"]; ok {
+ tagsAll := *tagsSchema
+ updatedSchema[k] = &tagsAll
+ } else {
+ panic(fmt.Sprintf("Unable to edit tagsAll schema for %q", rn))
}
} else {
- u.Schema = updateSchema(rn, r.Schema)
+ updatedSchema[k] = v
}
- return &u
- }
-
- updatedResourcesMap := map[string]*schema.Resource{}
- for rn, r := range sdkV2Provider.ResourcesMap {
- updatedResourcesMap[rn] = updatedResource(rn, r)
}
- sdkV2Provider.ResourcesMap = updatedResourcesMap
+ return updatedSchema
}