terraform {
  required_providers {
    alicloud = {
      source  = "aliyun/alicloud"
      version = ">= 1.268"
    }
    aws = {
      source  = "hashicorp/aws"
      version = "~> 6.0"
    }
  }

  backend "s3" {
    bucket       = "autonomous-deployment-terraform-state"
    region       = "us-west-2"
    use_lockfile = true
  }
}

provider "aws" {
  profile = "default"
  region  = "us-west-2"
  alias   = "tf_state"
}

provider "alicloud" {
  profile = var.account
  region  = "ap-southeast-1"
}

variable "env" {
  type = string
}

variable "account" {
  type = string
}

variable "plan" {
  type = string
}

data "aws_s3_object" "seed_state" {
  bucket = "autonomous-deployment-terraform-state"
  key    = "alicloud/account/seed/${var.env}.json"

  provider = aws.tf_state
}

locals {
  seed_outputs = jsondecode(data.aws_s3_object.seed_state.body).outputs
}

output "env" {
  value = var.env
}

output "base_account" {
  value = local.seed_outputs.base_account.value
}

output "seed_account" {
  value = local.seed_outputs.seed_account.value
}

output "shoot_account" {
  value = var.account
}

output "plan" {
  value = var.plan
}