DEV Community


Discussion on: Create An AWS S3 Based Website Using Terraform And Github Actions

loujaybee profile image
Lou — Cloud Engineer Author • Edited

Hey Aishwarya! :)

Ah yeah that part is confusing. I think I was answering it when I said:

*Note: * That the key in this context references the name of the state of the current provisioned resources, as a single backend state can hold data about many different terraform configurations.

But let me rephrase if that helps you understand it better...

Let's talk about remote state for a second. A large corporation could decide to have only one remote state bucket and re-use it across all teams (because they can). But they wouldn't want to all share the same remote state file. To get around this each project has a "key" which distinguishes that projects specific remote state from another.

In reality the remote state bucket has a structure like this:


Where the parent directory is your S3 and the child files are the state files (named according to your key). It's probably easier to see it in real life. So here's two screenshots of my own setup.

Example S3 (With a remote state bucket)

You can see I currently have three buckets setup. One is remote state, the other two are regular "resources".

The name of the state bucket is the: YOUR_REMOTE_STATE_BUCKET_NAME


Example S3 Remote State Bucket

And inside the remote state I have three projects, these are your keys.

The name of these files is the: YOUR_REMOTE_STATE_KEY


So when you're setting up Terraform remote sate you'll need:

  • A remote state bucket which you can create manually (Note: there are ways to script the creation of the remote state bucket itself but it gets a bit confusing as you have to create the bucket and then import it back into Terraform)
  • A key (which is usually just the name of the project)

Does that help?