terraform-provider-gitea/vendor/github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/fromproto/attribute_path.go
dependabot[bot] 910ccdb092
Bump github.com/hashicorp/terraform-plugin-sdk/v2 from 2.26.1 to 2.27.0
Bumps [github.com/hashicorp/terraform-plugin-sdk/v2](https://github.com/hashicorp/terraform-plugin-sdk) from 2.26.1 to 2.27.0.
- [Release notes](https://github.com/hashicorp/terraform-plugin-sdk/releases)
- [Changelog](https://github.com/hashicorp/terraform-plugin-sdk/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/terraform-plugin-sdk/compare/v2.26.1...v2.27.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/terraform-plugin-sdk/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-03 20:21:30 +00:00

67 lines
1.8 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package fromproto
import (
"errors"
"github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
var ErrUnknownAttributePathStepType = errors.New("unknown type of AttributePath_Step")
func AttributePath(in *tfplugin6.AttributePath) (*tftypes.AttributePath, error) {
steps, err := AttributePathSteps(in.Steps)
if err != nil {
return nil, err
}
return tftypes.NewAttributePathWithSteps(steps), nil
}
func AttributePaths(in []*tfplugin6.AttributePath) ([]*tftypes.AttributePath, error) {
resp := make([]*tftypes.AttributePath, 0, len(in))
for _, a := range in {
if a == nil {
resp = append(resp, nil)
continue
}
attr, err := AttributePath(a)
if err != nil {
return resp, err
}
resp = append(resp, attr)
}
return resp, nil
}
func AttributePathStep(step *tfplugin6.AttributePath_Step) (tftypes.AttributePathStep, error) {
selector := step.GetSelector()
if v, ok := selector.(*tfplugin6.AttributePath_Step_AttributeName); ok {
return tftypes.AttributeName(v.AttributeName), nil
}
if v, ok := selector.(*tfplugin6.AttributePath_Step_ElementKeyString); ok {
return tftypes.ElementKeyString(v.ElementKeyString), nil
}
if v, ok := selector.(*tfplugin6.AttributePath_Step_ElementKeyInt); ok {
return tftypes.ElementKeyInt(v.ElementKeyInt), nil
}
return nil, ErrUnknownAttributePathStepType
}
func AttributePathSteps(in []*tfplugin6.AttributePath_Step) ([]tftypes.AttributePathStep, error) {
resp := make([]tftypes.AttributePathStep, 0, len(in))
for _, step := range in {
if step == nil {
continue
}
s, err := AttributePathStep(step)
if err != nil {
return resp, err
}
resp = append(resp, s)
}
return resp, nil
}