@@ -518,9 +518,10 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
518
518
},
519
519
},
520
520
"resource_config" : schema.SingleNestedAttribute {
521
- Description : "Resource Configuration for the project." ,
522
- Optional : true ,
523
- Computed : true ,
521
+ Description : "Resource Configuration for the project." ,
522
+ Optional : true ,
523
+ Computed : true ,
524
+ PlanModifiers : []planmodifier.Object {objectplanmodifier .UseStateForUnknown ()},
524
525
Attributes : map [string ]schema.Attribute {
525
526
// This is actually "function_default_memory_type" in the API schema, but for better convention, we use "cpu" and do translation in the provider.
526
527
"function_default_cpu_type" : schema.StringAttribute {
@@ -530,64 +531,24 @@ At this time you cannot use a Vercel Project resource with in-line ` + "`environ
530
531
Validators : []validator.String {
531
532
stringvalidator .OneOf ("standard_legacy" , "standard" , "performance" ),
532
533
},
533
- PlanModifiers : []planmodifier.String {SuppressDiffIfNotConfigured (), stringplanmodifier .UseStateForUnknown ()},
534
+ PlanModifiers : []planmodifier.String {stringplanmodifier .UseStateForUnknown ()},
534
535
},
535
536
"function_default_timeout" : schema.Int64Attribute {
536
537
Description : "The default timeout for Serverless Functions." ,
537
538
Optional : true ,
538
539
Computed : true ,
539
540
Validators : []validator.Int64 {
540
- int64validator .AtLeast (0 ),
541
- int64validator .AtMost (901 ),
541
+ int64validator .AtLeast (1 ),
542
+ int64validator .AtMost (900 ),
542
543
},
543
- PlanModifiers : []planmodifier.Int64 {SuppressDiffIfNotConfigured (), int64planmodifier .UseStateForUnknown ()},
544
+ PlanModifiers : []planmodifier.Int64 {int64planmodifier .UseStateForUnknown ()},
544
545
},
545
546
},
546
- Default : objectdefault .StaticValue (types .ObjectValueMust (
547
- map [string ]attr.Type {
548
- "function_default_cpu_type" : types .StringType ,
549
- "function_default_timeout" : types .Int64Type ,
550
- },
551
- map [string ]attr.Value {
552
- "function_default_cpu_type" : types .StringNull (),
553
- "function_default_timeout" : types .Int64Null (),
554
- },
555
- )),
556
547
},
557
548
},
558
549
}
559
550
}
560
551
561
- type suppressDiffIfNotConfigured struct {}
562
-
563
- func SuppressDiffIfNotConfigured () * suppressDiffIfNotConfigured {
564
- return & suppressDiffIfNotConfigured {}
565
- }
566
-
567
- func (m * suppressDiffIfNotConfigured ) Description (ctx context.Context ) string {
568
- return "Ensures that the diff is suppressed if the attribute is not explicitly configured by users."
569
- }
570
-
571
- func (m * suppressDiffIfNotConfigured ) MarkdownDescription (ctx context.Context ) string {
572
- return m .Description (ctx )
573
- }
574
-
575
- func (m * suppressDiffIfNotConfigured ) PlanModifyString (ctx context.Context , req planmodifier.StringRequest , resp * planmodifier.StringResponse ) {
576
- if req .ConfigValue .IsNull () {
577
- resp .PlanValue = req .StateValue
578
- resp .RequiresReplace = false
579
- return
580
- }
581
- }
582
-
583
- func (m * suppressDiffIfNotConfigured ) PlanModifyInt64 (ctx context.Context , req planmodifier.Int64Request , resp * planmodifier.Int64Response ) {
584
- if req .ConfigValue .IsNull () {
585
- resp .PlanValue = req .StateValue
586
- resp .RequiresReplace = false
587
- return
588
- }
589
- }
590
-
591
552
// Project reflects the state terraform stores internally for a project.
592
553
type Project struct {
593
554
BuildCommand types.String `tfsdk:"build_command"`
@@ -624,7 +585,7 @@ type Project struct {
624
585
DirectoryListing types.Bool `tfsdk:"directory_listing"`
625
586
EnableAffectedProjectsDeployments types.Bool `tfsdk:"enable_affected_projects_deployments"`
626
587
SkewProtection types.String `tfsdk:"skew_protection"`
627
- ResourceConfig * ResourceConfig `tfsdk:"resource_config"`
588
+ ResourceConfig types. Object `tfsdk:"resource_config"`
628
589
}
629
590
630
591
type GitComments struct {
@@ -659,7 +620,6 @@ func (p Project) RequiresUpdateAfterCreation() bool {
659
620
! p .PrioritiseProductionBuilds .IsNull () ||
660
621
! p .DirectoryListing .IsNull () ||
661
622
! p .SkewProtection .IsNull () ||
662
- p .ResourceConfig != nil ||
663
623
! p .NodeVersion .IsNull ()
664
624
665
625
}
@@ -723,6 +683,14 @@ func parseEnvironment(ctx context.Context, vars []EnvironmentItem) (out []client
723
683
724
684
func (p * Project ) toCreateProjectRequest (ctx context.Context , envs []EnvironmentItem ) (req client.CreateProjectRequest , diags diag.Diagnostics ) {
725
685
clientEnvs , diags := parseEnvironment (ctx , envs )
686
+ if diags .HasError () {
687
+ return req , diags
688
+ }
689
+ resourceConfig , diags := p .resourceConfig (ctx )
690
+ if diags .HasError () {
691
+ return req , diags
692
+ }
693
+
726
694
return client.CreateProjectRequest {
727
695
BuildCommand : p .BuildCommand .ValueStringPointer (),
728
696
CommandForIgnoringBuildStep : p .IgnoreCommand .ValueStringPointer (),
@@ -738,6 +706,7 @@ func (p *Project) toCreateProjectRequest(ctx context.Context, envs []Environment
738
706
PublicSource : p .PublicSource .ValueBoolPointer (),
739
707
RootDirectory : p .RootDirectory .ValueStringPointer (),
740
708
ServerlessFunctionRegion : p .ServerlessFunctionRegion .ValueString (),
709
+ ResourceConfig : resourceConfig .toClientResourceConfig (),
741
710
}, diags
742
711
}
743
712
@@ -768,6 +737,10 @@ func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (r
768
737
if diags .HasError () {
769
738
return req , diags
770
739
}
740
+ resourceConfig , diags := p .resourceConfig (ctx )
741
+ if diags .HasError () {
742
+ return req , diags
743
+ }
771
744
return client.UpdateProjectRequest {
772
745
BuildCommand : p .BuildCommand .ValueStringPointer (),
773
746
CommandForIgnoringBuildStep : p .IgnoreCommand .ValueStringPointer (),
@@ -796,7 +769,7 @@ func (p *Project) toUpdateProjectRequest(ctx context.Context, oldName string) (r
796
769
DirectoryListing : p .DirectoryListing .ValueBool (),
797
770
SkewProtectionMaxAge : toSkewProtectionAge (p .SkewProtection ),
798
771
GitComments : gc .toUpdateProjectRequest (),
799
- ResourceConfig : p . ResourceConfig . toUpdateProjectRequest (),
772
+ ResourceConfig : resourceConfig . toClientResourceConfig (),
800
773
NodeVersion : p .NodeVersion .ValueString (),
801
774
}, nil
802
775
}
@@ -1026,22 +999,37 @@ func (o *OIDCTokenConfig) toUpdateProjectRequest() *client.OIDCTokenConfig {
1026
999
}
1027
1000
}
1028
1001
1002
+ var resourceConfigAttrType = types.ObjectType {
1003
+ AttrTypes : map [string ]attr.Type {
1004
+ "function_default_cpu_type" : types .StringType ,
1005
+ "function_default_timeout" : types .Int64Type ,
1006
+ },
1007
+ }
1008
+
1029
1009
type ResourceConfig struct {
1030
- FunctionDefaultMemoryType types.String `tfsdk:"function_default_cpu_type"`
1031
- FunctionDefaultTimeout types.Int64 `tfsdk:"function_default_timeout"`
1010
+ FunctionDefaultCPUType types.String `tfsdk:"function_default_cpu_type"`
1011
+ FunctionDefaultTimeout types.Int64 `tfsdk:"function_default_timeout"`
1012
+ }
1013
+
1014
+ func (p * Project ) resourceConfig (ctx context.Context ) (rc * ResourceConfig , diags diag.Diagnostics ) {
1015
+ diags = p .ResourceConfig .As (ctx , & rc , basetypes.ObjectAsOptions {
1016
+ UnhandledNullAsEmpty : true ,
1017
+ UnhandledUnknownAsEmpty : true ,
1018
+ })
1019
+ return rc , diags
1032
1020
}
1033
1021
1034
- func (r * ResourceConfig ) toUpdateProjectRequest () * client.ResourceConfig {
1035
- resourceConfig := & client.ResourceConfig {}
1022
+ func (r * ResourceConfig ) toClientResourceConfig () * client.ResourceConfig {
1036
1023
if r == nil {
1037
- return resourceConfig
1024
+ return nil
1038
1025
}
1026
+ var resourceConfig = & client.ResourceConfig {}
1039
1027
1040
- if ! r .FunctionDefaultMemoryType . IsNull () {
1041
- resourceConfig .FunctionDefaultMemoryType = r .FunctionDefaultMemoryType . ValueString ()
1028
+ if ! r .FunctionDefaultCPUType . IsUnknown () {
1029
+ resourceConfig .FunctionDefaultMemoryType = r .FunctionDefaultCPUType . ValueStringPointer ()
1042
1030
}
1043
- if ! r .FunctionDefaultTimeout .IsNull () {
1044
- resourceConfig .FunctionDefaultTimeout = r .FunctionDefaultTimeout .ValueInt64 ()
1031
+ if ! r .FunctionDefaultTimeout .IsUnknown () {
1032
+ resourceConfig .FunctionDefaultTimeout = r .FunctionDefaultTimeout .ValueInt64Pointer ()
1045
1033
}
1046
1034
return resourceConfig
1047
1035
}
@@ -1260,14 +1248,12 @@ func convertResponseToProject(ctx context.Context, response client.ProjectRespon
1260
1248
oidcTokenConfig .IssuerMode = types .StringValue (response .OIDCTokenConfig .IssuerMode )
1261
1249
}
1262
1250
1263
- resourceConfig := & ResourceConfig {}
1264
- if response .ResourceConfig != nil && plan .ResourceConfig != nil {
1265
- if ! plan .ResourceConfig .FunctionDefaultMemoryType .IsNull () {
1266
- resourceConfig .FunctionDefaultMemoryType = types .StringValue (response .ResourceConfig .FunctionDefaultMemoryType )
1267
- }
1268
- if ! plan .ResourceConfig .FunctionDefaultTimeout .IsNull () {
1269
- resourceConfig .FunctionDefaultTimeout = types .Int64Value (response .ResourceConfig .FunctionDefaultTimeout )
1270
- }
1251
+ resourceConfig := types .ObjectNull (resourceConfigAttrType .AttrTypes )
1252
+ if response .ResourceConfig != nil {
1253
+ resourceConfig = types .ObjectValueMust (resourceConfigAttrType .AttrTypes , map [string ]attr.Value {
1254
+ "function_default_cpu_type" : types .StringPointerValue (response .ResourceConfig .FunctionDefaultMemoryType ),
1255
+ "function_default_timeout" : types .Int64PointerValue (response .ResourceConfig .FunctionDefaultTimeout ),
1256
+ })
1271
1257
}
1272
1258
1273
1259
var oal * OptionsAllowlist
@@ -1531,9 +1517,10 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest
1531
1517
)
1532
1518
return
1533
1519
}
1534
- tflog .Info (ctx , "created project" , map [string ]any {
1520
+ tflog .Error (ctx , "created project" , map [string ]any {
1535
1521
"team_id" : result .TeamID .ValueString (),
1536
1522
"project_id" : result .ID .ValueString (),
1523
+ "project" : result ,
1537
1524
})
1538
1525
diags = resp .State .Set (ctx , result )
1539
1526
resp .Diagnostics .Append (diags ... )
0 commit comments