
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Add a local backend
/ 25
Add a Cloud Storage backend
/ 25
Refresh the state
/ 25
Clean up the workspace
/ 25
In this lab, you will create a local backend and then create a Cloud Storage bucket to migrate the state to a remote backend
In this lab, you will learn how to perform the following tasks:
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
On the Google Cloud menu, click Activate Cloud Shell.
If prompted, click Continue.
Confirm that Terraform is installed by running the following command:
In this section, you will configure a local backend which will then be moved to a Cloud Storage bucket.
main.tf
configuration file.main.tf
configuration file:main.tf
file:This will reference a terraform.tfstate
file in the terraform/state
directory.
The final code in main.tf
is as shown below.
Terraform must initialize any configured backend before use.
The Cloud Shell Editor should now display the state file called terraform.tfstate
in the terraform/state
directory.
Your google_storage_bucket.test-bucket-for-state
resource should be displayed.
Click Check my progress to verify local backend is created.
main.tf
file in the editor. You will now replace the current local backend with a gcs
backend.main.tf
file.The final code in main.tf
is as shown below:
terraform/state/default.tfstate
.Your state file now exists in a Cloud Storage bucket!
Click Check my progress to verify remote backend is created.
The terraform refresh
command is used to reconcile the state Terraform knows about (via its state file) with the real-world infrastructure. This can be used to detect any drift from the last-known state and to update the state file.
This does not modify infrastructure, but does modify the state file. If the state is changed, this may cause changes to occur during the next plan or apply.
key
and Value2 = value
.Click Check my progress to verify terraform is refreshed.
local
so you can delete the storage bucket. Copy and replace the gcs
configuration with the following:local
backend again. Type yes at the prompt to confirm.main.tf
file, add the force_destroy = true
argument to your google_storage_bucket
resource. When you delete a bucket, this boolean option will delete all contained objects.Your resource configuration should resemble the following:
Click Check my progress to verify the backend is deleted.
In this lab, you learned how to manage backends and state with Terraform. You created local and Cloud Storage backends to manage your state file, and also refreshed the state. In this lab, you learned how to perform the following tasks:
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one