Skip to content

Commit

Permalink
feat: 💥 refactor to use official astronomer terraform provider
Browse files Browse the repository at this point in the history
New upstream terraform provider
  • Loading branch information
ryan-pip committed Aug 6, 2024
1 parent 785c48c commit 11cf38c
Show file tree
Hide file tree
Showing 225 changed files with 39,585 additions and 6,241 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ tfgen:: install_plugins upstream/.git
provider:: tfgen install_plugins # build the provider binary
(cd provider && go build -o $(WORKING_DIR)/bin/${PROVIDER} -ldflags "-X ${PROJECT}/${VERSION_PATH}=${VERSION}" ${PROJECT}/${PROVIDER_PATH}/cmd/${PROVIDER})

build_sdks:: install_plugins provider build_nodejs build_python build_go build_dotnet # build all the sdks
build_sdks:: install_plugins provider build_nodejs build_python build_go # build_dotnet # build all the sdks

build_nodejs:: VERSION := $(shell pulumictl get version --language javascript)
build_nodejs:: install_plugins tfgen # build the node sdk
Expand Down
382 changes: 0 additions & 382 deletions README-DEVELOPMENT.md

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
The Astronomer Resource Provider lets you manage [astronomer](https://www.pulumi.com/registry/packages/astronomer/) resources as
part of the [Astronomer Cloud](https://www.astronomer.io/).

This provider is a bridged version of the [terraform provider](https://registry.terraform.io/providers/GK-Consulting/astronomer/latest/docs/resources/workspace). The
majority of the credit needs to go to the original [authors](https://github.com/GK-Consulting/terraform-provider-astronomer) of the terraform provider.
This provider is a bridged version of the offical [astonomer terraform provider](https://registry.terraform.io/providers/astronomer/astro/latest/docs).

## Installing

Expand Down
2 changes: 1 addition & 1 deletion go.work
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
go 1.21.5
go 1.21.12

use (
./provider
Expand Down
317 changes: 314 additions & 3 deletions go.work.sum

Large diffs are not rendered by default.

525 changes: 502 additions & 23 deletions provider/cmd/pulumi-resource-astronomer/bridge-metadata.json

Large diffs are not rendered by default.

5,418 changes: 4,659 additions & 759 deletions provider/cmd/pulumi-resource-astronomer/schema.json

Large diffs are not rendered by default.

220 changes: 111 additions & 109 deletions provider/go.mod

Large diffs are not rendered by default.

1,949 changes: 269 additions & 1,680 deletions provider/go.sum

Large diffs are not rendered by default.

120 changes: 26 additions & 94 deletions provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ import (
_ "embed"
"fmt"
"path/filepath"
"strings"
"unicode"

shimprovider "github.com/GK-Consulting/terraform-provider-astronomer/shim"
"github.com/ettle/strcase"
shimprovider "github.com/astronomer/terraform-provider-astro/shim"
pf "github.com/pulumi/pulumi-terraform-bridge/pf/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/ryan-pip/pulumi-astronomer/provider/pkg/version"
)

Expand All @@ -37,44 +33,10 @@ var bridgeMetadata []byte

// all of the token components used below.
const (
// This variable controls the default name of the package in the package
mainPkg = "astronomer"
mainMod = "index" // the astronomer module
)

func convertName(tfname string) (module string, name string) {
tfNameItems := strings.Split(tfname, "_")
contract.Assertf(len(tfNameItems) >= 2, "Invalid snake case name %s", tfname)
contract.Assertf(tfNameItems[0] == "astronomer", "Invalid snake case name %s. Does not start with astronomer", tfname)
module = mainMod
name = strings.Join(tfNameItems[1:], "_")
contract.Assertf(!unicode.IsDigit(rune(name[0])), "Pulumi name must not start with a digit: %s", name)
name = strcase.ToPascal(name)
return
}

func makeDataSource(ds string) tokens.ModuleMember {
mod, name := convertName(ds)
return tfbridge.MakeDataSource("astronomer", mod, "get"+name)
}

func makeResource(res string) tokens.Type {
mod, name := convertName(res)
return tfbridge.MakeResource("astronomer", mod, name)
}

func moduleComputeStrategy() tfbridge.Strategy {
return tfbridge.Strategy{
Resource: func(tfToken string, elem *tfbridge.ResourceInfo) error {
elem.Tok = makeResource(tfToken)
return nil
},
DataSource: func(tfToken string, elem *tfbridge.DataSourceInfo) error {
elem.Tok = makeDataSource(tfToken)
return nil
},
}
}

// preConfigureCallback is called before the providerConfigure function of the underlying provider.
// It should validate that the provider can be configured, and provide actionable errors in the case
// it cannot be. Configuration variables can be read from `vars` using the `stringValue` function -
Expand All @@ -88,77 +50,46 @@ func Provider() tfbridge.ProviderInfo {
// Instantiate the Terraform provider
p := pf.ShimProvider(shimprovider.NewProvider())

// Create a Pulumi provider mapping
delegateID := func(pulumiField string) tfbridge.ComputeID {
return tfbridge.DelegateIDField(resource.PropertyKey(pulumiField),
"astro", "https://github.com/ryan-pip/pulumi-astronomer")
}

prov := tfbridge.ProviderInfo{
P: p,
Name: "astronomer",
// DisplayName is a way to be able to change the casing of the provider
// name when being displayed on the Pulumi registry
DisplayName: "Astronomer",
// The default publisher for all packages is Pulumi.
// Change this to your personal name (or a company name) that you
// would like to be shown in the Pulumi Registry if this package is published
// there.
Publisher: "ryan-pip",
// LogoURL is optional but useful to help identify your package in the Pulumi Registry
// if this package is published there.
//
// You may host a logo on a domain you control or add an SVG logo for your package
// in your repository and use the raw content URL for that file as your logo URL.
LogoURL: "https://raw.githubusercontent.com/ryan-pip/pulumi-astronomer/main/docs/astronomer.svg",
// PluginDownloadURL is an optional URL used to download the Provider
// for use in Pulumi programs
// e.g https://github.com/org/pulumi-provider-name/releases/
P: p,
Name: "astro",
DisplayName: "Astronomer",
Publisher: "ryan-pip",
LogoURL: "https://raw.githubusercontent.com/ryan-pip/pulumi-astronomer/main/docs/astronomer.svg",
PluginDownloadURL: "github://api.github.com/ryan-pip/pulumi-astronomer",
Description: "A Pulumi package for creating and managing Astronomer Cloud resources",
// category/cloud tag helps with categorizing the package in the Pulumi Registry.
// For all available categories, see `Keywords` in
// https://www.pulumi.com/docs/guides/pulumi-packages/schema/#package.
Keywords: []string{
"pulumi",
"astronomer",
"category/infrastructure",
},
License: "Apache-2.0",
Homepage: "https://github.com/ryan-pip/pulumi-astronomer",
Repository: "https://github.com/ryan-pip/pulumi-astronomer",
// The GitHub Org for the provider - defaults to `terraform-providers`. Note that this
// should match the TF provider module's require directive, not any replace directives.
License: "Apache-2.0",
Homepage: "https://github.com/ryan-pip/pulumi-astronomer",
Repository: "https://github.com/ryan-pip/pulumi-astronomer",
Version: version.Version,
GitHubOrg: "GK-Consulting",
GitHubOrg: "astronomer",
MetadataInfo: tfbridge.NewProviderMetadata(bridgeMetadata),
TFProviderVersion: "0.3.0",
UpstreamRepoPath: "./upstream",
Config: map[string]*tfbridge.SchemaInfo{
// Add any required configuration here, or remove the example below if
// no additional points are required.
// "region": {
// Type: tfbridge.MakeType("region", "Region"),
// Default: &tfbridge.DefaultInfo{
// EnvVars: []string{"AWS_REGION", "AWS_DEFAULT_REGION"},
// },
// },
"token": {
Default: &tfbridge.DefaultInfo{
EnvVars: []string{"ASTRONOMER_API_TOKEN"},
EnvVars: []string{"ASTRO_API_TOKEN"},
},
},
},
PreConfigureCallback: preConfigureCallback,
Resources: map[string]*tfbridge.ResourceInfo{
// Map each resource in the Terraform provider to a Pulumi type.
//
// "aws_iam_role": {
// Tok: makeResource(mainMod, "aws_iam_role"),
// },
},
DataSources: map[string]*tfbridge.DataSourceInfo{
// Map each data source in the Terraform provider to a Pulumi function.
//
// "aws_ami": {
// Tok: makeDataSource(mainMod, "aws_ami"),
// },
Resources: map[string]*tfbridge.ResourceInfo{
"astro_hybrid_cluster_workspace_authorization": {
ComputeID: delegateID("clusterId"),
},
"astro_team_roles": {ComputeID: delegateID("teamId")},
},
DataSources: map[string]*tfbridge.DataSourceInfo{},
JavaScript: &tfbridge.JavaScriptInfo{
PackageName: "@ryan-pip/pulumi_astronomer",

Expand Down Expand Up @@ -204,7 +135,8 @@ func Provider() tfbridge.ProviderInfo {
},
}

prov.MustComputeTokens(moduleComputeStrategy())
prov.MustComputeTokens(tokens.SingleModule("astro_", mainMod,
tokens.MakeStandard(mainPkg)))
prov.SetAutonaming(255, "-")

return prov
Expand Down
56 changes: 40 additions & 16 deletions provider/shim/go.mod
Original file line number Diff line number Diff line change
@@ -1,31 +1,55 @@
module github.com/GK-Consulting/terraform-provider-astronomer/shim
module github.com/astronomer/terraform-provider-astro/shim

go 1.21.5

toolchain go1.21.6

replace (
github.com/GK-Consulting/terraform-provider-astronomer => ../../upstream
github.com/openglshaders/astronomer-api/v2 => ../../upstream/internal/api
terraform-provider-astronomer => github.com/ryan-pip/terraform-provider-astronomer v0.0.0-00010101000000-000000000000
)

require (
github.com/GK-Consulting/terraform-provider-astronomer v0.0.0-00010101000000-000000000000
github.com/hashicorp/terraform-plugin-framework v1.4.2
github.com/ryan-pip/pulumi-astronomer/provider v0.0.0-20240311084552-d5ad20b3423b
github.com/astronomer/terraform-provider-astro v0.3.0
github.com/hashicorp/terraform-plugin-framework v1.9.0
github.com/ryan-pip/pulumi-astronomer/provider v0.0.0-20240607020557-47813651c291
)

require (
github.com/fatih/color v1.15.0 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.19.1 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-plugin v1.6.0 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/hcl/v2 v2.20.1 // indirect
github.com/hashicorp/terraform-plugin-framework-timeouts v0.4.1 // indirect
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0 // indirect
github.com/hashicorp/terraform-plugin-go v0.23.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 // indirect
github.com/hashicorp/terraform-plugin-testing v1.8.0 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/lucsky/cuid v1.2.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/openglshaders/astronomer-api/v2 v2.0.0-00010101000000-000000000000 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/samber/lo v1.39.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/sys v0.16.0 // indirect
github.com/zclconf/go-cty v1.14.4 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.0 // indirect
)
Loading

0 comments on commit 11cf38c

Please sign in to comment.