Skip to content

Commit 9158ceb

Browse files
committed
[TF-34171] Adding a new resource tfe_organization_ttl_policy that describes the Max TTL policy for the organization
1 parent 6dd2ffb commit 9158ceb

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

internal/provider/provider_next.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ func (p *frameworkProvider) Resources(ctx context.Context) []func() resource.Res
185185
NewAzureOIDCConfigurationResource,
186186
NewVaultOIDCConfigurationResource,
187187
NewHYOKConfigurationResource,
188+
NewOrganizationTTLPolicyResource,
188189
}
189190
}
190191

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package provider
2+
3+
import (
4+
"context"
5+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
6+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault"
7+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
8+
9+
"github.com/hashicorp/terraform-plugin-framework/resource"
10+
"github.com/hashicorp/terraform-plugin-framework/types"
11+
12+
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
13+
)
14+
15+
// Resource schema definition
16+
type organizationTTLPolicyResource struct{}
17+
18+
type organizationTTLPolicyModel struct {
19+
Organization types.String `tfsdk:"organization"`
20+
UserToken types.String `tfsdk:"user_token"`
21+
OrganizationToken types.String `tfsdk:"organization_token"`
22+
TeamToken types.String `tfsdk:"team_token"`
23+
AuditTrailToken types.String `tfsdk:"audit_trail_token"`
24+
}
25+
26+
func NewOrganizationTTLPolicyResource() resource.Resource {
27+
return &organizationTTLPolicyResource{}
28+
}
29+
30+
func (r *organizationTTLPolicyResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
31+
resp.TypeName = req.ProviderTypeName + "_organization_ttl_policy"
32+
}
33+
34+
func (r *organizationTTLPolicyResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
35+
resp.Schema = schema.Schema{
36+
Version: 0,
37+
Attributes: map[string]schema.Attribute{
38+
"organization": schema.StringAttribute{
39+
Description: "The name of the organization.",
40+
Required: true,
41+
PlanModifiers: []planmodifier.String{
42+
stringplanmodifier.RequiresReplace(),
43+
},
44+
},
45+
"user_token_max_ttl": schema.StringAttribute{
46+
Description: "The maximum TTL allowed for usage of user tokens in the organization",
47+
Optional: true,
48+
Computed: true,
49+
Default: stringdefault.StaticString("2y"),
50+
PlanModifiers: []planmodifier.String{
51+
stringplanmodifier.RequiresReplace(),
52+
},
53+
},
54+
"org_token_max_ttl": schema.StringAttribute{
55+
Description: "The maximum TTL allowed for usage of organization tokens in the organization",
56+
Optional: true,
57+
Computed: true,
58+
Default: stringdefault.StaticString("2y"),
59+
PlanModifiers: []planmodifier.String{
60+
stringplanmodifier.RequiresReplace(),
61+
},
62+
},
63+
"team_token_max_ttl": schema.StringAttribute{
64+
Description: "The maximum TTL allowed for usage of team tokens in the organization",
65+
Optional: true,
66+
Computed: true,
67+
Default: stringdefault.StaticString("2y"),
68+
PlanModifiers: []planmodifier.String{
69+
stringplanmodifier.RequiresReplace(),
70+
},
71+
},
72+
"audit_trail_token_max_ttl": schema.StringAttribute{
73+
Description: "The maximum TTL allowed for usage of audit trail tokens in the organization",
74+
Optional: true,
75+
Computed: true,
76+
Default: stringdefault.StaticString("2y"),
77+
PlanModifiers: []planmodifier.String{
78+
stringplanmodifier.RequiresReplace(),
79+
},
80+
},
81+
},
82+
}
83+
}
84+
85+
// Create operation
86+
func (r *organizationTTLPolicyResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
87+
var plan organizationTTLPolicyModel
88+
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
89+
// TODO: Call API to create the policy
90+
//plan.ID = types.StringValue(fmt.Sprintf("org-ttl-policy-%s", plan.UserToken.ValueString()))
91+
//resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
92+
}
93+
94+
// Read operation
95+
func (r *organizationTTLPolicyResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
96+
var state organizationTTLPolicyModel
97+
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
98+
// TODO: Call API to read the policy
99+
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
100+
}
101+
102+
// Update operation
103+
func (r *organizationTTLPolicyResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
104+
var plan organizationTTLPolicyModel
105+
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
106+
// TODO: Call API to update the policy
107+
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
108+
}
109+
110+
// Delete operation
111+
func (r *organizationTTLPolicyResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) {
112+
var state organizationTTLPolicyModel
113+
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
114+
// TODO: Call API to delete the policy
115+
// resp.Diagnostics.Append(resp.State.RemoveResource(ctx)...)
116+
}

0 commit comments

Comments
 (0)