-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: added mux server for sxs framework migration (#664)
* added mux server for sxs framework migration * removed broken framework provider tests * updated provider type name
- Loading branch information
1 parent
ad7a8b9
commit 042152e
Showing
5 changed files
with
168 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package octopusdeploy_framework | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client" | ||
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"net/url" | ||
) | ||
|
||
type Config struct { | ||
Address string | ||
ApiKey string | ||
SpaceID string | ||
Client *client.Client | ||
} | ||
|
||
func (c *Config) GetClient(ctx context.Context) error { | ||
tflog.Debug(ctx, "GetClient") | ||
apiURL, err := url.Parse(c.Address) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
octopus, err := client.NewClient(nil, apiURL, c.ApiKey, "") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(c.SpaceID) > 0 { | ||
space, err := spaces.GetByID(octopus, c.SpaceID) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
octopus, err = client.NewClient(nil, apiURL, c.ApiKey, space.GetID()) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
c.Client = octopus | ||
|
||
createdClient := octopus != nil | ||
tflog.Debug(ctx, fmt.Sprintf("GetClient completed: %t", createdClient)) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package octopusdeploy_framework | ||
|
||
import ( | ||
"context" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/provider" | ||
"github.com/hashicorp/terraform-plugin-framework/provider/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
type octopusDeployFrameworkProvider struct { | ||
Address types.String `tfsdk:"address"` | ||
ApiKey types.String `tfsdk:"api_key"` | ||
SpaceID types.String `tfsdk:"space_id"` | ||
} | ||
|
||
var _ provider.Provider = (*octopusDeployFrameworkProvider)(nil) | ||
var _ provider.ProviderWithMetaSchema = (*octopusDeployFrameworkProvider)(nil) | ||
|
||
func NewOctopusDeployFrameworkProvider() *octopusDeployFrameworkProvider { | ||
return &octopusDeployFrameworkProvider{} | ||
} | ||
|
||
func (p *octopusDeployFrameworkProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { | ||
resp.TypeName = "octopusdeploy" | ||
} | ||
|
||
func (p *octopusDeployFrameworkProvider) MetaSchema(ctx context.Context, request provider.MetaSchemaRequest, response *provider.MetaSchemaResponse) { | ||
|
||
} | ||
|
||
func (p *octopusDeployFrameworkProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { | ||
var providerData octopusDeployFrameworkProvider | ||
resp.Diagnostics.Append(req.Config.Get(ctx, &providerData)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
config := Config{} | ||
config.ApiKey = providerData.ApiKey.ValueString() | ||
config.Address = providerData.Address.ValueString() | ||
config.SpaceID = providerData.SpaceID.ValueString() | ||
if err := config.GetClient(ctx); err != nil { | ||
resp.Diagnostics.AddError("failed to load client", err.Error()) | ||
} | ||
|
||
resp.DataSourceData = &config | ||
resp.ResourceData = &config | ||
} | ||
|
||
func (p *octopusDeployFrameworkProvider) DataSources(ctx context.Context) []func() datasource.DataSource { | ||
return []func() datasource.DataSource{} | ||
} | ||
|
||
func (p *octopusDeployFrameworkProvider) Resources(ctx context.Context) []func() resource.Resource { | ||
return []func() resource.Resource{} | ||
} | ||
|
||
func (p *octopusDeployFrameworkProvider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
Attributes: map[string]schema.Attribute{ | ||
"address": schema.StringAttribute{ | ||
Optional: false, | ||
Required: true, | ||
Description: "The endpoint of the Octopus REST API", | ||
}, | ||
"api_key": schema.StringAttribute{ | ||
Optional: false, | ||
Required: true, | ||
Description: "The API key to use with the Octopus REST API", | ||
}, | ||
"space_id": schema.StringAttribute{ | ||
Optional: true, | ||
Description: "The space ID to target", | ||
}, | ||
}, | ||
} | ||
} |