Skip to content

Commit

Permalink
Rename Resource.Type() to Resource.SchemaType()
Browse files Browse the repository at this point in the history
Since block.SetType () sets the block of type (i.e. `resource`),
it's confusing for Resource.Type () to return the resource type (i.e.
aws_s3_bucket) instead of the the `resource` literal.
Give different names to different things.
  • Loading branch information
minamijoyo committed Mar 30, 2022
1 parent c86e5e2 commit f94bafe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tfwrite/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ func NewEmptyResource(resourceType string, resourceName string) *Resource {
return NewResource(block)
}

// Type returns a type of resource.
// SchemaType returns a type of resource.
// It returns the first label of block.
// Note that it's not the same as the *hclwrite.Block.Type().
func (r *Resource) Type() string {
func (r *Resource) SchemaType() string {
labels := r.block.raw.Labels()
return labels[0]
}
Expand All @@ -43,7 +43,7 @@ func (r *Resource) Name() string {
// another resource.
func (r *Resource) SetAttributeByReference(name string, refResource *Resource, refAttribute string) {
traversal := hcl.Traversal{
hcl.TraverseRoot{Name: refResource.Type()},
hcl.TraverseRoot{Name: refResource.SchemaType()},
hcl.TraverseAttr{Name: refResource.Name()},
hcl.TraverseAttr{Name: refAttribute},
}
Expand Down
4 changes: 2 additions & 2 deletions tfwrite/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/google/go-cmp/cmp"
)

func TestResourceType(t *testing.T) {
func TestResourceSchemaType(t *testing.T) {
cases := []struct {
desc string
src string
Expand All @@ -26,7 +26,7 @@ resource "aws_s3_bucket" "example" {}
for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
r := parseTestResource(t, tc.src)
got := r.Type()
got := r.SchemaType()
if got != tc.want {
t.Errorf("got = %s, but want = %s", got, tc.want)
}
Expand Down

0 comments on commit f94bafe

Please sign in to comment.