generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 104
/
schema.tmpl
79 lines (67 loc) · 2.59 KB
/
schema.tmpl
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
// Code generated by generators/resource/main.go; DO NOT EDIT.
package {{ .PackageName }}
import (
"context"
{{if .ImportRegexp }}"regexp"{{- end}}
{{if .ImportFrameworkAttr }}"github.com/hashicorp/terraform-plugin-framework/attr"{{- end}}
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
. "github.com/hashicorp/terraform-provider-awscc/internal/generic"
"github.com/hashicorp/terraform-provider-awscc/internal/registry"
{{ if .ImportValidate }}"github.com/hashicorp/terraform-provider-awscc/internal/validate"{{- end }}
)
func init() {
registry.AddResourceTypeFactory("{{ .TerraformTypeName }}", {{ .FactoryFunctionName }})
}
// {{ .FactoryFunctionName }} returns the Terraform {{ .TerraformTypeName }} resource type.
// This Terraform resource type corresponds to the CloudFormation {{ .CloudFormationTypeName }} resource type.
func {{ .FactoryFunctionName }}(ctx context.Context) (provider.ResourceType, error) {
attributes := {{ .RootPropertiesSchema }}
{{ if .SyntheticIDAttribute }}
attributes["id"] = tfsdk.Attribute{
Description: "Uniquely identifies the resource.",
Type: types.StringType,
Computed: true,
PlanModifiers: []tfsdk.AttributePlanModifier{
tfsdk.UseStateForUnknown(),
},
}
{{- end }}
schema := tfsdk.Schema{
Description: {{ .SchemaDescription | printf "%q" }},
Version: {{ .SchemaVersion }},
Attributes: attributes,
}
var opts ResourceTypeOptions
opts = opts.WithCloudFormationTypeName("{{ .CloudFormationTypeName }}").WithTerraformTypeName("{{ .TerraformTypeName }}")
opts = opts.WithTerraformSchema(schema)
opts = opts.WithSyntheticIDAttribute({{ .SyntheticIDAttribute }})
opts = opts.WithAttributeNameMap(map[string]string{
{{- range $key, $value := .AttributeNameMap }}
"{{ $key }}": "{{ $value }}",
{{- end }}
})
{{ if not .HasUpdateMethod }}
opts = opts.IsImmutableType(true)
{{- end }}
{{ if .WriteOnlyPropertyPaths }}
opts = opts.WithWriteOnlyPropertyPaths([]string{
{{- range .WriteOnlyPropertyPaths }}
"{{ . }}",
{{- end }}
})
{{- end }}
opts = opts.WithCreateTimeoutInMinutes({{ .CreateTimeoutInMinutes }}).WithDeleteTimeoutInMinutes({{ .DeleteTimeoutInMinutes }})
{{ if .HasUpdateMethod }}
opts = opts.WithUpdateTimeoutInMinutes({{ .UpdateTimeoutInMinutes }})
{{- end }}
{{ if .RequiredAttributesValidator }}
opts = opts.WithRequiredAttributesValidators({{ .RequiredAttributesValidator }})
{{- end }}
resourceType, err := NewResourceType(ctx, opts...)
if err != nil {
return nil, err
}
return resourceType, nil
}