diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 2eca66f..c010ecd 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -3,22 +3,22 @@ id: e742591b-391d-4f4e-8484-d01a093b32ec management: docChecksum: a91eaf9ec1e6a3a6f4bf0571f5b18bae docVersion: 0.0.3 - speakeasyVersion: 1.228.1 - generationVersion: 2.292.0 - releaseVersion: 0.9.0 - configChecksum: 099f930233140a9803ac3954f0314d49 + speakeasyVersion: 1.241.0 + generationVersion: 2.300.0 + releaseVersion: 0.10.0 + configChecksum: 209a06e636e3932f0cf252f8833149be repoURL: https://github.com/LukeHagar/plexterraform.git repoSubDirectory: . published: true features: terraform: constsAndDefaults: 0.1.4 - core: 3.12.1 + core: 3.17.0 globalSecurity: 2.81.6 globalServerURLs: 2.82.1 globals: 2.82.1 methodServerURLs: 2.82.1 - nameOverrides: 2.81.1 + nameOverrides: 2.81.2 generatedFiles: - internal/sdk/server.go - internal/sdk/media.go diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index a3b7c75..bc8e1eb 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -12,7 +12,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: false terraform: - version: 0.9.0 + version: 0.10.0 author: LukeHagar imports: option: openapi diff --git a/README.md b/README.md index eb32332..ff61871 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ terraform { required_providers { PlexAPI = { source = "LukeHagar/PlexAPI" - version = "0.9.0" + version = "0.10.0" } } } diff --git a/RELEASES.md b/RELEASES.md index b4210c9..89504cc 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -158,4 +158,12 @@ Based on: - OpenAPI Doc - Speakeasy CLI 1.228.1 (2.292.0) https://github.com/speakeasy-api/speakeasy ### Generated -- [terraform v0.9.0] . \ No newline at end of file +- [terraform v0.9.0] . + +## 2024-04-06 01:03:34 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.241.0 (2.300.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [terraform v0.10.0] . \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 7f24119..eb3c01c 100644 --- a/docs/index.md +++ b/docs/index.md @@ -17,7 +17,7 @@ terraform { required_providers { PlexAPI = { source = "LukeHagar/PlexAPI" - version = "0.9.0" + version = "0.10.0" } } } diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index ff7212a..fe95fd4 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -2,7 +2,7 @@ terraform { required_providers { PlexAPI = { source = "LukeHagar/PlexAPI" - version = "0.9.0" + version = "0.10.0" } } } diff --git a/internal/provider/reflect/helpers.go b/internal/provider/reflect/helpers.go index 82b9515..42d19f2 100644 --- a/internal/provider/reflect/helpers.go +++ b/internal/provider/reflect/helpers.go @@ -46,7 +46,7 @@ func commaSeparatedString(in []string) string { // getStructTags returns a map of Terraform field names to their position in // the tags of the struct `in`. `in` must be a struct. -func getStructTags(_ context.Context, in reflect.Value, path path.Path) (map[string]int, error) { +func getStructTags(_ context.Context, in reflect.Value, path path.Path, opts Options) (map[string]int, error) { tags := map[string]int{} typ := trueReflectValue(in).Type() if typ.Kind() != reflect.Struct { diff --git a/internal/provider/reflect/options.go b/internal/provider/reflect/options.go index 490c5f1..d735aff 100644 --- a/internal/provider/reflect/options.go +++ b/internal/provider/reflect/options.go @@ -2,6 +2,11 @@ package reflect +const ( + SourceTypeState = iota + SourceTypePlan +) + // Options provides configuration settings for how the reflection behavior // works, letting callers tweak different behaviors based on their needs. type Options struct { @@ -19,4 +24,8 @@ type Options struct { // perfectly in the types they're being stored in, rather than // returning errors. Numbers will always be rounded towards 0. AllowRoundingNumbers bool + // SourceType informs the reflection system what the source is + // such that it can make decisions based on the tfPlanOnly annotation + // The default is SourceTypeState + SourceType int } diff --git a/internal/provider/reflect/struct.go b/internal/provider/reflect/struct.go index b670228..c730135 100644 --- a/internal/provider/reflect/struct.go +++ b/internal/provider/reflect/struct.go @@ -73,7 +73,7 @@ func Struct(ctx context.Context, typ attr.Type, object tftypes.Value, target ref // collect a map of fields that are defined in the tags of the struct // passed in - targetFields, err := getStructTags(ctx, target, path) + targetFields, err := getStructTags(ctx, target, path, opts) if err != nil { diags.Append(diag.WithPath(path, DiagIntoIncompatibleType{ Val: object, @@ -125,7 +125,8 @@ func Struct(ctx context.Context, typ attr.Type, object tftypes.Value, target ref } else { result = reflect.New(target.Type()).Elem() } - // Fork End + structType := trueReflectValue(target).Type() + for field, structFieldPos := range targetFields { attrType, ok := attrTypes[field] if !ok { @@ -136,6 +137,13 @@ func Struct(ctx context.Context, typ attr.Type, object tftypes.Value, target ref })) return target, diags } + + fieldReflected := structType.Field(structFieldPos) + if opts.SourceType == SourceTypeState && fieldReflected.Tag.Get(`tfPlanOnly`) == "true" { + // skip explicitly excluded fields + continue + } + // Fork End structField := result.Field(structFieldPos) fieldVal, fieldValDiags := BuildValue(ctx, attrType, objectFields[field], structField, opts, path.AtName(field)) diags.Append(fieldValDiags...) @@ -162,7 +170,7 @@ func FromStruct(ctx context.Context, typ attr.TypeWithAttributeTypes, val reflec // collect a map of fields that are defined in the tags of the struct // passed in - targetFields, err := getStructTags(ctx, val, path) + targetFields, err := getStructTags(ctx, val, path, Options{}) if err != nil { err = fmt.Errorf("error retrieving field names from struct tags: %w", err) diags.AddAttributeError( diff --git a/internal/provider/utils.go b/internal/provider/utils.go index 3cbc17b..6f4be25 100644 --- a/internal/provider/utils.go +++ b/internal/provider/utils.go @@ -11,13 +11,15 @@ import ( "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" - "github.com/hashicorp/terraform-plugin-framework/types/basetypes" "net/http" "net/http/httputil" "reflect" ) func debugResponse(response *http.Response) string { + if v := response.Request.Header.Get("X-Plex-Token"); v != "" { + response.Request.Header.Set("X-Plex-Token", "(sensitive)") + } dumpReq, err := httputil.DumpRequest(response.Request, true) if err != nil { dumpReq, err = httputil.DumpRequest(response.Request, false) @@ -60,11 +62,15 @@ func merge(ctx context.Context, req resource.UpdateRequest, resp *resource.Updat if resp.Diagnostics.HasError() { return } - - resp.Diagnostics.Append(state.As(ctx, target, basetypes.ObjectAsOptions{ + val, err := state.ToTerraformValue(ctx) + if err != nil { + resp.Diagnostics.Append(diag.NewErrorDiagnostic("Object Conversion Error", "An unexpected error was encountered trying to convert object. This is always an error in the provider. Please report the following to the provider developer:\n\n"+err.Error())) + return + } + resp.Diagnostics.Append(tfReflect.Into(ctx, types.ObjectType{AttrTypes: state.AttributeTypes(ctx)}, val, target, tfReflect.Options{ UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true, - })...) + }, path.Empty())...) if resp.Diagnostics.HasError() { return } @@ -82,5 +88,6 @@ func refreshPlan(ctx context.Context, plan types.Object, target interface{}, dia diagnostics.Append(tfReflect.Into(ctx, obj, val, target, tfReflect.Options{ UnhandledNullAsEmpty: true, UnhandledUnknownAsEmpty: true, + SourceType: tfReflect.SourceTypePlan, }, path.Empty())...) } diff --git a/internal/sdk/plexapi.go b/internal/sdk/plexapi.go index 659daaf..d67ae12 100644 --- a/internal/sdk/plexapi.go +++ b/internal/sdk/plexapi.go @@ -279,8 +279,8 @@ func New(opts ...SDKOption) *PlexAPI { Language: "go", OpenAPIDocVersion: "0.0.3", SDKVersion: "0.0.1", - GenVersion: "2.292.0", - UserAgent: "speakeasy-sdk/go 0.0.1 2.292.0 0.0.3 github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk", + GenVersion: "2.300.0", + UserAgent: "speakeasy-sdk/go 0.0.1 2.300.0 0.0.3 github.com/LukeHagar/terraform-provider-PlexAPI/internal/sdk", Globals: map[string]map[string]map[string]interface{}{ "parameters": {}, },