Skip to content

Add spicedb_relationship to manage relationships#4

Open
frekw wants to merge 5 commits intoEducationPerfect:mainfrom
frekw:feat/relationship
Open

Add spicedb_relationship to manage relationships#4
frekw wants to merge 5 commits intoEducationPerfect:mainfrom
frekw:feat/relationship

Conversation

@frekw
Copy link
Copy Markdown

@frekw frekw commented Dec 7, 2023

This should make it possible to bootstrap things like initial roles and other things that should always exist in SpiceDB.

This is my first attempt at writing a TF provider, so happy to receive feedback. I was also unable to run the tests locally due to

 Error: Inconsistent dependency lock file

        The following dependency selections recorded in the lock file are
        inconsistent with the current configuration:
          - provider registry.terraform.io/educationperfect/spicedb: required by this configuration but no version is selected

        To make the initial dependency selections that will initialize the dependency
        lock file, run:
          terraform init

so would gladly receive pointers to get them to run!

I took the liberty to pull in a spicedb as a dependency (a slightly older version compatible with go 1.19) in order to make sure we parse the actual relationships in the exact same way as it and zed does. I realize that dependency is a bit on the heavier side so happy to do something simpler if you prefer.

This should make it possible to bootstrap things like initial roles and other
things that should always exist in SpiceDB.
@frekw frekw force-pushed the feat/relationship branch from c1c2e43 to ee0442f Compare December 7, 2023 21:21
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

func (r *RelationshipResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if having Update not implemented would work?
Is it possible that in case of a change TF would think that SpiceDB was updated (because function returns) while no actual changes are performed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine, from the documentation on Update:

An error is returned if the response state is not set when Update is called by the framework. If the resource does not support modification and should always be recreated on configuration value updates, the Update logic can be left empty and ensure all configurable schema attributes implement the resource.RequiresReplace() attribute plan modifier.

@AlexeyRaga
Copy link
Copy Markdown
Contributor

AlexeyRaga commented Dec 19, 2023

thanks @frekw!

As for tests, there is this trick in TF that allows it to use a local version of a provider instead of the "real" one from the repository: you create a local ~/.terraformrc file and "register" your provider in there, for example:

provider_installation {
  dev_overrides {
    "educationperfect/spicedb" = "/Users/frekw/go/bin/"
  }
  direct {}
}

In fact, the CI does this as a step: https://github.com/EducationPerfect/terraform-provider-spicedb/blob/main/.github/workflows/test.yml#L76

Could you please try it and see if you can make tests to pass?

@frekw
Copy link
Copy Markdown
Author

frekw commented Dec 20, 2023

Ah great! I'll try that to ensure I can get the tests working. Thanks for the pointer! 🙇

@frekw
Copy link
Copy Markdown
Author

frekw commented Dec 20, 2023

@AlexeyRaga I got everything to work based on your pointers (locally at least) :)

TF_ACC=1 go test ./... -v  -timeout 120m -count=1
?       github.com/educationperfect/terraform-provider-spicedb  [no test files]
=== RUN   TestAccRelationshipResource
--- PASS: TestAccRelationshipResource (1.80s)
=== RUN   TestAccSchemaDataSource
--- PASS: TestAccSchemaDataSource (0.71s)
=== RUN   TestAccSchemaResource
--- PASS: TestAccSchemaResource (1.36s)
PASS
ok      github.com/educationperfect/terraform-provider-spicedb/internal/provider        4.700s

@frekw
Copy link
Copy Markdown
Author

frekw commented Jan 17, 2024

Ping @AlexeyRaga any updates? :)

@frekw
Copy link
Copy Markdown
Author

frekw commented Feb 1, 2024

Ping @AlexeyRaga

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants