Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple backends #276

Open
kinseii opened this issue Aug 1, 2024 · 3 comments
Open

Multiple backends #276

kinseii opened this issue Aug 1, 2024 · 3 comments
Labels
kind/bug Something isn't working

Comments

@kinseii
Copy link

kinseii commented Aug 1, 2024

We have multiple subscriptions in a cloud provider and we would like to store the state files for each StackTemplate in separate storages (backends). The documentation says (https://docs.cluster.dev/structure-project):

backend-name of the backend that will be used to store the cluster.dev state of the current project. Optional.

That is, it seems to be the way it was intended, since this parameter is optional in the Project. However, the validate and plan commands produce an error:

01:16:46 [FATAL] Project configuration check: fail
load base configuration: loading project: error in project config: backend is not defined. To use default local backend, set 'backend: default' option

Thus I can't specify multiple backends. If this is not a bug, I would like to request such a feature, thank you very much!

@kinseii kinseii added the kind/feature New feature or request label Aug 1, 2024
@romanprog
Copy link
Contributor

Hello.
You can use multiple backends for terraform states (configured in kind: stack ). The backend is tied to the stack.
But cdev's own state (configured in project.yaml, kind: project ) can be stored only in one backend.
Here is a conditional example:
project.yaml

name: example
kind: Project
backend: aws-backend # save cdev state in aws s3
variables:
  organization: cluster-dev
  region: eu-central-1
  state_bucket_name: cluster-dev-gha-tests

stack.yaml

name: aws-backend
kind: Backend
provider: s3
spec:
  bucket: {{ .project.variables.state_bucket_name }}
  region: {{ .project.variables.region }}
---
name: azurerm-backend
kind: backend
provider: azurerm
spec:
  resource_group_name: "StorageAccount-ResourceGroup"
  storage_account_name: "example"
  container_name: "cdev-states"
---
name: aws-stack
template: https://...
kind: Stack
backend: aws-backend # save tf states in aws s3
---
name: azure-stack
template: https://...
kind: Stack
backend: azurerm-backend # save tf states in azure 

Does this answer the question?

@kinseii
Copy link
Author

kinseii commented Sep 11, 2024

I've suspended PoC for cdev for now, but I'd like to report the following.

We are using Azure Blob Storage (ABS), we have multiple stacks in our project that use separate Subscriptions. I can manually switch Subscriptions with the command az account set -n $SUBSCRIPTION-NAME.

If I am in Subscription1 and if we have a Stack using Subscription1 in the backend. And Cdev itself is using Subscription2, then plan/apply gives an error (just the string “Error”), if you enable debug, you will see that it can't access Blob Storage for Cdev itself. So we have several subscriptions in our configuration and we need to define where to save the states of cdev itself and if I specify one of them (in the kind: Project), I will get an error when running for a subscription other than cdev backend.
I have so far used backend: default so that the cdev states are saved locally, but of course we have to do something about it.

@romanprog romanprog added kind/bug Something isn't working and removed kind/feature New feature or request labels Sep 13, 2024
@romanprog
Copy link
Contributor

Understood, i changed label of this issue to bug. Will check this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants