* IaaS Volume (#541) * Onboard IaaS Volume * Labels mapping * Add acceptance test * Remove source field * Fix lint * Add examples and docs * Fix lint * Fix lint * Fix lint * Volume source field (#542) * Onboard IaaS Volume * Labels mapping * Add acceptance test * Remove source field * Fix lint * Add examples and docs * Fix lint * Fix lint * Fix lint * Add source field supoort * Fix labels and source mapping * Remove unecessary source mapping * Move methods to conversion pkg * Revert change * Update stackit/internal/services/iaas/volume/datasource.go Co-authored-by: João Palet <joao.palet@outlook.com> * Update stackit/internal/services/iaas/volume/resource.go Co-authored-by: João Palet <joao.palet@outlook.com> * Update stackit/internal/services/iaas/volume/resource.go Co-authored-by: João Palet <joao.palet@outlook.com> * Update stackit/internal/services/iaas/volume/resource.go Co-authored-by: João Palet <joao.palet@outlook.com> * Changes after review * Change after revie --------- Co-authored-by: João Palet <joao.palet@outlook.com> * Onboard IaaS security groups (#545) * onboard iaas security group * add examples and generate docs * fix linter issues * fix deletion * Update stackit/internal/services/iaas/securitygroup/resource.go Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * rename data source example file * update docs * remove field * remove field * remove plan modifier from the name field * refactor labels in mapFields * change function from utils to conversion * remove rules from the security group * update docs * add security group acceptance test * add plan modifiers to stateful field * sort imports * change stateful description --------- Co-authored-by: Gökçe Gök Klingel <goekce.goek_klingel@stackit.cloud> Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * IaaS Server baseline configuration (#546) * Server resource schema * Implemente CRUD methods and unit testsg * Bug fixes * Bug fix * Make variable private * Remove delete_on_termination and update descriptions * Add security_group field to initial networking * Add examples and acc test * Generate docs * Fix lint * Fix lint issue * Fix unit test * Update desc * Gen docs * Onboard IaaS network interface (#544) * implement network interface * handle labels * add CIDR validation * fix linter issues and generate docs * remove computed from the allowed addresses and fix the conditions * Update stackit/internal/services/iaas/networkinterface/resource.go Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * Update stackit/internal/services/iaas/networkinterface/datasource.go Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * apply code review changes * remove status from schema * remove unnecessary GET call * Update stackit/internal/services/iaas/networkinterface/resource.go Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * Update stackit/internal/services/iaas/networkinterface/resource.go Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * rename nic_security to security * add beta markdown description * use existing validateIP function * use utils function for the options listing * refactor labels * change function from utils to conversion * make allowed addresses a list of strings * add acceptance test for network interfaces * fix acceptance test * rename security_groups as security_group_ids * extend descriptions * fix acc test --------- Co-authored-by: Gökçe Gök Klingel <goekce.goek_klingel@stackit.cloud> Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * rename volume data source example (#552) Co-authored-by: Gökçe Gök Klingel <goekce.goek_klingel@stackit.cloud> * add requires replace to ipv4 and ipv6 fields (#549) Co-authored-by: Gökçe Gök Klingel <goekce.goek_klingel@stackit.cloud> Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * Server resource improvements (#548) * Improvements to server resource * Fix example * Remove useStateForUnknown * Update SDK modules * Update iaasalpha moduel (#555) * Remove initial networking field (#556) * Server attachment resources (#557) * Server attachemnt resources * Add examples * Update volume datasource example * Fix linting issues * Fix linting * Fix examples formatting * Update go.mod * Revert iaas to v0.11 * Onboard iaas public ip (#551) * onboard public ip * onboard public ip * add public ip acceptance test * Update examples/data-sources/stackit_public_ip/data-source.tf Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * add plan modifier to IP * change type in the volume data source * add network_interface field to public ip resource * rename network_interface to network_interface_id * remove obsolete checks * extend unit tests * add network_interface_id in example * extend unit test * extend acceptance test * sort imports --------- Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * Add labels to network, network are and network area route resources (#559) * Fix network_interface example * Extend network, network area and network area route with labels * Revert iaas to v0.11.0 --------- Co-authored-by: GokceGK <161626272+GokceGK@users.noreply.github.com> * Onboard iaas security group rule (#553) * onboard security group rule * add security group rule to acceptance test * change type in examples * fix acc test issues * extend example with objects * remove obsolete field from acceptance test * remove unnecessary plan modifier * adapt schema fields * adapt schema fields * add requires replace to all fields * extend descriptions with protocol limitations * rename subfield protocol to number * add requires replace to objects * make icmp_parameters fields required * add empty field checks for nested objects * make max and min fields required in the port_range object * make number field computed in the protocol object * add UseStateForUnknown in protocol number * remove obsolete unit test * add checks for empty protocol and adapt unit test * add atLeastOneOf validation in protocol fields * fix linter issues * Add project existence check before deleting SNA (#561) * add project list check and error in network area deletion * Update stackit/internal/services/iaas/networkarea/resource.go Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> --------- Co-authored-by: Vicente Pinto <vicente.pinto@freiheit.com> * Example server use cases and other fixes (#560) * Add example usage to server resource * Update examples * Fix beta warning * Update docs and examples * Remove size from example * Fix server description, fix security group rule error message * Other fixes * remove field from datasource --------- Co-authored-by: GokceGK <161626272+GokceGK@users.noreply.github.com> * Security group rule fixes (#562) * Add example usage to server resource * Update examples * Fix beta warning * Update docs and examples * Remove size from example * Fix server description, fix security group rule error message * Other fixes * Fixes to sec group rule * Fix lint * Change after review --------- Co-authored-by: GokceGK <161626272+GokceGK@users.noreply.github.com> * Fix server example (#565) * Fix server example * Fixes to examples, add CIDR validation to nic * Migrate iaasalpha to iaas (#568) * Migrate iaasalpha to iaas * Fix lint * Update example * Improvements to security group rule (#569) * Improvements to security group rule * Fix lint * Fix example and remove computed from description * Fix formatting * Update description --------- Co-authored-by: João Palet <joao.palet@outlook.com> Co-authored-by: GokceGK <161626272+GokceGK@users.noreply.github.com> Co-authored-by: Gökçe Gök Klingel <goekce.goek_klingel@stackit.cloud>
505 lines
28 KiB
Go
505 lines
28 KiB
Go
package stackit
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"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"
|
|
argusCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/argus/credential"
|
|
argusInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/argus/instance"
|
|
argusScrapeConfig "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/argus/scrapeconfig"
|
|
dnsRecordSet "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/dns/recordset"
|
|
dnsZone "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/dns/zone"
|
|
iaasNetwork "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/network"
|
|
iaasNetworkArea "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/networkarea"
|
|
iaasNetworkAreaRoute "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/networkarearoute"
|
|
iaasNetworkInterface "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/networkinterface"
|
|
iaasNetworkInterfaceAttach "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/networkinterfaceattach"
|
|
iaasPublicIp "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/publicip"
|
|
iaasSecurityGroup "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/securitygroup"
|
|
iaasSecurityGroupRule "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/securitygrouprule"
|
|
iaasServer "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/server"
|
|
iaasServiceAccountAttach "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/serviceaccountattach"
|
|
iaasVolume "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/volume"
|
|
iaasVolumeAttach "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/iaas/volumeattach"
|
|
loadBalancerCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/loadbalancer/credential"
|
|
loadBalancer "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/loadbalancer/loadbalancer"
|
|
loadBalancerObservabilityCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/loadbalancer/observability-credential"
|
|
logMeCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logme/credential"
|
|
logMeInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/logme/instance"
|
|
mariaDBCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/mariadb/credential"
|
|
mariaDBInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/mariadb/instance"
|
|
mongoDBFlexInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/mongodbflex/instance"
|
|
mongoDBFlexUser "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/mongodbflex/user"
|
|
objectStorageBucket "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/objectstorage/bucket"
|
|
objecStorageCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/objectstorage/credential"
|
|
objecStorageCredentialsGroup "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/objectstorage/credentialsgroup"
|
|
observabilityCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/observability/credential"
|
|
observabilityInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/observability/instance"
|
|
observabilityScrapeConfig "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/observability/scrapeconfig"
|
|
openSearchCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/opensearch/credential"
|
|
openSearchInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/opensearch/instance"
|
|
postgresFlexDatabase "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/database"
|
|
postgresFlexInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/instance"
|
|
postgresFlexUser "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/postgresflex/user"
|
|
rabbitMQCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/rabbitmq/credential"
|
|
rabbitMQInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/rabbitmq/instance"
|
|
redisCredential "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/redis/credential"
|
|
redisInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/redis/instance"
|
|
resourceManagerProject "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/resourcemanager/project"
|
|
secretsManagerInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/secretsmanager/instance"
|
|
secretsManagerUser "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/secretsmanager/user"
|
|
serverBackupSchedule "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/serverbackup/schedule"
|
|
skeCluster "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/ske/cluster"
|
|
skeKubeconfig "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/ske/kubeconfig"
|
|
skeProject "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/ske/project"
|
|
sqlServerFlexInstance "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sqlserverflex/instance"
|
|
sqlServerFlexUser "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sqlserverflex/user"
|
|
|
|
sdkauth "github.com/stackitcloud/stackit-sdk-go/core/auth"
|
|
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
|
|
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
|
)
|
|
|
|
// Ensure the implementation satisfies the expected interfaces
|
|
var (
|
|
_ provider.Provider = &Provider{}
|
|
)
|
|
|
|
// Provider is the provider implementation.
|
|
type Provider struct {
|
|
version string
|
|
}
|
|
|
|
// New is a helper function to simplify provider server and testing implementation.
|
|
func New(version string) func() provider.Provider {
|
|
return func() provider.Provider {
|
|
return &Provider{
|
|
version: version,
|
|
}
|
|
}
|
|
}
|
|
|
|
func (p *Provider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
|
|
resp.TypeName = "stackit"
|
|
resp.Version = p.version
|
|
}
|
|
|
|
type providerModel struct {
|
|
CredentialsFilePath types.String `tfsdk:"credentials_path"`
|
|
ServiceAccountEmail types.String `tfsdk:"service_account_email"`
|
|
ServiceAccountKey types.String `tfsdk:"service_account_key"`
|
|
ServiceAccountKeyPath types.String `tfsdk:"service_account_key_path"`
|
|
PrivateKey types.String `tfsdk:"private_key"`
|
|
PrivateKeyPath types.String `tfsdk:"private_key_path"`
|
|
Token types.String `tfsdk:"service_account_token"`
|
|
Region types.String `tfsdk:"region"`
|
|
ArgusCustomEndpoint types.String `tfsdk:"argus_custom_endpoint"`
|
|
DNSCustomEndpoint types.String `tfsdk:"dns_custom_endpoint"`
|
|
IaaSCustomEndpoint types.String `tfsdk:"iaas_custom_endpoint"`
|
|
PostgresFlexCustomEndpoint types.String `tfsdk:"postgresflex_custom_endpoint"`
|
|
MongoDBFlexCustomEndpoint types.String `tfsdk:"mongodbflex_custom_endpoint"`
|
|
LoadBalancerCustomEndpoint types.String `tfsdk:"loadbalancer_custom_endpoint"`
|
|
LogMeCustomEndpoint types.String `tfsdk:"logme_custom_endpoint"`
|
|
RabbitMQCustomEndpoint types.String `tfsdk:"rabbitmq_custom_endpoint"`
|
|
MariaDBCustomEndpoint types.String `tfsdk:"mariadb_custom_endpoint"`
|
|
AuthorizationCustomEndpoint types.String `tfsdk:"authorization_custom_endpoint"`
|
|
ObjectStorageCustomEndpoint types.String `tfsdk:"objectstorage_custom_endpoint"`
|
|
ObservabilityCustomEndpoint types.String `tfsdk:"observability_custom_endpoint"`
|
|
OpenSearchCustomEndpoint types.String `tfsdk:"opensearch_custom_endpoint"`
|
|
RedisCustomEndpoint types.String `tfsdk:"redis_custom_endpoint"`
|
|
SecretsManagerCustomEndpoint types.String `tfsdk:"secretsmanager_custom_endpoint"`
|
|
SQLServerFlexCustomEndpoint types.String `tfsdk:"sqlserverflex_custom_endpoint"`
|
|
SKECustomEndpoint types.String `tfsdk:"ske_custom_endpoint"`
|
|
ServerBackupCustomEndpoint types.String `tfsdk:"server_backup_custom_endpoint"`
|
|
ResourceManagerCustomEndpoint types.String `tfsdk:"resourcemanager_custom_endpoint"`
|
|
TokenCustomEndpoint types.String `tfsdk:"token_custom_endpoint"`
|
|
EnableBetaResources types.Bool `tfsdk:"enable_beta_resources"`
|
|
ServiceEnablementCustomEndpoint types.String `tfsdk:"service_enablement_custom_endpoint"`
|
|
}
|
|
|
|
// Schema defines the provider-level schema for configuration data.
|
|
func (p *Provider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
|
|
descriptions := map[string]string{
|
|
"credentials_path": "Path of JSON from where the credentials are read. Takes precedence over the env var `STACKIT_CREDENTIALS_PATH`. Default value is `~/.stackit/credentials.json`.",
|
|
"service_account_token": "Token used for authentication. If set, the token flow will be used to authenticate all operations.",
|
|
"service_account_key_path": "Path for the service account key used for authentication. If set, the key flow will be used to authenticate all operations.",
|
|
"service_account_key": "Service account key used for authentication. If set, the key flow will be used to authenticate all operations.",
|
|
"private_key_path": "Path for the private RSA key used for authentication, relevant for the key flow. It takes precedence over the private key that is included in the service account key.",
|
|
"private_key": "Private RSA key used for authentication, relevant for the key flow. It takes precedence over the private key that is included in the service account key.",
|
|
"service_account_email": "Service account email. It can also be set using the environment variable STACKIT_SERVICE_ACCOUNT_EMAIL. It is required if you want to use the resource manager project resource.",
|
|
"region": "Region will be used as the default location for regional services. Not all services require a region, some are global",
|
|
"argus_custom_endpoint": "Custom endpoint for the Argus service",
|
|
"dns_custom_endpoint": "Custom endpoint for the DNS service",
|
|
"iaas_custom_endpoint": "Custom endpoint for the IaaS service",
|
|
"mongodbflex_custom_endpoint": "Custom endpoint for the MongoDB Flex service",
|
|
"loadbalancer_custom_endpoint": "Custom endpoint for the Load Balancer service",
|
|
"logme_custom_endpoint": "Custom endpoint for the LogMe service",
|
|
"rabbitmq_custom_endpoint": "Custom endpoint for the RabbitMQ service",
|
|
"mariadb_custom_endpoint": "Custom endpoint for the MariaDB service",
|
|
"authorization_custom_endpoint": "Custom endpoint for the Membership service",
|
|
"objectstorage_custom_endpoint": "Custom endpoint for the Object Storage service",
|
|
"observability_custom_endpoint": "Custom endpoint for the Observability service",
|
|
"opensearch_custom_endpoint": "Custom endpoint for the OpenSearch service",
|
|
"postgresflex_custom_endpoint": "Custom endpoint for the PostgresFlex service",
|
|
"redis_custom_endpoint": "Custom endpoint for the Redis service",
|
|
"server_backup_custom_endpoint": "Custom endpoint for the Server Backup service",
|
|
"resourcemanager_custom_endpoint": "Custom endpoint for the Resource Manager service",
|
|
"secretsmanager_custom_endpoint": "Custom endpoint for the Secrets Manager service",
|
|
"sqlserverflex_custom_endpoint": "Custom endpoint for the SQL Server Flex service",
|
|
"ske_custom_endpoint": "Custom endpoint for the Kubernetes Engine (SKE) service",
|
|
"service_enablement_custom_endpoint": "Custom endpoint for the Service Enablement API",
|
|
"token_custom_endpoint": "Custom endpoint for the token API, which is used to request access tokens when using the key flow",
|
|
"enable_beta_resources": "Enable beta resources. Default is false.",
|
|
}
|
|
|
|
resp.Schema = schema.Schema{
|
|
Attributes: map[string]schema.Attribute{
|
|
"credentials_path": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["credentials_path"],
|
|
},
|
|
"service_account_email": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["service_account_email"],
|
|
},
|
|
"service_account_token": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["service_account_token"],
|
|
},
|
|
"service_account_key_path": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["service_account_key_path"],
|
|
},
|
|
"service_account_key": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["service_account_key"],
|
|
},
|
|
"private_key": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["private_key"],
|
|
},
|
|
"private_key_path": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["private_key_path"],
|
|
},
|
|
"region": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["region"],
|
|
},
|
|
"argus_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["argus_custom_endpoint"],
|
|
DeprecationMessage: "Argus service has been deprecated and integration will be removed after February 26th 2025. Please use `observability_custom_endpoint` and `observability` resources instead, which offer the exact same functionality.",
|
|
},
|
|
"dns_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["dns_custom_endpoint"],
|
|
},
|
|
"iaas_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["iaas_custom_endpoint"],
|
|
},
|
|
"postgresflex_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["postgresflex_custom_endpoint"],
|
|
},
|
|
"mariadb_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["mariadb_custom_endpoint"],
|
|
},
|
|
"authorization_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["authorization_custom_endpoint"],
|
|
},
|
|
"mongodbflex_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["mongodbflex_custom_endpoint"],
|
|
},
|
|
"loadbalancer_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["loadbalancer_custom_endpoint"],
|
|
},
|
|
"logme_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["logme_custom_endpoint"],
|
|
},
|
|
"rabbitmq_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["rabbitmq_custom_endpoint"],
|
|
},
|
|
"objectstorage_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["objectstorage_custom_endpoint"],
|
|
},
|
|
"observability_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["observability_custom_endpoint"],
|
|
},
|
|
"opensearch_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["opensearch_custom_endpoint"],
|
|
},
|
|
"redis_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["redis_custom_endpoint"],
|
|
},
|
|
"resourcemanager_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["resourcemanager_custom_endpoint"],
|
|
},
|
|
"secretsmanager_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["secretsmanager_custom_endpoint"],
|
|
},
|
|
"sqlserverflex_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["sqlserverflex_custom_endpoint"],
|
|
},
|
|
"ske_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["ske_custom_endpoint"],
|
|
},
|
|
"server_backup_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["server_backup_custom_endpoint"],
|
|
},
|
|
"service_enablement_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["service_enablement_custom_endpoint"],
|
|
},
|
|
"token_custom_endpoint": schema.StringAttribute{
|
|
Optional: true,
|
|
Description: descriptions["token_custom_endpoint"],
|
|
},
|
|
"enable_beta_resources": schema.BoolAttribute{
|
|
Optional: true,
|
|
Description: descriptions["enable_beta_resources"],
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
// Configure prepares a stackit API client for data sources and resources.
|
|
func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
|
|
// Retrieve provider data and configuration
|
|
var providerConfig providerModel
|
|
diags := req.Config.Get(ctx, &providerConfig)
|
|
resp.Diagnostics.Append(diags...)
|
|
if resp.Diagnostics.HasError() {
|
|
return
|
|
}
|
|
|
|
// Configure SDK client
|
|
sdkConfig := &config.Configuration{}
|
|
var providerData core.ProviderData
|
|
if !(providerConfig.CredentialsFilePath.IsUnknown() || providerConfig.CredentialsFilePath.IsNull()) {
|
|
sdkConfig.CredentialsFilePath = providerConfig.CredentialsFilePath.ValueString()
|
|
}
|
|
if !(providerConfig.ServiceAccountEmail.IsUnknown() || providerConfig.ServiceAccountEmail.IsNull()) {
|
|
providerData.ServiceAccountEmail = providerConfig.ServiceAccountEmail.ValueString()
|
|
sdkConfig.ServiceAccountEmail = providerConfig.ServiceAccountEmail.ValueString()
|
|
}
|
|
if !(providerConfig.ServiceAccountKey.IsUnknown() || providerConfig.ServiceAccountKey.IsNull()) {
|
|
sdkConfig.ServiceAccountKey = providerConfig.ServiceAccountKey.ValueString()
|
|
}
|
|
if !(providerConfig.ServiceAccountKeyPath.IsUnknown() || providerConfig.ServiceAccountKeyPath.IsNull()) {
|
|
sdkConfig.ServiceAccountKeyPath = providerConfig.ServiceAccountKeyPath.ValueString()
|
|
}
|
|
if !(providerConfig.PrivateKey.IsUnknown() || providerConfig.PrivateKey.IsNull()) {
|
|
sdkConfig.PrivateKey = providerConfig.PrivateKey.ValueString()
|
|
}
|
|
if !(providerConfig.PrivateKeyPath.IsUnknown() || providerConfig.PrivateKeyPath.IsNull()) {
|
|
sdkConfig.PrivateKeyPath = providerConfig.PrivateKeyPath.ValueString()
|
|
}
|
|
if !(providerConfig.Token.IsUnknown() || providerConfig.Token.IsNull()) {
|
|
sdkConfig.Token = providerConfig.Token.ValueString()
|
|
}
|
|
if !(providerConfig.Region.IsUnknown() || providerConfig.Region.IsNull()) {
|
|
providerData.Region = providerConfig.Region.ValueString()
|
|
}
|
|
if !(providerConfig.ArgusCustomEndpoint.IsUnknown() || providerConfig.ArgusCustomEndpoint.IsNull()) {
|
|
providerData.ArgusCustomEndpoint = providerConfig.ArgusCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.DNSCustomEndpoint.IsUnknown() || providerConfig.DNSCustomEndpoint.IsNull()) {
|
|
providerData.DnsCustomEndpoint = providerConfig.DNSCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.IaaSCustomEndpoint.IsUnknown() || providerConfig.IaaSCustomEndpoint.IsNull()) {
|
|
providerData.IaaSCustomEndpoint = providerConfig.IaaSCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.PostgresFlexCustomEndpoint.IsUnknown() || providerConfig.PostgresFlexCustomEndpoint.IsNull()) {
|
|
providerData.PostgresFlexCustomEndpoint = providerConfig.PostgresFlexCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.MongoDBFlexCustomEndpoint.IsUnknown() || providerConfig.MongoDBFlexCustomEndpoint.IsNull()) {
|
|
providerData.MongoDBFlexCustomEndpoint = providerConfig.MongoDBFlexCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.LoadBalancerCustomEndpoint.IsUnknown() || providerConfig.LoadBalancerCustomEndpoint.IsNull()) {
|
|
providerData.LoadBalancerCustomEndpoint = providerConfig.LoadBalancerCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.LogMeCustomEndpoint.IsUnknown() || providerConfig.LogMeCustomEndpoint.IsNull()) {
|
|
providerData.LogMeCustomEndpoint = providerConfig.LogMeCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.RabbitMQCustomEndpoint.IsUnknown() || providerConfig.RabbitMQCustomEndpoint.IsNull()) {
|
|
providerData.RabbitMQCustomEndpoint = providerConfig.RabbitMQCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.MariaDBCustomEndpoint.IsUnknown() || providerConfig.MariaDBCustomEndpoint.IsNull()) {
|
|
providerData.MariaDBCustomEndpoint = providerConfig.MariaDBCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.AuthorizationCustomEndpoint.IsUnknown() || providerConfig.AuthorizationCustomEndpoint.IsNull()) {
|
|
providerData.AuthorizationCustomEndpoint = providerConfig.AuthorizationCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.ObjectStorageCustomEndpoint.IsUnknown() || providerConfig.ObjectStorageCustomEndpoint.IsNull()) {
|
|
providerData.ObjectStorageCustomEndpoint = providerConfig.ObjectStorageCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.ObservabilityCustomEndpoint.IsUnknown() || providerConfig.ObservabilityCustomEndpoint.IsNull()) {
|
|
providerData.ObservabilityCustomEndpoint = providerConfig.ObservabilityCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.OpenSearchCustomEndpoint.IsUnknown() || providerConfig.OpenSearchCustomEndpoint.IsNull()) {
|
|
providerData.OpenSearchCustomEndpoint = providerConfig.OpenSearchCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.RedisCustomEndpoint.IsUnknown() || providerConfig.RedisCustomEndpoint.IsNull()) {
|
|
providerData.RedisCustomEndpoint = providerConfig.RedisCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.ResourceManagerCustomEndpoint.IsUnknown() || providerConfig.ResourceManagerCustomEndpoint.IsNull()) {
|
|
providerData.ResourceManagerCustomEndpoint = providerConfig.ResourceManagerCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.SecretsManagerCustomEndpoint.IsUnknown() || providerConfig.SecretsManagerCustomEndpoint.IsNull()) {
|
|
providerData.SecretsManagerCustomEndpoint = providerConfig.SecretsManagerCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.SQLServerFlexCustomEndpoint.IsUnknown() || providerConfig.SQLServerFlexCustomEndpoint.IsNull()) {
|
|
providerData.SQLServerFlexCustomEndpoint = providerConfig.SQLServerFlexCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.SKECustomEndpoint.IsUnknown() || providerConfig.SKECustomEndpoint.IsNull()) {
|
|
providerData.SKECustomEndpoint = providerConfig.SKECustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.ServiceEnablementCustomEndpoint.IsUnknown() || providerConfig.ServiceEnablementCustomEndpoint.IsNull()) {
|
|
providerData.ServiceEnablementCustomEndpoint = providerConfig.ServiceEnablementCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.TokenCustomEndpoint.IsUnknown() || providerConfig.TokenCustomEndpoint.IsNull()) {
|
|
sdkConfig.TokenCustomUrl = providerConfig.TokenCustomEndpoint.ValueString()
|
|
}
|
|
if !(providerConfig.EnableBetaResources.IsUnknown() || providerConfig.EnableBetaResources.IsNull()) {
|
|
providerData.EnableBetaResources = providerConfig.EnableBetaResources.ValueBool()
|
|
}
|
|
roundTripper, err := sdkauth.SetupAuth(sdkConfig)
|
|
if err != nil {
|
|
core.LogAndAddError(ctx, &resp.Diagnostics, "Error configuring provider", fmt.Sprintf("Setting up authentication: %v", err))
|
|
return
|
|
}
|
|
|
|
// Make round tripper and custom endpoints available during DataSource and Resource
|
|
// type Configure methods.
|
|
providerData.RoundTripper = roundTripper
|
|
resp.DataSourceData = providerData
|
|
resp.ResourceData = providerData
|
|
}
|
|
|
|
// DataSources defines the data sources implemented in the provider.
|
|
func (p *Provider) DataSources(_ context.Context) []func() datasource.DataSource {
|
|
return []func() datasource.DataSource{
|
|
argusInstance.NewInstanceDataSource,
|
|
argusScrapeConfig.NewScrapeConfigDataSource,
|
|
dnsZone.NewZoneDataSource,
|
|
dnsRecordSet.NewRecordSetDataSource,
|
|
iaasNetwork.NewNetworkDataSource,
|
|
iaasNetworkArea.NewNetworkAreaDataSource,
|
|
iaasNetworkAreaRoute.NewNetworkAreaRouteDataSource,
|
|
iaasNetworkInterface.NewNetworkInterfaceDataSource,
|
|
iaasVolume.NewVolumeDataSource,
|
|
iaasPublicIp.NewPublicIpDataSource,
|
|
iaasServer.NewServerDataSource,
|
|
iaasSecurityGroup.NewSecurityGroupDataSource,
|
|
iaasSecurityGroupRule.NewSecurityGroupRuleDataSource,
|
|
loadBalancer.NewLoadBalancerDataSource,
|
|
logMeInstance.NewInstanceDataSource,
|
|
logMeCredential.NewCredentialDataSource,
|
|
mariaDBInstance.NewInstanceDataSource,
|
|
mariaDBCredential.NewCredentialDataSource,
|
|
mongoDBFlexInstance.NewInstanceDataSource,
|
|
mongoDBFlexUser.NewUserDataSource,
|
|
objectStorageBucket.NewBucketDataSource,
|
|
objecStorageCredentialsGroup.NewCredentialsGroupDataSource,
|
|
objecStorageCredential.NewCredentialDataSource,
|
|
observabilityInstance.NewInstanceDataSource,
|
|
observabilityScrapeConfig.NewScrapeConfigDataSource,
|
|
openSearchInstance.NewInstanceDataSource,
|
|
openSearchCredential.NewCredentialDataSource,
|
|
postgresFlexDatabase.NewDatabaseDataSource,
|
|
postgresFlexInstance.NewInstanceDataSource,
|
|
postgresFlexUser.NewUserDataSource,
|
|
rabbitMQInstance.NewInstanceDataSource,
|
|
rabbitMQCredential.NewCredentialDataSource,
|
|
redisInstance.NewInstanceDataSource,
|
|
redisCredential.NewCredentialDataSource,
|
|
resourceManagerProject.NewProjectDataSource,
|
|
secretsManagerInstance.NewInstanceDataSource,
|
|
secretsManagerUser.NewUserDataSource,
|
|
sqlServerFlexInstance.NewInstanceDataSource,
|
|
sqlServerFlexUser.NewUserDataSource,
|
|
serverBackupSchedule.NewScheduleDataSource,
|
|
serverBackupSchedule.NewSchedulesDataSource,
|
|
skeProject.NewProjectDataSource,
|
|
skeCluster.NewClusterDataSource,
|
|
}
|
|
}
|
|
|
|
// Resources defines the resources implemented in the provider.
|
|
func (p *Provider) Resources(_ context.Context) []func() resource.Resource {
|
|
return []func() resource.Resource{
|
|
argusCredential.NewCredentialResource,
|
|
argusInstance.NewInstanceResource,
|
|
argusScrapeConfig.NewScrapeConfigResource,
|
|
dnsZone.NewZoneResource,
|
|
dnsRecordSet.NewRecordSetResource,
|
|
iaasNetwork.NewNetworkResource,
|
|
iaasNetworkArea.NewNetworkAreaResource,
|
|
iaasNetworkAreaRoute.NewNetworkAreaRouteResource,
|
|
iaasNetworkInterface.NewNetworkInterfaceResource,
|
|
iaasVolume.NewVolumeResource,
|
|
iaasPublicIp.NewPublicIpResource,
|
|
iaasVolumeAttach.NewVolumeAttachResource,
|
|
iaasNetworkInterfaceAttach.NewNetworkInterfaceAttachResource,
|
|
iaasServiceAccountAttach.NewServiceAccountAttachResource,
|
|
iaasServer.NewServerResource,
|
|
iaasSecurityGroup.NewSecurityGroupResource,
|
|
iaasSecurityGroupRule.NewSecurityGroupRuleResource,
|
|
loadBalancer.NewLoadBalancerResource,
|
|
loadBalancerCredential.NewCredentialResource,
|
|
loadBalancerObservabilityCredential.NewObservabilityCredentialResource,
|
|
logMeInstance.NewInstanceResource,
|
|
logMeCredential.NewCredentialResource,
|
|
mariaDBInstance.NewInstanceResource,
|
|
mariaDBCredential.NewCredentialResource,
|
|
mongoDBFlexInstance.NewInstanceResource,
|
|
mongoDBFlexUser.NewUserResource,
|
|
objectStorageBucket.NewBucketResource,
|
|
objecStorageCredentialsGroup.NewCredentialsGroupResource,
|
|
objecStorageCredential.NewCredentialResource,
|
|
observabilityCredential.NewCredentialResource,
|
|
observabilityInstance.NewInstanceResource,
|
|
observabilityScrapeConfig.NewScrapeConfigResource,
|
|
openSearchInstance.NewInstanceResource,
|
|
openSearchCredential.NewCredentialResource,
|
|
postgresFlexDatabase.NewDatabaseResource,
|
|
postgresFlexInstance.NewInstanceResource,
|
|
postgresFlexUser.NewUserResource,
|
|
rabbitMQInstance.NewInstanceResource,
|
|
rabbitMQCredential.NewCredentialResource,
|
|
redisInstance.NewInstanceResource,
|
|
redisCredential.NewCredentialResource,
|
|
resourceManagerProject.NewProjectResource,
|
|
secretsManagerInstance.NewInstanceResource,
|
|
secretsManagerUser.NewUserResource,
|
|
sqlServerFlexInstance.NewInstanceResource,
|
|
sqlServerFlexUser.NewUserResource,
|
|
serverBackupSchedule.NewScheduleResource,
|
|
skeProject.NewProjectResource,
|
|
skeCluster.NewClusterResource,
|
|
skeKubeconfig.NewKubeconfigResource,
|
|
}
|
|
}
|