From f489013678052086bb2c2d16cd167ddc9b050ac6 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Tue, 25 Apr 2023 16:41:47 -0400 Subject: [PATCH] rename to tf-oci Signed-off-by: Jason Hall --- README.md | 6 ++-- docs/data-sources/ref.md | 10 ++----- docs/index.md | 6 ++-- docs/resources/append.md | 10 ++----- .../data-sources/crane_ref/data-source.tf | 2 +- examples/provider/provider.tf | 2 +- examples/resources/crane_append/resource.tf | 2 +- go.mod | 2 +- internal/provider/append_resource_test.go | 12 ++++---- internal/provider/provider.go | 28 +++++++++---------- internal/provider/provider_test.go | 2 +- internal/provider/ref_data_source_test.go | 6 ++-- main.go | 22 +++------------ 13 files changed, 42 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index f5bf2d2..89f64cd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ -# Terraform Provider for [`crane`](https://github.com/google/go-containerregistry/blob/main/cmd/crane/README.md) +# Terraform Provider for OCI operations -[![Tests](https://github.com/imjasonh/terraform-provider-crane/actions/workflows/test.yml/badge.svg)](https://github.com/imjasonh/terraform-provider-crane/actions/workflows/test.yml) +[![Tests](https://github.com/imjasonh/terraform-provider-oci/actions/workflows/test.yml/badge.svg)](https://github.com/imjasonh/terraform-provider-oci/actions/workflows/test.yml) + +This provider is intended to provide some behavior similar to [`crane`](https://github.com/google/go-containerregistry/blob/main/cmd/crane/README.md). ## Developing the Provider diff --git a/docs/data-sources/ref.md b/docs/data-sources/ref.md index 4fe4470..9e2493d 100644 --- a/docs/data-sources/ref.md +++ b/docs/data-sources/ref.md @@ -1,22 +1,16 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "crane_ref Data Source - terraform-provider-crane" +page_title: "oci_ref Data Source - terraform-provider-oci" subcategory: "" description: |- Image ref data source --- -# crane_ref (Data Source) +# oci_ref (Data Source) Image ref data source -## Example Usage -```terraform -data "crane_ref" "example" { - ref = "registry.example.com/repo/image:tag" -} -``` ## Schema diff --git a/docs/index.md b/docs/index.md index 6cb5336..20dc4d5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,19 +1,19 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "crane Provider" +page_title: "oci Provider" subcategory: "" description: |- --- -# crane Provider +# oci Provider ## Example Usage ```terraform -provider "crane" { +provider "oci" { # example configuration here } ``` diff --git a/docs/resources/append.md b/docs/resources/append.md index f962f36..5d03675 100644 --- a/docs/resources/append.md +++ b/docs/resources/append.md @@ -1,22 +1,16 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "crane_append Resource - terraform-provider-crane" +page_title: "oci_append Resource - terraform-provider-oci" subcategory: "" description: |- Image append resource --- -# crane_append (Resource) +# oci_append (Resource) Image append resource -## Example Usage -```terraform -resource "crane_append" "example" { - base_image = "alpine:3.18" -} -``` ## Schema diff --git a/examples/data-sources/crane_ref/data-source.tf b/examples/data-sources/crane_ref/data-source.tf index 673398e..1b44e44 100644 --- a/examples/data-sources/crane_ref/data-source.tf +++ b/examples/data-sources/crane_ref/data-source.tf @@ -1,3 +1,3 @@ -data "crane_ref" "example" { +data "oci_ref" "example" { ref = "registry.example.com/repo/image:tag" } diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 2c4f54c..73f7daa 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -1,3 +1,3 @@ -provider "crane" { +provider "oci" { # example configuration here } diff --git a/examples/resources/crane_append/resource.tf b/examples/resources/crane_append/resource.tf index 4236655..b580ea8 100644 --- a/examples/resources/crane_append/resource.tf +++ b/examples/resources/crane_append/resource.tf @@ -1,3 +1,3 @@ -resource "crane_append" "example" { +resource "oci_append" "example" { base_image = "alpine:3.18" } diff --git a/go.mod b/go.mod index 35e17d1..b8d9f9b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/imjasonh/terraform-provider-crane +module github.com/chainguard-dev/terraform-provider-oci go 1.19 diff --git a/internal/provider/append_resource_test.go b/internal/provider/append_resource_test.go index 92385b1..132bb1e 100644 --- a/internal/provider/append_resource_test.go +++ b/internal/provider/append_resource_test.go @@ -54,17 +54,17 @@ func TestAccExampleResource(t *testing.T) { Steps: []resource.TestStep{ // Create and Read testing { - Config: fmt.Sprintf(`resource "crane_append" "test" { + Config: fmt.Sprintf(`resource "oci_append" "test" { base_image = %q }`, ref1), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("crane_append.test", "base_image", ref1.String()), - resource.TestCheckResourceAttr("crane_append.test", "id", "TODO"), + resource.TestCheckResourceAttr("oci_append.test", "base_image", ref1.String()), + resource.TestCheckResourceAttr("oci_append.test", "id", "TODO"), ), }, // ImportState testing { - ResourceName: "crane_append.test", + ResourceName: "oci_append.test", ImportState: true, ImportStateVerify: true, // This is not normally necessary, but is here because this @@ -75,11 +75,11 @@ func TestAccExampleResource(t *testing.T) { }, // Update and Read testing { - Config: fmt.Sprintf(`resource "crane_append" "test" { + Config: fmt.Sprintf(`resource "oci_append" "test" { base_image = %q }`, ref2), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("crane_append.test", "base_image", ref2.String()), + resource.TestCheckResourceAttr("oci_append.test", "base_image", ref2.String()), ), }, // Delete testing automatically occurs in TestCase diff --git a/internal/provider/provider.go b/internal/provider/provider.go index e0d11a4..4e4c105 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -10,27 +10,27 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" ) -var _ provider.Provider = &CraneProvider{} +var _ provider.Provider = &OCIProvider{} -// CraneProvider defines the provider implementation. -type CraneProvider struct { +// OCIProvider defines the provider implementation. +type OCIProvider struct { // version is set to the provider version on release, "dev" when the // provider is built and ran locally, and "test" when running acceptance // testing. version string } -// CraneProviderModel describes the provider data model. -type CraneProviderModel struct { +// OCIProviderModel describes the provider data model. +type OCIProviderModel struct { // TODO: Add provider configuration attributes here. } -func (p *CraneProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { - resp.TypeName = "crane" +func (p *OCIProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { + resp.TypeName = "oci" resp.Version = p.version } -func (p *CraneProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { +func (p *OCIProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { resp.Schema = schema.Schema{ Attributes: map[string]schema.Attribute{ // TODO: Add provider configuration attributes here. @@ -38,11 +38,9 @@ func (p *CraneProvider) Schema(ctx context.Context, req provider.SchemaRequest, } } -func (p *CraneProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { - var data CraneProviderModel - +func (p *OCIProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { + var data OCIProviderModel resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) - if resp.Diagnostics.HasError() { return } @@ -52,13 +50,13 @@ func (p *CraneProvider) Configure(ctx context.Context, req provider.ConfigureReq resp.ResourceData = client } -func (p *CraneProvider) Resources(ctx context.Context) []func() resource.Resource { +func (p *OCIProvider) Resources(ctx context.Context) []func() resource.Resource { return []func() resource.Resource{ NewAppendResource, } } -func (p *CraneProvider) DataSources(ctx context.Context) []func() datasource.DataSource { +func (p *OCIProvider) DataSources(ctx context.Context) []func() datasource.DataSource { return []func() datasource.DataSource{ NewRefDataSource, } @@ -66,7 +64,7 @@ func (p *CraneProvider) DataSources(ctx context.Context) []func() datasource.Dat func New(version string) func() provider.Provider { return func() provider.Provider { - return &CraneProvider{ + return &OCIProvider{ version: version, } } diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 90234b0..0064a5f 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -12,7 +12,7 @@ import ( // CLI command executed to create a provider server to which the CLI can // reattach. var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){ - "crane": providerserver.NewProtocol6WithError(New("test")()), + "oci": providerserver.NewProtocol6WithError(New("test")()), } func testAccPreCheck(t *testing.T) { diff --git a/internal/provider/ref_data_source_test.go b/internal/provider/ref_data_source_test.go index 691229c..61ed76b 100644 --- a/internal/provider/ref_data_source_test.go +++ b/internal/provider/ref_data_source_test.go @@ -43,12 +43,12 @@ func TestAccExampleDataSource(t *testing.T) { Steps: []resource.TestStep{ // Read testing { - Config: fmt.Sprintf(`data "crane_ref" "test" { + Config: fmt.Sprintf(`data "oci_ref" "test" { ref = %q }`, ref), Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.crane_ref.test", "id", ref.Context().Digest(d.String()).String()), - resource.TestCheckResourceAttr("data.crane_ref.test", "digest", d.String()), + resource.TestCheckResourceAttr("data.oci_ref.test", "id", ref.Context().Digest(d.String()).String()), + resource.TestCheckResourceAttr("data.oci_ref.test", "digest", d.String()), ), }, }, diff --git a/main.go b/main.go index 07e4db8..bec3fdd 100644 --- a/main.go +++ b/main.go @@ -5,28 +5,14 @@ import ( "flag" "log" + "github.com/chainguard-dev/terraform-provider-oci/internal/provider" "github.com/hashicorp/terraform-plugin-framework/providerserver" - "github.com/imjasonh/terraform-provider-crane/internal/provider" ) -// Run "go generate" to format example terraform files and generate the docs for the registry/website - -// If you do not have terraform installed, you can remove the formatting command, but its suggested to -// ensure the documentation is formatted properly. -//go:generate terraform fmt -recursive ./examples/ - -// Run the docs generation tool, check its repository for more information on how it works and how docs -// can be customized. +//go:generate terraform fmt -recursive ./examples/. //go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs -var ( - // these will be set by the goreleaser configuration - // to appropriate values for the compiled binary. - version string = "dev" - - // goreleaser can pass other information to the main package, such as the specific commit - // https://goreleaser.com/cookbooks/using-main.version/ -) +const version string = "dev" func main() { var debug bool @@ -35,7 +21,7 @@ func main() { flag.Parse() err := providerserver.Serve(context.Background(), provider.New(version), providerserver.ServeOpts{ - Address: "registry.terraform.io/imjasonh/crane", + Address: "registry.terraform.io/chainguard-dev/oci", Debug: debug, })