Skip to content

Commit

Permalink
rename to tf-oci
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <jason@chainguard.dev>
  • Loading branch information
imjasonh committed Apr 25, 2023
1 parent ef4bcaa commit f489013
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 68 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 2 additions & 8 deletions docs/data-sources/ref.md
Original file line number Diff line number Diff line change
@@ -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 generated by tfplugindocs -->
## Schema
Expand Down
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -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
}
```
Expand Down
10 changes: 2 additions & 8 deletions docs/resources/append.md
Original file line number Diff line number Diff line change
@@ -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 generated by tfplugindocs -->
## Schema
Expand Down
2 changes: 1 addition & 1 deletion examples/data-sources/crane_ref/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
data "crane_ref" "example" {
data "oci_ref" "example" {
ref = "registry.example.com/repo/image:tag"
}
2 changes: 1 addition & 1 deletion examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
provider "crane" {
provider "oci" {
# example configuration here
}
2 changes: 1 addition & 1 deletion examples/resources/crane_append/resource.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
resource "crane_append" "example" {
resource "oci_append" "example" {
base_image = "alpine:3.18"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/imjasonh/terraform-provider-crane
module github.com/chainguard-dev/terraform-provider-oci

go 1.19

Expand Down
12 changes: 6 additions & 6 deletions internal/provider/append_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 13 additions & 15 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,37 @@ 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.
},
}
}

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
}
Expand All @@ -52,21 +50,21 @@ 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,
}
}

func New(version string) func() provider.Provider {
return func() provider.Provider {
return &CraneProvider{
return &OCIProvider{
version: version,
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/ref_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
),
},
},
Expand Down
22 changes: 4 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
})

Expand Down

0 comments on commit f489013

Please sign in to comment.