aztfmod / rover

The rover is a docker container in charge of the deployment of the Terraform platform engineering for Azure
MIT License
171 stars 142 forks source link

Initial support for TFC-TFE remote backend type #254

Closed LaurentLesle closed 2 years ago

LaurentLesle commented 2 years ago

Support hybrid azurerm and remote

Azurerm only

rover \
  -lz /tf/caf/landingzones/caf_solution \
  -var-folder /tf/caf/configuration/level1/identity \
  -tfstate_subscription_id 0000000-00000-0000-00000-000000 \
  -target_subscription 0000000-00000-0000-00000-000000 \
  -tfstate identity.tfstate \
  -env contoso \
  -level level1 \
  -p ${TF_DATA_DIR}/identity.tfstate.tfplan \
  -a plan
landingzone = {
  backend_type        = "azurerm"
  level               = "level1"
  key                 = "identity"
  global_settings_key = "launchpad"
  tfstates = {
    launchpad = {
      tfstate   = "caf_launchpad.tfstate"
      workspace = "tfstate"
      level     = "lower"
    }
  }
}

Update remote state migrated to remote while keeping the state of the current deployment to azurerm

landingzone = {
  backend_type        = "azurerm"
  level               = "level1"
  key                 = "identity"
  global_settings_key = "launchpad"
  tfstates = {
    launchpad = {
      backend_type = "remote"
      organization = "aztfmod"
      workspace    = "contoso_level0_caf_launchpad"
    }
  }
}

Migrate an existing tfstate from azurerm to remote backend type

rover \
  -lz /tf/caf/landingzones/caf_solution \
  -var-folder /tf/caf/configuration/level1/identity \
  -tfstate_subscription_id 0000000-00000-0000-00000-000000 \
  -target_subscription 0000000-00000-0000-00000-000000 \
  -tfstate identity.tfstate \
  -env contoso \
  -level level1 \
  -p ${TF_DATA_DIR}/identity.tfstate.tfplan \
  -remote_organization aztfmod  \
  -a migrate -force-copy -input=false 

once completed update the landingzone.tfvars from

landingzone = {
  backend_type        = "**azurerm**"
  level               = "level1"
  key                 = "identity"
  global_settings_key = "launchpad"
  tfstates = {
    launchpad = {
      backend_type = "remote"
      organization = "aztfmod"
      workspace    = "contoso_level0_caf_launchpad"
    }
  }
}

to

landingzone = {
  backend_type        = "**remote**"
  level               = "level1"
  key                 = "identity"
  global_settings_key = "launchpad"
  tfstates = {
    launchpad = {
      backend_type = "remote"
      organization = "aztfmod"
      workspace    = "contoso_level0_caf_launchpad"
    }
  }
}

rover command to execute plan and apply against TFC/TFE in local mode

rover \
  -lz /tf/caf/landingzones/caf_solution \
  -var-folder /tf/caf/configuration/level1/identity \
  -target_subscription 0000000-00000-0000-00000-000000 \
  -tfstate identity.tfstate \
  -env contoso \
  -level level1 \
  -remote_organization aztfmod \
  -a apply