Skip to content

Commit f87419f

Browse files
tgc-revival: support SecretManagerSecret (#15473) (#4659)
[upstream:fe71c31929e3527f41cb31ce3225d8fc4b5e2c5c] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent db42fba commit f87419f

30 files changed

+2155
-1
lines changed

pkg/cai2hcl/converters/convert_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ func ConvertResource(asset caiasset.Asset) ([]*models.TerraformResourceBlock, er
4141
} else if strings.Contains(asset.Name, "regions") {
4242
converter = ConverterMap[asset.Type]["ComputeRegionHealthCheck"]
4343
}
44+
case "secretmanager.googleapis.com/Secret":
45+
if strings.Contains(asset.Name, "locations") {
46+
converter = ConverterMap[asset.Type]["SecretManagerRegionalRegionalSecret"]
47+
} else {
48+
converter = ConverterMap[asset.Type]["SecretManagerSecret"]
49+
}
4450
}
4551
}
4652

pkg/cai2hcl/converters/resource_converters.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import (
4040
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/pubsub"
4141
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/redis"
4242
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/resourcemanager"
43+
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/secretmanager"
44+
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/secretmanagerregional"
4345

4446
tpg_provider "github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/provider"
4547
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -247,4 +249,8 @@ var ConverterMap = map[string]map[string]models.Cai2hclConverter{
247249
"redis.googleapis.com/Instance": {
248250
"Default": redis.NewRedisInstanceCai2hclConverter(provider),
249251
},
252+
"secretmanager.googleapis.com/Secret": {
253+
"SecretManagerRegionalRegionalSecret": secretmanagerregional.NewSecretManagerRegionalRegionalSecretCai2hclConverter(provider),
254+
"SecretManagerSecret": secretmanager.NewSecretManagerSecretCai2hclConverter(provider),
255+
},
250256
}

pkg/provider/provider_mmv1_resources.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/pubsub"
2727
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/redis"
2828
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/resourcemanager"
29+
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/secretmanager"
30+
"github.com/GoogleCloudPlatform/terraform-google-conversion/v7/pkg/services/secretmanagerregional"
2931
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
3032
)
3133

@@ -36,7 +38,7 @@ var handwrittenTfplan2caiResources = map[string]*schema.Resource{
3638
// ####### END handwritten resources ###########
3739
}
3840

39-
// Generated resources: 66
41+
// Generated resources: 68
4042
var generatedResources = map[string]*schema.Resource{
4143
"google_alloydb_backup": alloydb.ResourceAlloydbBackup(),
4244
"google_alloydb_cluster": alloydb.ResourceAlloydbCluster(),
@@ -104,4 +106,6 @@ var generatedResources = map[string]*schema.Resource{
104106
"google_pubsub_topic": pubsub.ResourcePubsubTopic(),
105107
"google_redis_cluster": redis.ResourceRedisCluster(),
106108
"google_redis_instance": redis.ResourceRedisInstance(),
109+
"google_secret_manager_secret": secretmanager.ResourceSecretManagerSecret(),
110+
"google_secret_manager_regional_secret": secretmanagerregional.ResourceSecretManagerRegionalRegionalSecret(),
107111
}
Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,326 @@
1+
// ----------------------------------------------------------------------------
2+
//
3+
// *** AUTO GENERATED CODE *** Type: MMv1 ***
4+
//
5+
// ----------------------------------------------------------------------------
6+
//
7+
// This code is generated by Magic Modules using the following:
8+
//
9+
// Configuration: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/secretmanager/Secret.yaml
10+
// Template: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/tgc_next/services/resource.go.tmpl
11+
//
12+
// DO NOT EDIT this file directly. Any changes made to this file will be
13+
// overwritten during the next generation cycle.
14+
//
15+
// ----------------------------------------------------------------------------
16+
17+
package secretmanager
18+
19+
import (
20+
"context"
21+
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
23+
)
24+
25+
const SecretManagerSecretAssetType string = "secretmanager.googleapis.com/Secret"
26+
27+
const SecretManagerSecretSchemaName string = "google_secret_manager_secret"
28+
29+
// Prevent ForceNew when upgrading replication.automatic -> replication.auto
30+
func secretManagerSecretAutoCustomizeDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) error {
31+
oAutomatic, nAutomatic := diff.GetChange("replication.0.automatic")
32+
_, nAuto := diff.GetChange("replication.0.auto")
33+
autoLen := len(nAuto.([]interface{}))
34+
35+
// Do not ForceNew if we are removing "automatic" while adding "auto"
36+
if oAutomatic == true && nAutomatic == false && autoLen > 0 {
37+
return nil
38+
}
39+
40+
if diff.HasChange("replication.0.automatic") {
41+
if err := diff.ForceNew("replication.0.automatic"); err != nil {
42+
return err
43+
}
44+
}
45+
46+
if diff.HasChange("replication.0.auto") {
47+
if err := diff.ForceNew("replication.0.auto"); err != nil {
48+
return err
49+
}
50+
}
51+
52+
return nil
53+
}
54+
55+
func ResourceSecretManagerSecret() *schema.Resource {
56+
return &schema.Resource{
57+
Schema: map[string]*schema.Schema{
58+
"replication": {
59+
Type: schema.TypeList,
60+
Required: true,
61+
ForceNew: true,
62+
Description: `The replication policy of the secret data attached to the Secret. It cannot be changed
63+
after the Secret has been created.`,
64+
MaxItems: 1,
65+
Elem: &schema.Resource{
66+
Schema: map[string]*schema.Schema{
67+
"auto": {
68+
Type: schema.TypeList,
69+
Optional: true,
70+
ForceNew: true,
71+
Description: `The Secret will automatically be replicated without any restrictions.`,
72+
MaxItems: 1,
73+
Elem: &schema.Resource{
74+
Schema: map[string]*schema.Schema{
75+
"customer_managed_encryption": {
76+
Type: schema.TypeList,
77+
Optional: true,
78+
Description: `The customer-managed encryption configuration of the Secret.
79+
If no configuration is provided, Google-managed default
80+
encryption is used.`,
81+
MaxItems: 1,
82+
Elem: &schema.Resource{
83+
Schema: map[string]*schema.Schema{
84+
"kms_key_name": {
85+
Type: schema.TypeString,
86+
Required: true,
87+
Description: `The resource name of the Cloud KMS CryptoKey used to encrypt secret payloads.`,
88+
},
89+
},
90+
},
91+
},
92+
},
93+
},
94+
ExactlyOneOf: []string{"replication.0.user_managed", "replication.0.auto"},
95+
},
96+
"user_managed": {
97+
Type: schema.TypeList,
98+
Optional: true,
99+
ForceNew: true,
100+
Description: `The Secret will be replicated to the regions specified by the user.`,
101+
MaxItems: 1,
102+
Elem: &schema.Resource{
103+
Schema: map[string]*schema.Schema{
104+
"replicas": {
105+
Type: schema.TypeList,
106+
Required: true,
107+
ForceNew: true,
108+
Description: `The list of Replicas for this Secret. Cannot be empty.`,
109+
MinItems: 1,
110+
Elem: &schema.Resource{
111+
Schema: map[string]*schema.Schema{
112+
"location": {
113+
Type: schema.TypeString,
114+
Required: true,
115+
ForceNew: true,
116+
Description: `The canonical IDs of the location to replicate data. For example: "us-east1".`,
117+
},
118+
"customer_managed_encryption": {
119+
Type: schema.TypeList,
120+
Optional: true,
121+
Description: `Customer Managed Encryption for the secret.`,
122+
MaxItems: 1,
123+
Elem: &schema.Resource{
124+
Schema: map[string]*schema.Schema{
125+
"kms_key_name": {
126+
Type: schema.TypeString,
127+
Required: true,
128+
Description: `Describes the Cloud KMS encryption key that will be used to protect destination secret.`,
129+
},
130+
},
131+
},
132+
},
133+
},
134+
},
135+
},
136+
},
137+
},
138+
ExactlyOneOf: []string{"replication.0.user_managed", "replication.0.auto"},
139+
},
140+
},
141+
},
142+
},
143+
"secret_id": {
144+
Type: schema.TypeString,
145+
Required: true,
146+
ForceNew: true,
147+
Description: `This must be unique within the project.`,
148+
},
149+
"annotations": {
150+
Type: schema.TypeMap,
151+
Optional: true,
152+
Description: `Custom metadata about the secret.
153+
154+
Annotations are distinct from various forms of labels. Annotations exist to allow
155+
client tools to store their own state information without requiring a database.
156+
157+
Annotation keys must be between 1 and 63 characters long, have a UTF-8 encoding of
158+
maximum 128 bytes, begin and end with an alphanumeric character ([a-z0-9A-Z]), and
159+
may have dashes (-), underscores (_), dots (.), and alphanumerics in between these
160+
symbols.
161+
162+
The total size of annotation keys and values must be less than 16KiB.
163+
164+
An object containing a list of "key": value pairs. Example:
165+
{ "name": "wrench", "mass": "1.3kg", "count": "3" }.
166+
167+
168+
**Note**: This field is non-authoritative, and will only manage the annotations present in your configuration.
169+
Please refer to the field 'effective_annotations' for all of the annotations present on the resource.`,
170+
Elem: &schema.Schema{Type: schema.TypeString},
171+
},
172+
"expire_time": {
173+
Type: schema.TypeString,
174+
Computed: true,
175+
Optional: true,
176+
Description: `Timestamp in UTC when the Secret is scheduled to expire. This is always provided on output, regardless of what was sent on input.
177+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
178+
Only one of 'expire_time' or 'ttl' can be provided.`,
179+
},
180+
"labels": {
181+
Type: schema.TypeMap,
182+
Optional: true,
183+
Description: `The labels assigned to this Secret.
184+
185+
Label keys must be between 1 and 63 characters long, have a UTF-8 encoding of maximum 128 bytes,
186+
and must conform to the following PCRE regular expression: [\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}
187+
188+
Label values must be between 0 and 63 characters long, have a UTF-8 encoding of maximum 128 bytes,
189+
and must conform to the following PCRE regular expression: [\p{Ll}\p{Lo}\p{N}_-]{0,63}
190+
191+
No more than 64 labels can be assigned to a given resource.
192+
193+
An object containing a list of "key": value pairs. Example:
194+
{ "name": "wrench", "mass": "1.3kg", "count": "3" }.
195+
196+
197+
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
198+
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
199+
Elem: &schema.Schema{Type: schema.TypeString},
200+
},
201+
"rotation": {
202+
Type: schema.TypeList,
203+
Optional: true,
204+
Description: `The rotation time and period for a Secret. At 'next_rotation_time', Secret Manager will send a Pub/Sub notification to the topics configured on the Secret. 'topics' must be set to configure rotation.`,
205+
MaxItems: 1,
206+
Elem: &schema.Resource{
207+
Schema: map[string]*schema.Schema{
208+
"next_rotation_time": {
209+
Type: schema.TypeString,
210+
Optional: true,
211+
Description: `Timestamp in UTC at which the Secret is scheduled to rotate.
212+
A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".`,
213+
RequiredWith: []string{"rotation.0.rotation_period"},
214+
},
215+
"rotation_period": {
216+
Type: schema.TypeString,
217+
Optional: true,
218+
Description: `The Duration between rotation notifications. Must be in seconds and at least 3600s (1h) and at most 3153600000s (100 years).
219+
If rotationPeriod is set, 'next_rotation_time' must be set. 'next_rotation_time' will be advanced by this period when the service automatically sends rotation notifications.`,
220+
},
221+
},
222+
},
223+
RequiredWith: []string{"topics"},
224+
},
225+
"tags": {
226+
Type: schema.TypeMap,
227+
Optional: true,
228+
ForceNew: true,
229+
Description: `A map of resource manager tags.
230+
Resource manager tag keys and values have the same definition as resource manager tags.
231+
Keys must be in the format tagKeys/{tag_key_id}, and values are in the format tagValues/{tag_value_id}.`,
232+
Elem: &schema.Schema{Type: schema.TypeString},
233+
},
234+
"topics": {
235+
Type: schema.TypeList,
236+
Optional: true,
237+
Description: `A list of up to 10 Pub/Sub topics to which messages are published when control plane operations are called on the secret or its versions.`,
238+
Elem: &schema.Resource{
239+
Schema: map[string]*schema.Schema{
240+
"name": {
241+
Type: schema.TypeString,
242+
Required: true,
243+
Description: `The resource name of the Pub/Sub topic that will be published to, in the following format: projects/*/topics/*.
244+
For publication to succeed, the Secret Manager Service Agent service account must have pubsub.publisher permissions on the topic.`,
245+
},
246+
},
247+
},
248+
},
249+
"ttl": {
250+
Type: schema.TypeString,
251+
Optional: true,
252+
Description: `The TTL for the Secret.
253+
A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".
254+
Only one of 'ttl' or 'expire_time' can be provided.`,
255+
},
256+
"version_aliases": {
257+
Type: schema.TypeMap,
258+
Optional: true,
259+
Description: `Mapping from version alias to version name.
260+
261+
A version alias is a string with a maximum length of 63 characters and can contain
262+
uppercase and lowercase letters, numerals, and the hyphen (-) and underscore ('_')
263+
characters. An alias string must start with a letter and cannot be the string
264+
'latest' or 'NEW'. No more than 50 aliases can be assigned to a given secret.
265+
266+
An object containing a list of "key": value pairs. Example:
267+
{ "name": "wrench", "mass": "1.3kg", "count": "3" }.`,
268+
Elem: &schema.Schema{Type: schema.TypeString},
269+
},
270+
"version_destroy_ttl": {
271+
Type: schema.TypeString,
272+
Optional: true,
273+
Description: `Secret Version TTL after destruction request.
274+
This is a part of the delayed delete feature on Secret Version.
275+
For secret with versionDestroyTtl>0, version destruction doesn't happen immediately
276+
on calling destroy instead the version goes to a disabled state and
277+
the actual destruction happens after this TTL expires.`,
278+
},
279+
"create_time": {
280+
Type: schema.TypeString,
281+
Computed: true,
282+
Description: `The time at which the Secret was created.`,
283+
},
284+
"effective_annotations": {
285+
Type: schema.TypeMap,
286+
Computed: true,
287+
Description: `All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services.`,
288+
Elem: &schema.Schema{Type: schema.TypeString},
289+
},
290+
"effective_labels": {
291+
Type: schema.TypeMap,
292+
Computed: true,
293+
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
294+
Elem: &schema.Schema{Type: schema.TypeString},
295+
},
296+
"name": {
297+
Type: schema.TypeString,
298+
Computed: true,
299+
Description: `The resource name of the Secret. Format:
300+
'projects/{{project}}/secrets/{{secret_id}}'`,
301+
},
302+
"terraform_labels": {
303+
Type: schema.TypeMap,
304+
Computed: true,
305+
Description: `The combination of labels configured directly on the resource
306+
and default labels configured on the provider.`,
307+
Elem: &schema.Schema{Type: schema.TypeString},
308+
},
309+
"deletion_protection": {
310+
Type: schema.TypeBool,
311+
Optional: true,
312+
Description: `Whether Terraform will be prevented from destroying the secret. Defaults to false.
313+
When the field is set to true in Terraform state, a 'terraform apply'
314+
or 'terraform destroy' that would delete the secret will fail.`,
315+
Default: false,
316+
},
317+
"project": {
318+
Type: schema.TypeString,
319+
Optional: true,
320+
Computed: true,
321+
ForceNew: true,
322+
},
323+
},
324+
UseJSONNumber: true,
325+
}
326+
}

0 commit comments

Comments
 (0)