feat: testing (#34)
## Description
<!-- **Please link some issue here describing what you are trying to achieve.**
In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->
relates to #1234
## Checklist
- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)
Reviewed-on: #34
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
parent
c22e758b2c
commit
32e41d8b44
24 changed files with 858 additions and 2431 deletions
|
|
@ -1,12 +1,233 @@
|
|||
package postgresflexalpha
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/testutil"
|
||||
)
|
||||
|
||||
var (
|
||||
validFlavor = "2.4"
|
||||
kekKeyRingId = ""
|
||||
kekKeyVersion = ""
|
||||
kekKeySA = ""
|
||||
)
|
||||
|
||||
func testAccPreCheck(t *testing.T) {
|
||||
// TODO: if needed ...
|
||||
}
|
||||
|
||||
//func TestAccResourceExample_parallel(t *testing.T) {
|
||||
// t.Parallel()
|
||||
//
|
||||
// exData := resData{
|
||||
// Region: "eu01",
|
||||
// ServiceAccountFilePath: sa_file,
|
||||
// ProjectID: project_id,
|
||||
// Name: acctest.RandomWithPrefix("tf-acc"),
|
||||
// }
|
||||
//
|
||||
// resource.Test(t, resource.TestCase{
|
||||
// ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
|
||||
// Steps: []resource.TestStep{
|
||||
// {
|
||||
// Config: testAccResourceEncryptionExampleConfig(exData),
|
||||
// Check: resource.TestCheckResourceAttrSet("example_resource.test", "id"),
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
//}
|
||||
|
||||
type resData struct {
|
||||
ServiceAccountFilePath string
|
||||
ProjectID string
|
||||
Region string
|
||||
Name string
|
||||
Flavor string
|
||||
BackupSchedule string
|
||||
RetentionDays uint32
|
||||
}
|
||||
|
||||
func getExample() resData {
|
||||
return resData{
|
||||
Region: testutil.Region,
|
||||
ServiceAccountFilePath: testutil.ServiceAccountFile,
|
||||
ProjectID: testutil.ProjectId,
|
||||
Name: acctest.RandomWithPrefix("tf-acc"),
|
||||
Flavor: "2.4",
|
||||
BackupSchedule: "0 0 * * *",
|
||||
RetentionDays: 33,
|
||||
}
|
||||
}
|
||||
|
||||
func TestAccResourceExample_basic(t *testing.T) {
|
||||
exData := getExample()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: testAccResourceNoEncryptionExampleConfig(exData),
|
||||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("example_resource.test", "name", exData.Name),
|
||||
resource.TestCheckResourceAttrSet("example_resource.test", "id"),
|
||||
),
|
||||
},
|
||||
//// Create and verify
|
||||
//{
|
||||
// Config: testAccResourceNoEncryptionExampleConfig(exData),
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// resource.TestCheckResourceAttr("example_resource.test", "name", exData.Name),
|
||||
// ),
|
||||
//},
|
||||
//// Update and verify
|
||||
//{
|
||||
// Config: testAccResourceNoEncryptionExampleConfig(exData),
|
||||
// Check: resource.ComposeTestCheckFunc(
|
||||
// resource.TestCheckResourceAttr("example_resource.test", "name", exData.Name),
|
||||
// ),
|
||||
//},
|
||||
// Import test
|
||||
{
|
||||
ResourceName: "example_resource.test",
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccResourceNoEncryptionExampleConfig(data resData) string {
|
||||
return fmt.Sprintf(`
|
||||
|
||||
%[1]s
|
||||
|
||||
resource "stackitprivatepreview_postgresflexalpha_instance" "test" {
|
||||
project_id = %[2]q
|
||||
name = %[3]q
|
||||
backup_schedule = %[4]q
|
||||
retention_days = %[5]d
|
||||
flavor_id = %[6]q
|
||||
replicas = 1
|
||||
storage = {
|
||||
performance_class = "premium-perf2-stackit"
|
||||
size = 10
|
||||
}
|
||||
network = {
|
||||
acl = ["0.0.0.0/0"]
|
||||
access_scope = "PUBLIC"
|
||||
}
|
||||
version = 17
|
||||
}
|
||||
|
||||
`,
|
||||
testutil.PostgresFlexProviderConfig(data.ServiceAccountFilePath),
|
||||
data.ProjectID,
|
||||
data.Name,
|
||||
data.BackupSchedule,
|
||||
data.RetentionDays,
|
||||
data.Flavor,
|
||||
data.Name,
|
||||
)
|
||||
}
|
||||
|
||||
func testAccResourceEncryptionExampleConfig(data resData) string {
|
||||
return fmt.Sprintf(`
|
||||
|
||||
%[1]s
|
||||
|
||||
resource "stackitprivatepreview_postgresflexalpha_instance" "test" {
|
||||
project_id = %[2]q
|
||||
name = %[3]q
|
||||
backup_schedule = "0 0 * * *"
|
||||
retention_days = 45
|
||||
flavor_id = "2.1"
|
||||
replicas = 1
|
||||
storage = {
|
||||
performance_class = "premium-perf2-stackit"
|
||||
size = 10
|
||||
}
|
||||
encryption = {
|
||||
kek_key_id = "key01"
|
||||
kek_key_ring_id = "key_ring_01"
|
||||
kek_key_version = 1
|
||||
service_account = "service@account.email"
|
||||
}
|
||||
network = {
|
||||
acl = ["0.0.0.0/0"]
|
||||
access_scope = "PUBLIC"
|
||||
}
|
||||
version = 14
|
||||
}
|
||||
|
||||
`,
|
||||
testutil.PostgresFlexProviderConfig(data.ServiceAccountFilePath),
|
||||
data.ProjectID,
|
||||
data.Name,
|
||||
)
|
||||
}
|
||||
|
||||
func testCheckResourceExists(resourceName string) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
rs, ok := s.RootModule().Resources[resourceName]
|
||||
if !ok {
|
||||
return fmt.Errorf("resource not found: %s", resourceName)
|
||||
}
|
||||
|
||||
if rs.Primary.ID == "" {
|
||||
return fmt.Errorf("resource ID not set")
|
||||
}
|
||||
|
||||
// Verify resource exists in the API
|
||||
//client := testAccProvider.Meta().(*APIClient)
|
||||
//_, err := client.GetResource(rs.Primary.ID)
|
||||
//if err != nil {
|
||||
// return fmt.Errorf("error fetching resource: %w", err)
|
||||
//}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func setupMockServer() *httptest.Server {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.HandleFunc("/api/resources", func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodPost:
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
json.NewEncoder(w).Encode(map[string]string{
|
||||
"id": "mock-id-123",
|
||||
"name": "test-resource",
|
||||
})
|
||||
case http.MethodGet:
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode([]map[string]string{})
|
||||
}
|
||||
})
|
||||
|
||||
return httptest.NewServer(mux)
|
||||
}
|
||||
|
||||
func TestUnitResourceCreate(t *testing.T) {
|
||||
server := setupMockServer()
|
||||
defer server.Close()
|
||||
|
||||
// Configure provider to use mock server URL
|
||||
os.Setenv("API_ENDPOINT", server.URL)
|
||||
|
||||
// Run unit tests against mock
|
||||
}
|
||||
|
||||
// type postgresFlexClientMocked struct {
|
||||
// returnError bool
|
||||
// getFlavorsResp *postgresflex.GetFlavorsResponse
|
||||
|
|
@ -20,21 +241,40 @@ import (
|
|||
// return c.getFlavorsResp, nil
|
||||
// }
|
||||
|
||||
func TestNewInstanceResource(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want resource.Resource
|
||||
}{
|
||||
{
|
||||
name: "create empty instance resource",
|
||||
want: &instanceResource{},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := NewInstanceResource(); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewInstanceResource() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
//func TestNewInstanceResource(t *testing.T) {
|
||||
// exData := resData{
|
||||
// Region: "eu01",
|
||||
// ServiceAccountFilePath: sa_file,
|
||||
// ProjectID: project_id,
|
||||
// Name: "testRes",
|
||||
// }
|
||||
// resource.Test(t, resource.TestCase{
|
||||
// ProtoV6ProviderFactories: testutil.TestAccProtoV6ProviderFactories,
|
||||
// Steps: []resource.TestStep{
|
||||
// {
|
||||
// Config: testAccResourceEncryptionExampleConfig(exData),
|
||||
// Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// resource.TestCheckResourceAttr("example_resource.test", "name", exData.Name),
|
||||
// resource.TestCheckResourceAttrSet("example_resource.test", "id"),
|
||||
// ),
|
||||
// },
|
||||
// },
|
||||
// })
|
||||
//
|
||||
// //tests := []struct {
|
||||
// // name string
|
||||
// // want resource.Resource
|
||||
// //}{
|
||||
// // {
|
||||
// // name: "create empty instance resource",
|
||||
// // want: &instanceResource{},
|
||||
// // },
|
||||
// //}
|
||||
// //for _, tt := range tests {
|
||||
// // t.Run(tt.name, func(t *testing.T) {
|
||||
// // if got := NewInstanceResource(); !reflect.DeepEqual(got, tt.want) {
|
||||
// // t.Errorf("NewInstanceResource() = %v, want %v", got, tt.want)
|
||||
// // }
|
||||
// // })
|
||||
// //}
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@ import (
|
|||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
|
||||
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
|
||||
"github.com/hashicorp/terraform-plugin-testing/terraform"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
||||
|
|
@ -26,13 +29,31 @@ var (
|
|||
resourceSecurityGroupMinConfig string //nolint:unused // needs implementation
|
||||
)
|
||||
|
||||
func setup() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
slog.Info("could not find .env file - not loading .env")
|
||||
return
|
||||
}
|
||||
slog.Info("loaded .env file")
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
setup()
|
||||
code := m.Run()
|
||||
// shutdown()
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
// Instance resource data
|
||||
var instanceResource = map[string]string{
|
||||
"project_id": testutil.ProjectId,
|
||||
"region": "eu01",
|
||||
"name": fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(7, acctest.CharSetAlphaNum)),
|
||||
"acl": "192.168.0.0/16",
|
||||
"backup_schedule": "00 16 * * *",
|
||||
"backup_schedule_updated": "00 12 * * *",
|
||||
"retention_days": "33",
|
||||
"flavor_cpu": "2",
|
||||
"flavor_ram": "4",
|
||||
"flavor_description": "Small, Compute optimized",
|
||||
|
|
@ -41,75 +62,96 @@ var instanceResource = map[string]string{
|
|||
"storage_size": "5",
|
||||
"version": "14",
|
||||
"flavor_id": "2.4",
|
||||
"kek_key_id": "UUID1",
|
||||
"kek_key_ring_id": "UUID2",
|
||||
"kek_key_version": "1",
|
||||
"service_account": "service@account.com",
|
||||
"access_scope": "SNA",
|
||||
}
|
||||
|
||||
// User resource data
|
||||
var userResource = map[string]string{
|
||||
"username": fmt.Sprintf("tfaccuser%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlpha)),
|
||||
"role": "createdb",
|
||||
"project_id": instanceResource["project_id"],
|
||||
"project_id": testutil.ProjectId,
|
||||
}
|
||||
|
||||
// Database resource data
|
||||
var databaseResource = map[string]string{
|
||||
"name": fmt.Sprintf("tfaccdb%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlphaNum)),
|
||||
"name": fmt.Sprintf("tfaccdb%s", acctest.RandStringFromCharSet(4, acctest.CharSetAlphaNum)),
|
||||
"project_id": testutil.ProjectId,
|
||||
}
|
||||
|
||||
func configResources(backupSchedule string, region *string) string {
|
||||
var regionConfig string
|
||||
if region != nil {
|
||||
regionConfig = fmt.Sprintf(`region = %q`, *region)
|
||||
}
|
||||
func configResources(backupSchedule string, _ *string) string {
|
||||
return fmt.Sprintf(
|
||||
`
|
||||
%s
|
||||
|
||||
resource "stackit_postgresflex_instance" "instance" {
|
||||
project_id = "%s"
|
||||
name = "%s"
|
||||
acl = ["%s"]
|
||||
backup_schedule = "%s"
|
||||
flavor = {
|
||||
cpu = %s
|
||||
ram = %s
|
||||
}
|
||||
replicas = %s
|
||||
storage = {
|
||||
class = "%s"
|
||||
size = %s
|
||||
}
|
||||
version = "%s"
|
||||
%s
|
||||
|
||||
resource "stackitprivatepreview_postgresflexalpha_instance" "instance" {
|
||||
project_id = "%s"
|
||||
region = "%s"
|
||||
name = "%s"
|
||||
backup_schedule = "%s"
|
||||
retention_days = %s
|
||||
flavor_id = %s
|
||||
replicas = %s
|
||||
storage = {
|
||||
performance_class = "%s"
|
||||
size = %s
|
||||
}
|
||||
encryption = {
|
||||
kek_key_id = "%s"
|
||||
kek_key_ring_id = "%s"
|
||||
kek_key_version = "%s"
|
||||
service_account = "%s"
|
||||
}
|
||||
network = {
|
||||
acl = ["%s"]
|
||||
access_scope = "%s"
|
||||
}
|
||||
version = %s
|
||||
}
|
||||
|
||||
resource "stackit_postgresflex_user" "user" {
|
||||
project_id = stackit_postgresflex_instance.instance.project_id
|
||||
instance_id = stackit_postgresflex_instance.instance.instance_id
|
||||
resource "stackitprivatepreview_postgresflexalpha_user" "user" {
|
||||
project_id = "%s"
|
||||
instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
|
||||
username = "%s"
|
||||
roles = ["%s"]
|
||||
}
|
||||
|
||||
resource "stackit_postgresflex_database" "database" {
|
||||
project_id = stackit_postgresflex_instance.instance.project_id
|
||||
instance_id = stackit_postgresflex_instance.instance.instance_id
|
||||
resource "stackitprivatepreview_postgresflexalpha_database" "database" {
|
||||
project_id = "%s"
|
||||
instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
|
||||
name = "%s"
|
||||
owner = stackit_postgresflex_user.user.username
|
||||
owner = stackitprivatepreview_postgresflexalpha_user.user.username
|
||||
}
|
||||
`,
|
||||
testutil.PostgresFlexProviderConfig(),
|
||||
testutil.PostgresFlexProviderConfig(
|
||||
utils.GetEnvOrDefault("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_FILE", "~/service-account.json"),
|
||||
),
|
||||
instanceResource["project_id"],
|
||||
instanceResource["region"],
|
||||
instanceResource["name"],
|
||||
instanceResource["acl"],
|
||||
backupSchedule,
|
||||
instanceResource["flavor_cpu"],
|
||||
instanceResource["flavor_ram"],
|
||||
instanceResource["retention_days"],
|
||||
instanceResource["flavor_id"],
|
||||
instanceResource["replicas"],
|
||||
instanceResource["storage_class"],
|
||||
instanceResource["storage_size"],
|
||||
instanceResource["kek_key_id"],
|
||||
instanceResource["kek_key_ring_id"],
|
||||
instanceResource["kek_key_version"],
|
||||
instanceResource["service_account"],
|
||||
instanceResource["acl"],
|
||||
instanceResource["access_scope"],
|
||||
instanceResource["version"],
|
||||
regionConfig,
|
||||
|
||||
userResource["project_id"],
|
||||
userResource["username"],
|
||||
userResource["role"],
|
||||
|
||||
databaseResource["project_id"],
|
||||
databaseResource["name"],
|
||||
)
|
||||
}
|
||||
|
|
@ -126,107 +168,107 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
|
|||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Instance
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"project_id",
|
||||
instanceResource["project_id"],
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"name",
|
||||
instanceResource["name"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"acl.#",
|
||||
"1",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"acl.0",
|
||||
instanceResource["acl"],
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.id",
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.description",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"backup_schedule",
|
||||
instanceResource["backup_schedule"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.cpu",
|
||||
instanceResource["flavor_cpu"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.ram",
|
||||
instanceResource["flavor_ram"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"replicas",
|
||||
instanceResource["replicas"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"storage.class",
|
||||
instanceResource["storage_class"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"storage.size",
|
||||
instanceResource["storage_size"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"version",
|
||||
instanceResource["version"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"region",
|
||||
testutil.Region,
|
||||
),
|
||||
|
||||
// User
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"stackit_postgresflex_user.user", "project_id",
|
||||
"stackit_postgresflex_instance.instance", "project_id",
|
||||
"stackitprivatepreview_postgresflexalpha_user.user", "project_id",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance", "project_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"stackit_postgresflex_user.user", "instance_id",
|
||||
"stackit_postgresflex_instance.instance", "instance_id",
|
||||
"stackitprivatepreview_postgresflexalpha_user.user", "instance_id",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance", "instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrSet("stackit_postgresflex_user.user", "user_id"),
|
||||
resource.TestCheckResourceAttrSet("stackit_postgresflex_user.user", "password"),
|
||||
resource.TestCheckResourceAttrSet("stackitprivatepreview_postgresflexalpha_user.user", "user_id"),
|
||||
resource.TestCheckResourceAttrSet("stackitprivatepreview_postgresflexalpha_user.user", "password"),
|
||||
|
||||
// Database
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"stackit_postgresflex_database.database", "project_id",
|
||||
"stackit_postgresflex_instance.instance", "project_id",
|
||||
"stackitprivatepreview_postgresflexalpha_database.database", "project_id",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance", "project_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"stackit_postgresflex_database.database", "instance_id",
|
||||
"stackit_postgresflex_instance.instance", "instance_id",
|
||||
"stackitprivatepreview_postgresflexalpha_database.database", "instance_id",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance", "instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_database.database",
|
||||
"stackitprivatepreview_postgresflexalpha_database.database",
|
||||
"name",
|
||||
databaseResource["name"],
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"stackit_postgresflex_database.database", "owner",
|
||||
"stackit_postgresflex_user.user", "username",
|
||||
"stackitprivatepreview_postgresflexalpha_database.database", "owner",
|
||||
"stackitprivatepreview_postgresflexalpha_user.user", "username",
|
||||
),
|
||||
),
|
||||
},
|
||||
|
|
@ -236,21 +278,21 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
|
|||
`
|
||||
%s
|
||||
|
||||
data "stackit_postgresflex_instance" "instance" {
|
||||
project_id = stackit_postgresflex_instance.instance.project_id
|
||||
instance_id = stackit_postgresflex_instance.instance.instance_id
|
||||
data "stackitprivatepreview_postgresflexalpha_instance" "instance" {
|
||||
project_id = stackitprivatepreview_postgresflexalpha_instance.instance.project_id
|
||||
instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
|
||||
}
|
||||
|
||||
data "stackit_postgresflex_user" "user" {
|
||||
project_id = stackit_postgresflex_instance.instance.project_id
|
||||
instance_id = stackit_postgresflex_instance.instance.instance_id
|
||||
user_id = stackit_postgresflex_user.user.user_id
|
||||
data "stackitprivatepreview_postgresflexalpha_user" "user" {
|
||||
project_id = stackitprivatepreview_postgresflexalpha_instance.instance.project_id
|
||||
instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
|
||||
user_id = stackitprivatepreview_postgresflexalpha_user.user.user_id
|
||||
}
|
||||
|
||||
data "stackit_postgresflex_database" "database" {
|
||||
project_id = stackit_postgresflex_instance.instance.project_id
|
||||
instance_id = stackit_postgresflex_instance.instance.instance_id
|
||||
database_id = stackit_postgresflex_database.database.database_id
|
||||
data "stackitprivatepreview_postgresflexalpha_database" "database" {
|
||||
project_id = stackitprivatepreview_postgresflexalpha_instance.instance.project_id
|
||||
instance_id = stackitprivatepreview_postgresflexalpha_instance.instance.instance_id
|
||||
database_id = stackitprivatepreview_postgresflexalpha_database.database.database_id
|
||||
}
|
||||
`,
|
||||
configResources(instanceResource["backup_schedule"], nil),
|
||||
|
|
@ -258,135 +300,135 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
|
|||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Instance data
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"project_id",
|
||||
instanceResource["project_id"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"name",
|
||||
instanceResource["name"],
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"data.stackit_postgresflex_instance.instance", "project_id",
|
||||
"stackit_postgresflex_instance.instance", "project_id",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance", "project_id",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance", "project_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"data.stackit_postgresflex_instance.instance", "instance_id",
|
||||
"stackit_postgresflex_instance.instance", "instance_id",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance", "instance_id",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance", "instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"data.stackit_postgresflex_user.user", "instance_id",
|
||||
"stackit_postgresflex_user.user", "instance_id",
|
||||
"data.stackitprivatepreview_postgresflexalpha_user.user", "instance_id",
|
||||
"stackitprivatepreview_postgresflexalpha_user.user", "instance_id",
|
||||
),
|
||||
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"acl.#",
|
||||
"1",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"acl.0",
|
||||
instanceResource["acl"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"backup_schedule",
|
||||
instanceResource["backup_schedule"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.id",
|
||||
instanceResource["flavor_id"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.description",
|
||||
instanceResource["flavor_description"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.cpu",
|
||||
instanceResource["flavor_cpu"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.ram",
|
||||
instanceResource["flavor_ram"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_instance.instance",
|
||||
"data.stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"replicas",
|
||||
instanceResource["replicas"],
|
||||
),
|
||||
|
||||
// User data
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_user.user",
|
||||
"data.stackitprivatepreview_postgresflexalpha_user.user",
|
||||
"project_id",
|
||||
userResource["project_id"],
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"data.stackit_postgresflex_user.user",
|
||||
"data.stackitprivatepreview_postgresflexalpha_user.user",
|
||||
"user_id",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_user.user",
|
||||
"data.stackitprivatepreview_postgresflexalpha_user.user",
|
||||
"username",
|
||||
userResource["username"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_user.user",
|
||||
"data.stackitprivatepreview_postgresflexalpha_user.user",
|
||||
"roles.#",
|
||||
"1",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_user.user",
|
||||
"data.stackitprivatepreview_postgresflexalpha_user.user",
|
||||
"roles.0",
|
||||
userResource["role"],
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"data.stackit_postgresflex_user.user",
|
||||
"data.stackitprivatepreview_postgresflexalpha_user.user",
|
||||
"host",
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"data.stackit_postgresflex_user.user",
|
||||
"data.stackitprivatepreview_postgresflexalpha_user.user",
|
||||
"port",
|
||||
),
|
||||
|
||||
// Database data
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_database.database",
|
||||
"data.stackitprivatepreview_postgresflexalpha_database.database",
|
||||
"project_id",
|
||||
instanceResource["project_id"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"data.stackit_postgresflex_database.database",
|
||||
"data.stackitprivatepreview_postgresflexalpha_database.database",
|
||||
"name",
|
||||
databaseResource["name"],
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"data.stackit_postgresflex_database.database",
|
||||
"data.stackitprivatepreview_postgresflexalpha_database.database",
|
||||
"instance_id",
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttrPair(
|
||||
"data.stackit_postgresflex_database.database",
|
||||
"data.stackitprivatepreview_postgresflexalpha_database.database",
|
||||
"owner",
|
||||
"data.stackit_postgresflex_user.user",
|
||||
"data.stackitprivatepreview_postgresflexalpha_user.user",
|
||||
"username",
|
||||
),
|
||||
),
|
||||
},
|
||||
// Import
|
||||
{
|
||||
ResourceName: "stackit_postgresflex_instance.instance",
|
||||
ResourceName: "stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
ImportStateIdFunc: func(s *terraform.State) (string, error) {
|
||||
r, ok := s.RootModule().Resources["stackit_postgresflex_instance.instance"]
|
||||
r, ok := s.RootModule().Resources["stackitprivatepreview_postgresflexalpha_instance.instance"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find resource stackit_postgresflex_instance.instance")
|
||||
return "", fmt.Errorf("couldn't find resource stackitprivatepreview_postgresflexalpha_instance.instance")
|
||||
}
|
||||
instanceId, ok := r.Primary.Attributes["instance_id"]
|
||||
if !ok {
|
||||
|
|
@ -400,11 +442,11 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
|
|||
ImportStateVerifyIgnore: []string{"password"},
|
||||
},
|
||||
{
|
||||
ResourceName: "stackit_postgresflex_user.user",
|
||||
ResourceName: "stackitprivatepreview_postgresflexalpha_user.user",
|
||||
ImportStateIdFunc: func(s *terraform.State) (string, error) {
|
||||
r, ok := s.RootModule().Resources["stackit_postgresflex_user.user"]
|
||||
r, ok := s.RootModule().Resources["stackitprivatepreview_postgresflexalpha_user.user"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find resource stackit_postgresflex_user.user")
|
||||
return "", fmt.Errorf("couldn't find resource stackitprivatepreview_postgresflexalpha_user.user")
|
||||
}
|
||||
instanceId, ok := r.Primary.Attributes["instance_id"]
|
||||
if !ok {
|
||||
|
|
@ -422,11 +464,11 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
|
|||
ImportStateVerifyIgnore: []string{"password", "uri"},
|
||||
},
|
||||
{
|
||||
ResourceName: "stackit_postgresflex_database.database",
|
||||
ResourceName: "stackitprivatepreview_postgresflexalpha_database.database",
|
||||
ImportStateIdFunc: func(s *terraform.State) (string, error) {
|
||||
r, ok := s.RootModule().Resources["stackit_postgresflex_database.database"]
|
||||
r, ok := s.RootModule().Resources["stackitprivatepreview_postgresflexalpha_database.database"]
|
||||
if !ok {
|
||||
return "", fmt.Errorf("couldn't find resource stackit_postgresflex_database.database")
|
||||
return "", fmt.Errorf("couldn't find resource stackitprivatepreview_postgresflexalpha_database.database")
|
||||
}
|
||||
instanceId, ok := r.Primary.Attributes["instance_id"]
|
||||
if !ok {
|
||||
|
|
@ -454,69 +496,69 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
|
|||
Check: resource.ComposeAggregateTestCheckFunc(
|
||||
// Instance data
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"project_id",
|
||||
instanceResource["project_id"],
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"instance_id",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"name",
|
||||
instanceResource["name"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"acl.#",
|
||||
"1",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"acl.0",
|
||||
instanceResource["acl"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"backup_schedule",
|
||||
instanceResource["backup_schedule_updated"],
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.id",
|
||||
),
|
||||
resource.TestCheckResourceAttrSet(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.description",
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.cpu",
|
||||
instanceResource["flavor_cpu"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"flavor.ram",
|
||||
instanceResource["flavor_ram"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"replicas",
|
||||
instanceResource["replicas"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"storage.class",
|
||||
instanceResource["storage_class"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"storage.size",
|
||||
instanceResource["storage_size"],
|
||||
),
|
||||
resource.TestCheckResourceAttr(
|
||||
"stackit_postgresflex_instance.instance",
|
||||
"stackitprivatepreview_postgresflexalpha_instance.instance",
|
||||
"version",
|
||||
instanceResource["version"],
|
||||
),
|
||||
|
|
@ -545,7 +587,7 @@ func testAccCheckPostgresFlexDestroy(s *terraform.State) error {
|
|||
|
||||
instancesToDestroy := []string{}
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "stackit_postgresflex_instance" {
|
||||
if rs.Type != "stackitprivatepreview_postgresflexalpha_instance" {
|
||||
continue
|
||||
}
|
||||
// instance terraform ID: = "[project_id],[region],[instance_id]"
|
||||
|
|
|
|||
|
|
@ -1 +1,24 @@
|
|||
|
||||
resource "stackitprivatepreview_postgresflexalpha_instance" "msh-instance-only" {
|
||||
project_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
name = "example-instance"
|
||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
||||
backup_schedule = "0 0 * * *"
|
||||
retention_days = 30
|
||||
flavor_id = "flavor.id"
|
||||
replicas = 1
|
||||
storage = {
|
||||
performance_class = "premium-perf2-stackit"
|
||||
size = 10
|
||||
}
|
||||
encryption = {
|
||||
kek_key_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
kek_key_ring_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
||||
kek_key_version = 1
|
||||
service_account = "service@account.email"
|
||||
}
|
||||
network = {
|
||||
acl = ["XXX.XXX.XXX.X/XX", "XX.XXX.XX.X/XX"]
|
||||
access_scope = "PUBLIC"
|
||||
}
|
||||
version = 17
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,15 +146,11 @@ func (d *databaseDataSource) Read(ctx context.Context, req datasource.ReadReques
|
|||
data.Id = types.Int64Value(dbId)
|
||||
data.TfId = utils.BuildInternalTerraformId(projectId, region, instanceId, databaseName)
|
||||
data.Owner = types.StringValue(databaseResp.GetOwner())
|
||||
|
||||
// TODO: fill remaining fields
|
||||
// data.CollationName = types.Sometype(apiResponse.GetCollationName())
|
||||
// data.CompatibilityLevel = types.Sometype(apiResponse.GetCompatibilityLevel())
|
||||
// data.DatabaseName = types.Sometype(apiResponse.GetDatabaseName())
|
||||
// data.Id = types.Sometype(apiResponse.GetId())
|
||||
// data.InstanceId = types.Sometype(apiResponse.GetInstanceId())
|
||||
data.CollationName = types.StringValue(databaseResp.GetCollationName())
|
||||
data.CompatibilityLevel = types.Int64Value(databaseResp.GetCompatibilityLevel())
|
||||
data.DatabaseName = types.StringValue(databaseResp.GetName())
|
||||
// data.InstanceId = types.StringValue(databaseResp.GetInstanceId())
|
||||
// data.Name = types.Sometype(apiResponse.GetName())
|
||||
// data.Owner = types.Sometype(apiResponse.GetOwner())
|
||||
// data.ProjectId = types.Sometype(apiResponse.GetProjectId())
|
||||
// data.Region = types.Sometype(apiResponse.GetRegion())
|
||||
|
||||
|
|
|
|||
|
|
@ -1,118 +0,0 @@
|
|||
package sqlserverflexbeta
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
sqlserverflexbetaPkg "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
|
||||
sqlserverflexbetaUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/utils"
|
||||
|
||||
sqlserverflexbetaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/flavors/datasources_gen"
|
||||
)
|
||||
|
||||
var _ datasource.DataSource = (*flavorsDataSource)(nil)
|
||||
|
||||
const errorPrefix = "[Sqlserverflexbeta - Flavors]"
|
||||
|
||||
func NewFlavorsDataSource() datasource.DataSource {
|
||||
return &flavorsDataSource{}
|
||||
}
|
||||
|
||||
type flavorsDataSource struct {
|
||||
client *sqlserverflexbetaPkg.APIClient
|
||||
providerData core.ProviderData
|
||||
}
|
||||
|
||||
func (d *flavorsDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
|
||||
resp.TypeName = req.ProviderTypeName + "_sqlserverflexbeta_flavors"
|
||||
}
|
||||
|
||||
func (d *flavorsDataSource) Schema(ctx context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
|
||||
resp.Schema = sqlserverflexbetaGen.FlavorsDataSourceSchema(ctx)
|
||||
}
|
||||
|
||||
// Configure adds the provider configured client to the data source.
|
||||
func (d *flavorsDataSource) Configure(
|
||||
ctx context.Context,
|
||||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
var ok bool
|
||||
d.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
apiClient := sqlserverflexbetaUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
d.client = apiClient
|
||||
tflog.Info(ctx, fmt.Sprintf("%s client configured", errorPrefix))
|
||||
}
|
||||
|
||||
func (d *flavorsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
|
||||
var data sqlserverflexbetaGen.FlavorsModel
|
||||
|
||||
// Read Terraform configuration data into the model
|
||||
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
|
||||
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.InitProviderContext(ctx)
|
||||
|
||||
projectId := data.ProjectId.ValueString()
|
||||
region := d.providerData.GetRegionWithOverride(data.Region)
|
||||
flavorsId := data.FlavorsId.ValueString()
|
||||
|
||||
ctx = tflog.SetField(ctx, "project_id", projectId)
|
||||
ctx = tflog.SetField(ctx, "region", region)
|
||||
ctx = tflog.SetField(ctx, "flavors_id", flavorsId)
|
||||
|
||||
flavorsResp, err := d.client.GetFlavorsRequest(ctx, projectId, region, flavorsId).Execute()
|
||||
if err != nil {
|
||||
utils.LogError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
err,
|
||||
"Reading flavors",
|
||||
fmt.Sprintf("flavors with ID %q does not exist in project %q.", flavorsId, projectId),
|
||||
map[int]string{
|
||||
http.StatusForbidden: fmt.Sprintf("Project with ID %q not found or forbidden access", projectId),
|
||||
},
|
||||
)
|
||||
resp.State.RemoveResource(ctx)
|
||||
return
|
||||
}
|
||||
|
||||
ctx = core.LogResponse(ctx)
|
||||
|
||||
// Todo: Read API call logic
|
||||
|
||||
// Example data value setting
|
||||
// data.Id = types.StringValue("example-id")
|
||||
|
||||
err = mapResponseToModel(ctx, flavorsResp, &data, resp.Diagnostics)
|
||||
if err != nil {
|
||||
core.LogAndAddError(
|
||||
ctx,
|
||||
&resp.Diagnostics,
|
||||
fmt.Sprintf("%s Read", errorPrefix),
|
||||
fmt.Sprintf("Processing API payload: %v", err),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// Save data into Terraform state
|
||||
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -7,13 +7,12 @@ import (
|
|||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/conversion"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
||||
|
||||
sqlserverflexbetaPkg "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
|
||||
sqlserverflexbetaUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/utils"
|
||||
// sqlserverflexbetaUtils "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/utils"
|
||||
|
||||
sqlserverflexbetaGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/user/datasources_gen"
|
||||
)
|
||||
|
|
@ -45,17 +44,17 @@ func (d *userDataSource) Configure(
|
|||
req datasource.ConfigureRequest,
|
||||
resp *datasource.ConfigureResponse,
|
||||
) {
|
||||
var ok bool
|
||||
d.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
apiClient := sqlserverflexbetaUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
d.client = apiClient
|
||||
//var ok bool
|
||||
//d.providerData, ok = conversion.ParseProviderData(ctx, req.ProviderData, &resp.Diagnostics)
|
||||
//if !ok {
|
||||
// return
|
||||
//}
|
||||
//
|
||||
//apiClient := sqlserverflexbetaUtils.ConfigureClient(ctx, &d.providerData, &resp.Diagnostics)
|
||||
//if resp.Diagnostics.HasError() {
|
||||
// return
|
||||
//}
|
||||
//d.client = apiClient
|
||||
tflog.Info(ctx, fmt.Sprintf("%s client configured", errorPrefix))
|
||||
}
|
||||
|
||||
|
|
|
|||
11
stackit/internal/testutil/assert.go
Normal file
11
stackit/internal/testutil/assert.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package testutil
|
||||
|
||||
import "testing"
|
||||
|
||||
func Equal[V comparable](t *testing.T, got, expected V) {
|
||||
t.Helper()
|
||||
|
||||
if expected != got {
|
||||
t.Errorf("assert equal failed:\ngot: %v \nexpected: %v", got, expected)
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
package testutil
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -20,7 +19,8 @@ import (
|
|||
|
||||
const (
|
||||
// Default location of credentials JSON
|
||||
credentialsFilePath = ".stackit/credentials.json" //nolint:gosec // linter false positive
|
||||
// credentialsFilePath = ".stackit/credentials.json" //nolint:gosec // linter false positive
|
||||
serviceAccountFilePath = ".stackit/service_account.json"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -29,7 +29,7 @@ var (
|
|||
// CLI command executed to create a provider server to which the CLI can
|
||||
// reattach.
|
||||
TestAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
|
||||
"stackit": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||
"stackitprivatepreview": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||
}
|
||||
|
||||
// TestEphemeralAccProtoV6ProviderFactories is used to instantiate a provider during
|
||||
|
|
@ -40,8 +40,8 @@ var (
|
|||
// See the Terraform acceptance test documentation on ephemeral resources for more information:
|
||||
// https://developer.hashicorp.com/terraform/plugin/testing/acceptance-tests/ephemeral-resources
|
||||
TestEphemeralAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
|
||||
"stackit": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||
"echo": echoprovider.NewProviderServer(),
|
||||
"stackitprivatepreview": providerserver.NewProtocol6WithError(stackit.New("test-version")()),
|
||||
"echo": echoprovider.NewProviderServer(),
|
||||
}
|
||||
|
||||
// E2ETestsEnabled checks if end-to-end tests should be run.
|
||||
|
|
@ -52,6 +52,8 @@ var (
|
|||
// ProjectId is the id of project used for tests
|
||||
ProjectId = os.Getenv("TF_ACC_PROJECT_ID")
|
||||
Region = os.Getenv("TF_ACC_REGION")
|
||||
// ServiceAccountFile is the json file of the service account
|
||||
ServiceAccountFile = os.Getenv("TF_ACC_SERVICE_ACCOUNT_FILE")
|
||||
// ServerId is the id of a server used for some tests
|
||||
ServerId = getenv("TF_ACC_SERVER_ID", "")
|
||||
// TestProjectParentContainerID is the container id of the parent resource under which projects are created as part of the resource-manager acceptance tests
|
||||
|
|
@ -97,26 +99,27 @@ var (
|
|||
|
||||
func ObservabilityProviderConfig() string {
|
||||
if ObservabilityCustomEndpoint == "" {
|
||||
return `provider "stackit" {
|
||||
return `provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
observability_custom_endpoint = "%s"
|
||||
}`,
|
||||
ObservabilityCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
func CdnProviderConfig() string {
|
||||
if CdnCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
cdn_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -126,10 +129,10 @@ func CdnProviderConfig() string {
|
|||
|
||||
func DnsProviderConfig() string {
|
||||
if DnsCustomEndpoint == "" {
|
||||
return `provider "stackit" {}`
|
||||
return `provider "stackitprivatepreview" {}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
dns_custom_endpoint = "%s"
|
||||
}`,
|
||||
DnsCustomEndpoint,
|
||||
|
|
@ -139,12 +142,12 @@ func DnsProviderConfig() string {
|
|||
func IaaSProviderConfig() string {
|
||||
if IaaSCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
iaas_custom_endpoint = "%s"
|
||||
}`,
|
||||
IaaSCustomEndpoint,
|
||||
|
|
@ -154,13 +157,13 @@ func IaaSProviderConfig() string {
|
|||
func IaaSProviderConfigWithBetaResourcesEnabled() string {
|
||||
if IaaSCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
enable_beta_resources = true
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
enable_beta_resources = true
|
||||
iaas_custom_endpoint = "%s"
|
||||
}`,
|
||||
|
|
@ -171,13 +174,13 @@ func IaaSProviderConfigWithBetaResourcesEnabled() string {
|
|||
func IaaSProviderConfigWithExperiments() string {
|
||||
if IaaSCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
experiments = [ "routing-tables", "network" ]
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
iaas_custom_endpoint = "%s"
|
||||
experiments = [ "routing-tables", "network" ]
|
||||
}`,
|
||||
|
|
@ -188,12 +191,12 @@ func IaaSProviderConfigWithExperiments() string {
|
|||
func KMSProviderConfig() string {
|
||||
if KMSCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
kms_custom_endpoint = "%s"
|
||||
}`,
|
||||
KMSCustomEndpoint,
|
||||
|
|
@ -203,12 +206,12 @@ func KMSProviderConfig() string {
|
|||
func LoadBalancerProviderConfig() string {
|
||||
if LoadBalancerCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
loadbalancer_custom_endpoint = "%s"
|
||||
}`,
|
||||
LoadBalancerCustomEndpoint,
|
||||
|
|
@ -218,12 +221,12 @@ func LoadBalancerProviderConfig() string {
|
|||
func LogMeProviderConfig() string {
|
||||
if LogMeCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
logme_custom_endpoint = "%s"
|
||||
}`,
|
||||
LogMeCustomEndpoint,
|
||||
|
|
@ -233,12 +236,12 @@ func LogMeProviderConfig() string {
|
|||
func MariaDBProviderConfig() string {
|
||||
if MariaDBCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
mariadb_custom_endpoint = "%s"
|
||||
}`,
|
||||
MariaDBCustomEndpoint,
|
||||
|
|
@ -248,13 +251,13 @@ func MariaDBProviderConfig() string {
|
|||
func ModelServingProviderConfig() string {
|
||||
if ModelServingCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}
|
||||
`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
modelserving_custom_endpoint = "%s"
|
||||
}`,
|
||||
ModelServingCustomEndpoint,
|
||||
|
|
@ -264,12 +267,12 @@ func ModelServingProviderConfig() string {
|
|||
func MongoDBFlexProviderConfig() string {
|
||||
if MongoDBFlexCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
mongodbflex_custom_endpoint = "%s"
|
||||
}`,
|
||||
MongoDBFlexCustomEndpoint,
|
||||
|
|
@ -279,12 +282,12 @@ func MongoDBFlexProviderConfig() string {
|
|||
func ObjectStorageProviderConfig() string {
|
||||
if ObjectStorageCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
objectstorage_custom_endpoint = "%s"
|
||||
}`,
|
||||
ObjectStorageCustomEndpoint,
|
||||
|
|
@ -294,29 +297,32 @@ func ObjectStorageProviderConfig() string {
|
|||
func OpenSearchProviderConfig() string {
|
||||
if OpenSearchCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
opensearch_custom_endpoint = "%s"
|
||||
}`,
|
||||
OpenSearchCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
func PostgresFlexProviderConfig() string {
|
||||
func PostgresFlexProviderConfig(saFile string) string {
|
||||
if PostgresFlexCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
return fmt.Sprintf(`
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
service_account_key_path = "%s"
|
||||
}`, saFile)
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
service_account_key_path = "%s"
|
||||
postgresflex_custom_endpoint = "%s"
|
||||
}`,
|
||||
saFile,
|
||||
PostgresFlexCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
|
@ -324,12 +330,12 @@ func PostgresFlexProviderConfig() string {
|
|||
func RabbitMQProviderConfig() string {
|
||||
if RabbitMQCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
rabbitmq_custom_endpoint = "%s"
|
||||
}`,
|
||||
RabbitMQCustomEndpoint,
|
||||
|
|
@ -339,12 +345,12 @@ func RabbitMQProviderConfig() string {
|
|||
func RedisProviderConfig() string {
|
||||
if RedisCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
redis_custom_endpoint = "%s"
|
||||
}`,
|
||||
RedisCustomEndpoint,
|
||||
|
|
@ -352,53 +358,56 @@ func RedisProviderConfig() string {
|
|||
}
|
||||
|
||||
func ResourceManagerProviderConfig() string {
|
||||
token := GetTestProjectServiceAccountToken("")
|
||||
key := GetTestProjectServiceAccountJson("")
|
||||
if ResourceManagerCustomEndpoint == "" || AuthorizationCustomEndpoint == "" {
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
service_account_token = "%s"
|
||||
provider "stackitprivatepreview" {
|
||||
service_account_key = "%s"
|
||||
}`,
|
||||
token,
|
||||
key,
|
||||
)
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
resourcemanager_custom_endpoint = "%s"
|
||||
authorization_custom_endpoint = "%s"
|
||||
service_account_token = "%s"
|
||||
}`,
|
||||
ResourceManagerCustomEndpoint,
|
||||
AuthorizationCustomEndpoint,
|
||||
token,
|
||||
key,
|
||||
)
|
||||
}
|
||||
|
||||
func SecretsManagerProviderConfig() string {
|
||||
if SecretsManagerCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
secretsmanager_custom_endpoint = "%s"
|
||||
}`,
|
||||
SecretsManagerCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
||||
func SQLServerFlexProviderConfig() string {
|
||||
func SQLServerFlexProviderConfig(saFile string) string {
|
||||
if SQLServerFlexCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
return fmt.Sprintf(`
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
service_account_key_path = "%s"
|
||||
}`, saFile)
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
service_account_key_path = "%s"
|
||||
sqlserverflex_custom_endpoint = "%s"
|
||||
}`,
|
||||
saFile,
|
||||
SQLServerFlexCustomEndpoint,
|
||||
)
|
||||
}
|
||||
|
|
@ -406,13 +415,13 @@ func SQLServerFlexProviderConfig() string {
|
|||
func ServerBackupProviderConfig() string {
|
||||
if ServerBackupCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
server_backup_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -423,13 +432,13 @@ func ServerBackupProviderConfig() string {
|
|||
func ServerUpdateProviderConfig() string {
|
||||
if ServerUpdateCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
server_update_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -440,12 +449,12 @@ func ServerUpdateProviderConfig() string {
|
|||
func SKEProviderConfig() string {
|
||||
if SKECustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
ske_custom_endpoint = "%s"
|
||||
}`,
|
||||
SKECustomEndpoint,
|
||||
|
|
@ -455,13 +464,13 @@ func SKEProviderConfig() string {
|
|||
func AuthorizationProviderConfig() string {
|
||||
if AuthorizationCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
experiments = ["iam"]
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
authorization_custom_endpoint = "%s"
|
||||
experiments = ["iam"]
|
||||
}`,
|
||||
|
|
@ -472,13 +481,13 @@ func AuthorizationProviderConfig() string {
|
|||
func ServiceAccountProviderConfig() string {
|
||||
if ServiceAccountCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
service_account_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -489,13 +498,13 @@ func ServiceAccountProviderConfig() string {
|
|||
func GitProviderConfig() string {
|
||||
if GitCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
enable_beta_resources = true
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
git_custom_endpoint = "%s"
|
||||
enable_beta_resources = true
|
||||
}`,
|
||||
|
|
@ -506,12 +515,12 @@ func GitProviderConfig() string {
|
|||
func ScfProviderConfig() string {
|
||||
if ScfCustomEndpoint == "" {
|
||||
return `
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
}`
|
||||
}
|
||||
return fmt.Sprintf(`
|
||||
provider "stackit" {
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "eu01"
|
||||
scf_custom_endpoint = "%s"
|
||||
}`,
|
||||
|
|
@ -526,11 +535,11 @@ func ResourceNameWithDateTime(name string) string {
|
|||
return fmt.Sprintf("tf-acc-%s-%s", name, dateTimeTrimmed)
|
||||
}
|
||||
|
||||
func GetTestProjectServiceAccountToken(path string) string {
|
||||
func GetTestProjectServiceAccountJson(path string) string {
|
||||
var err error
|
||||
token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN")
|
||||
token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_JSON")
|
||||
if !tokenSet || token == "" {
|
||||
token, err = readTestTokenFromCredentialsFile(path)
|
||||
token, err = readTestServiceAccountJsonFromFile(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
|
@ -538,11 +547,53 @@ func GetTestProjectServiceAccountToken(path string) string {
|
|||
return token
|
||||
}
|
||||
|
||||
func readTestTokenFromCredentialsFile(path string) (string, error) {
|
||||
//func GetTestProjectServiceAccountToken(path string) string {
|
||||
// var err error
|
||||
// token, tokenSet := os.LookupEnv("TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN")
|
||||
// if !tokenSet || token == "" {
|
||||
// token, err = readTestTokenFromCredentialsFile(path)
|
||||
// if err != nil {
|
||||
// return ""
|
||||
// }
|
||||
// }
|
||||
// return token
|
||||
//}
|
||||
//
|
||||
//func readTestTokenFromCredentialsFile(path string) (string, error) {
|
||||
// if path == "" {
|
||||
// customPath, customPathSet := os.LookupEnv("STACKIT_CREDENTIALS_PATH")
|
||||
// if !customPathSet || customPath == "" {
|
||||
// path = credentialsFilePath
|
||||
// home, err := os.UserHomeDir()
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("getting home directory: %w", err)
|
||||
// }
|
||||
// path = filepath.Join(home, path)
|
||||
// } else {
|
||||
// path = customPath
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// credentialsRaw, err := os.ReadFile(path)
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("opening file: %w", err)
|
||||
// }
|
||||
//
|
||||
// var credentials struct {
|
||||
// TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN string `json:"TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN"`
|
||||
// }
|
||||
// err = json.Unmarshal(credentialsRaw, &credentials)
|
||||
// if err != nil {
|
||||
// return "", fmt.Errorf("unmarshalling credentials: %w", err)
|
||||
// }
|
||||
// return credentials.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN, nil
|
||||
//}
|
||||
|
||||
func readTestServiceAccountJsonFromFile(path string) (string, error) {
|
||||
if path == "" {
|
||||
customPath, customPathSet := os.LookupEnv("STACKIT_CREDENTIALS_PATH")
|
||||
customPath, customPathSet := os.LookupEnv("STACKIT_SERVICE_ACCOUNT_PATH")
|
||||
if !customPathSet || customPath == "" {
|
||||
path = credentialsFilePath
|
||||
path = serviceAccountFilePath
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("getting home directory: %w", err)
|
||||
|
|
@ -557,15 +608,7 @@ func readTestTokenFromCredentialsFile(path string) (string, error) {
|
|||
if err != nil {
|
||||
return "", fmt.Errorf("opening file: %w", err)
|
||||
}
|
||||
|
||||
var credentials struct {
|
||||
TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN string `json:"TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN"`
|
||||
}
|
||||
err = json.Unmarshal(credentialsRaw, &credentials)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("unmarshalling credentials: %w", err)
|
||||
}
|
||||
return credentials.TF_ACC_TEST_PROJECT_SERVICE_ACCOUNT_TOKEN, nil
|
||||
return string(credentialsRaw), nil
|
||||
}
|
||||
|
||||
func getenv(key, defaultValue string) string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue