-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathframework_provider.go
161 lines (148 loc) · 5.01 KB
/
framework_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package octopusdeploy_framework
import (
"context"
"os"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"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"`
AccessToken types.String `tfsdk:"access_token"`
SpaceID types.String `tfsdk:"space_id"`
}
var _ provider.Provider = (*octopusDeployFrameworkProvider)(nil)
var _ provider.ProviderWithMetaSchema = (*octopusDeployFrameworkProvider)(nil)
var _ provider.ProviderWithFunctions
func NewOctopusDeployFrameworkProvider() *octopusDeployFrameworkProvider {
return &octopusDeployFrameworkProvider{}
}
func (p *octopusDeployFrameworkProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = util.GetProviderName()
}
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()
if config.ApiKey == "" {
config.ApiKey = os.Getenv("OCTOPUS_APIKEY")
}
if config.ApiKey == "" {
config.ApiKey = os.Getenv("OCTOPUS_API_KEY")
}
if config.AccessToken == "" {
config.AccessToken = os.Getenv("OCTOPUS_ACCESS_TOKEN")
}
config.Address = providerData.Address.ValueString()
if config.Address == "" {
config.Address = os.Getenv("OCTOPUS_URL")
}
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{
NewProjectGroupsDataSource,
NewSpaceDataSource,
NewSpacesDataSource,
NewLifecyclesDataSource,
NewEnvironmentsDataSource,
NewStepTemplateDataSource,
NewGitCredentialsDataSource,
NewFeedsDataSource,
NewLibraryVariableSetDataSource,
NewVariablesDataSource,
NewProjectsDataSource,
NewMachineProxyDataSource,
NewTenantsDataSource,
NewTagSetsDataSource,
NewScriptModuleDataSource,
NewTenantProjectDataSource,
NewUsersDataSource,
NewServiceAccountOIDCIdentityDataSource,
NewWorkersDataSource,
NewDeploymentFreezeDataSource,
}
}
func (p *octopusDeployFrameworkProvider) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{
NewSpaceResource,
NewProjectGroupResource,
NewMavenFeedResource,
NewOCIRegistryFeedResource,
NewS3FeedResource,
NewGoogleContainerRegistryFeedResource,
NewAzureContainerRegistryFeedResource,
NewLifecycleResource,
NewEnvironmentResource,
NewStepTemplateResource,
NewGitCredentialResource,
NewHelmFeedResource,
NewArtifactoryGenericFeedResource,
NewGitHubRepositoryFeedResource,
NewAwsElasticContainerRegistryFeedResource,
NewNugetFeedResource,
NewTenantProjectResource,
NewTenantProjectVariableResource,
NewTenantCommonVariableResource,
NewLibraryVariableSetFeedResource,
NewVariableResource,
NewProjectResource,
NewProjectVersioningStrategyResource,
NewMachineProxyResource,
NewTagResource,
NewDockerContainerRegistryFeedResource,
NewTagSetResource,
NewUsernamePasswordAccountResource,
NewRunbookResource,
NewTenantResource,
NewTentacleCertificateResource,
NewListeningTentacleWorkerResource,
NewSSHConnectionWorkerResource,
NewScriptModuleResource,
NewUserResource,
NewDeploymentFreezeResource,
NewDeploymentFreezeProjectResource,
NewServiceAccountOIDCIdentity,
NewGenericOidcResource,
NewDeploymentFreezeTenantResource,
NewGitTriggerResource,
NewBuiltInTriggerResource,
}
}
func (p *octopusDeployFrameworkProvider) Schema(_ context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"address": schema.StringAttribute{
Optional: true,
Description: "The endpoint of the Octopus REST API",
},
"api_key": schema.StringAttribute{
Optional: true,
Description: "The API key to use with the Octopus REST API",
},
"access_token": schema.StringAttribute{
Optional: true,
Description: "The OIDC Access Token to use with the Octopus REST API",
},
"space_id": schema.StringAttribute{
Optional: true,
Description: "The space ID to target",
},
},
}
}