From c7a7eb6a633896354752262dfca593955d14b60b Mon Sep 17 00:00:00 2001 From: fraliv13 <5892139+fraliv13@users.noreply.github.com> Date: Mon, 3 Jul 2023 18:55:38 +0300 Subject: [PATCH] Import existing databases --- helm/crds/provisioning.totalsoft.ro_azuredatabases.yaml | 4 ++++ .../provisioning.totalsoft.ro_azuremanageddatabases.yaml | 4 ++++ .../provisioning/provisioners/pulumi/azure_db.go | 1 + .../provisioning/provisioners/pulumi/azure_managed_db.go | 1 + pkg/apis/provisioning/v1alpha1/azureDatabaseTypes.go | 4 ++++ .../provisioning/v1alpha1/azureManagedDatabaseTypes.go | 4 ++++ .../provisioning/v1alpha1/azuredatabasespec.go | 9 +++++++++ .../provisioning/v1alpha1/azuremanageddatabasespec.go | 9 +++++++++ 8 files changed, 36 insertions(+) diff --git a/helm/crds/provisioning.totalsoft.ro_azuredatabases.yaml b/helm/crds/provisioning.totalsoft.ro_azuredatabases.yaml index 3fd8c63..9a47152 100644 --- a/helm/crds/provisioning.totalsoft.ro_azuredatabases.yaml +++ b/helm/crds/provisioning.totalsoft.ro_azuredatabases.yaml @@ -73,6 +73,10 @@ spec: - domain type: object type: array + importDatabaseId: + description: 'Existing database to be used instead of creating a new + one eg: /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/servers/testsvr/databases/testdb' + type: string platformRef: description: Target platform (custom resource name). type: string diff --git a/helm/crds/provisioning.totalsoft.ro_azuremanageddatabases.yaml b/helm/crds/provisioning.totalsoft.ro_azuremanageddatabases.yaml index a2b7936..8800079 100644 --- a/helm/crds/provisioning.totalsoft.ro_azuremanageddatabases.yaml +++ b/helm/crds/provisioning.totalsoft.ro_azuremanageddatabases.yaml @@ -75,6 +75,10 @@ spec: - domain type: object type: array + importDatabaseId: + description: 'Existing database to be used instead of creating a new + one eg: /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/servers/testsvr/databases/testdb' + type: string managedInstance: description: Target managed instance spec. properties: diff --git a/internal/controllers/provisioning/provisioners/pulumi/azure_db.go b/internal/controllers/provisioning/provisioners/pulumi/azure_db.go index 2e4c332..5c3db73 100644 --- a/internal/controllers/provisioning/provisioners/pulumi/azure_db.go +++ b/internal/controllers/provisioning/provisioners/pulumi/azure_db.go @@ -75,6 +75,7 @@ func azureDbDeployFunc(platform string, tenant *platformv1.Tenant, pulumi.RetainOnDelete(PulumiRetainOnDelete), pulumi.IgnoreChanges(ignoreChanges), pulumi.Aliases([]pulumi.Alias{{Name: pulumi.String(dbNameV1)}}), + pulumi.Import(pulumi.ID(dbSpec.Spec.ImportDatabaseId)), ) if err != nil { return err diff --git a/internal/controllers/provisioning/provisioners/pulumi/azure_managed_db.go b/internal/controllers/provisioning/provisioners/pulumi/azure_managed_db.go index 75ea2f0..e8437be 100644 --- a/internal/controllers/provisioning/provisioners/pulumi/azure_managed_db.go +++ b/internal/controllers/provisioning/provisioners/pulumi/azure_managed_db.go @@ -40,6 +40,7 @@ func azureManagedDbDeployFunc(platform string, tenant *platformv1.Tenant, pulumi.RetainOnDelete(PulumiRetainOnDelete), pulumi.IgnoreChanges(ignoreChanges), pulumi.Aliases([]pulumi.Alias{{Name: pulumi.String(dbNameV1)}}), + pulumi.Import(pulumi.ID(dbSpec.Spec.ImportDatabaseId)), ) if err != nil { return err diff --git a/pkg/apis/provisioning/v1alpha1/azureDatabaseTypes.go b/pkg/apis/provisioning/v1alpha1/azureDatabaseTypes.go index 685328b..efbb674 100644 --- a/pkg/apis/provisioning/v1alpha1/azureDatabaseTypes.go +++ b/pkg/apis/provisioning/v1alpha1/azureDatabaseTypes.go @@ -29,6 +29,10 @@ type AzureDatabaseSpec struct { // eg: /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/servers/testsvr/databases/testdb // +optional SourceDatabaseId string `json:"sourceDatabaseId,omitempty"` + // Existing database to be used instead of creating a new one + // eg: /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/servers/testsvr/databases/testdb + // +optional + ImportDatabaseId string `json:"importDatabaseId,omitempty"` // +optional Exports []AzureDatabaseExportsSpec `json:"exports,omitempty"` ProvisioningMeta `json:",inline"` diff --git a/pkg/apis/provisioning/v1alpha1/azureManagedDatabaseTypes.go b/pkg/apis/provisioning/v1alpha1/azureManagedDatabaseTypes.go index 21fe6fd..8986550 100644 --- a/pkg/apis/provisioning/v1alpha1/azureManagedDatabaseTypes.go +++ b/pkg/apis/provisioning/v1alpha1/azureManagedDatabaseTypes.go @@ -25,6 +25,10 @@ type AzureManagedDatabaseSpec struct { // Restore from external backup. Leave empty for a new empty database. // +optional RestoreFrom AzureManagedDatabaseRestoreSpec `json:"restoreFrom,omitempty"` + // Existing database to be used instead of creating a new one + // eg: /subscriptions/00000000-1111-2222-3333-444444444444/resourceGroups/Default-SQL-SouthEastAsia/providers/Microsoft.Sql/servers/testsvr/databases/testdb + // +optional + ImportDatabaseId string `json:"importDatabaseId,omitempty"` // Export provisioning values spec. // +optional Exports []AzureManagedDatabaseExportsSpec `json:"exports,omitempty"` diff --git a/pkg/generated/applyconfiguration/provisioning/v1alpha1/azuredatabasespec.go b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azuredatabasespec.go index 4ae3b3c..483cdc0 100644 --- a/pkg/generated/applyconfiguration/provisioning/v1alpha1/azuredatabasespec.go +++ b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azuredatabasespec.go @@ -29,6 +29,7 @@ type AzureDatabaseSpecApplyConfiguration struct { SqlServer *SqlServerSpecApplyConfiguration `json:"sqlServer,omitempty"` Sku *string `json:"sku,omitempty"` SourceDatabaseId *string `json:"sourceDatabaseId,omitempty"` + ImportDatabaseId *string `json:"importDatabaseId,omitempty"` Exports []AzureDatabaseExportsSpecApplyConfiguration `json:"exports,omitempty"` ProvisioningMetaApplyConfiguration `json:",inline"` } @@ -71,6 +72,14 @@ func (b *AzureDatabaseSpecApplyConfiguration) WithSourceDatabaseId(value string) return b } +// WithImportDatabaseId sets the ImportDatabaseId field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ImportDatabaseId field is set to the value of the last call. +func (b *AzureDatabaseSpecApplyConfiguration) WithImportDatabaseId(value string) *AzureDatabaseSpecApplyConfiguration { + b.ImportDatabaseId = &value + return b +} + // WithExports adds the given value to the Exports field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the Exports field. diff --git a/pkg/generated/applyconfiguration/provisioning/v1alpha1/azuremanageddatabasespec.go b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azuremanageddatabasespec.go index 8be8b87..ffb821d 100644 --- a/pkg/generated/applyconfiguration/provisioning/v1alpha1/azuremanageddatabasespec.go +++ b/pkg/generated/applyconfiguration/provisioning/v1alpha1/azuremanageddatabasespec.go @@ -28,6 +28,7 @@ type AzureManagedDatabaseSpecApplyConfiguration struct { DbName *string `json:"dbName,omitempty"` ManagedInstance *AzureManagedInstanceSpecApplyConfiguration `json:"managedInstance,omitempty"` RestoreFrom *AzureManagedDatabaseRestoreSpecApplyConfiguration `json:"restoreFrom,omitempty"` + ImportDatabaseId *string `json:"importDatabaseId,omitempty"` Exports []AzureManagedDatabaseExportsSpecApplyConfiguration `json:"exports,omitempty"` ProvisioningMetaApplyConfiguration `json:",inline"` } @@ -62,6 +63,14 @@ func (b *AzureManagedDatabaseSpecApplyConfiguration) WithRestoreFrom(value *Azur return b } +// WithImportDatabaseId sets the ImportDatabaseId field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ImportDatabaseId field is set to the value of the last call. +func (b *AzureManagedDatabaseSpecApplyConfiguration) WithImportDatabaseId(value string) *AzureManagedDatabaseSpecApplyConfiguration { + b.ImportDatabaseId = &value + return b +} + // WithExports adds the given value to the Exports field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the Exports field.