/
security_group_schema.go
121 lines (114 loc) · 4.22 KB
/
security_group_schema.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
package edgegw
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
schemaD "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
schemaR "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
superschema "github.com/FrangipaneTeam/terraform-plugin-framework-superschema"
fstringvalidator "github.com/FrangipaneTeam/terraform-plugin-framework-validators/stringvalidator"
)
func securityGroupSchema(_ context.Context) superschema.Schema {
return superschema.Schema{
Resource: superschema.SchemaDetails{
MarkdownDescription: "The Security Group resource allows you to manage an security group in an Edge Gateway.",
},
DataSource: superschema.SchemaDetails{
MarkdownDescription: "The Security Group data source allows you to retrieve information about an security group in an Edge Gateway.",
},
Attributes: map[string]superschema.Attribute{
"id": superschema.StringAttribute{
Common: &schemaR.StringAttribute{
Computed: true,
MarkdownDescription: "The ID of the Security Group.",
},
Resource: &schemaR.StringAttribute{
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
DataSource: &schemaD.StringAttribute{
Optional: true,
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("name"), path.MatchRoot("id")),
},
},
},
"name": superschema.StringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The name of the security group.",
},
Resource: &schemaR.StringAttribute{
Required: true,
},
DataSource: &schemaD.StringAttribute{
Computed: true,
Optional: true,
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("name"), path.MatchRoot("id")),
},
},
},
"edge_gateway_name": superschema.StringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The name of the Edge Gateway.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplaceIfConfigured(),
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("edge_gateway_name"), path.MatchRoot("edge_gateway_id")),
},
},
},
"edge_gateway_id": superschema.StringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The ID of the Edge Gateway.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.RequiresReplaceIfConfigured(),
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.ExactlyOneOf(path.MatchRoot("edge_gateway_name"), path.MatchRoot("edge_gateway_id")),
},
},
},
"description": superschema.StringAttribute{
Common: &schemaR.StringAttribute{
MarkdownDescription: "The description of the security group.",
},
Resource: &schemaR.StringAttribute{
Optional: true,
},
DataSource: &schemaD.StringAttribute{
Computed: true,
},
},
"member_org_network_ids": superschema.SetAttribute{
Common: &schemaR.SetAttribute{
MarkdownDescription: "The list of organization network IDs to which the security group is applied.",
ElementType: types.StringType,
},
Resource: &schemaR.SetAttribute{
Optional: true,
Validators: []validator.Set{
setvalidator.ValueStringsAre(fstringvalidator.IsURN()),
// TODO Add validator to check if URN is network https://github.com/FrangipaneTeam/terraform-plugin-framework-validators/issues/76
},
},
DataSource: &schemaD.SetAttribute{
Computed: true,
},
},
},
}
}