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

Introducing a dedicated bootstrap lab #11

Merged
merged 2 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions 0-bootstrap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Getting started

Let’s get started by bootstrapping Terraform and out AWS environment.

## AWS credentials setup

Before you start you will need

- an AWS account that you can safely use during this workshop
- administrator credentials to this account
- install the aws cli according to the [documentation](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)

If you already have a mechanism in place for allowing access to AWS accounts (like SAML or AWS SSO), please use this.
Otherwise, you can create an IAM users as described [here](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-prereqs.html#getting-started-prereqs-iam).

Lastly you have to publish your credentials to your shell environment. If you created an IAM user earlier,
you can follow [this guide](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-methods)
to configure your credentials with the `aws configure` command.

### Test your credentials setup

To make sure that your environment is set up correctly, you can use the following command:

```shell
$ aws sts get-caller-identity
{
"UserId": "AIDASAMPLEUSERID",
"Account": "123456789012",
"Arn": "arn:aws:iam::123456789012:user/DevAdmin"
}
```

You should make sure, that the field `Account` has the same account id that you wanted to use.

## Bootstrap Terraform

### Install Terraform

During this workshop we will be using the terraform cli. To install we recommend that you use the
[terraform version manager tfenv](https://github.com/tfutils/tfenv).

You can now install terraform using tfenv

```shell
$ tfenv install 1.1.9
```

Test if you are using the correct version afterwards

```shell
$ terraform --version
Terraform v1.1.9
...
```

### Bootstrap the Terraform project

1. Create a new folder and cd into it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why a new folder? aren't we already in 0-bootstrap and could do it in here?

1. Create a new file `main.tf`
2. Add these lines to the `main.tf`:
```tf
terraform {
required_version = "~> 1.1.7"
}

provider "aws" {
region = "eu-central-1"
}
```
3. Run `terraform init`

You should see some output similar to this:
```shell
$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/aws...
- Installing hashicorp/aws v4.27.0...
- Installed hashicorp/aws v4.27.0 (signed by HashiCorp)

Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.

Terraform has been successfully initialized!
...
```
## Next

Our AWS environment and the terraform project is now properly set up. In the [next lab](../1-getting-started/), we can start deploying a first resource to our AWS account.
21 changes: 4 additions & 17 deletions 1-getting-started/README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
# Getting started

Let’s get started by bootstrapping Terraform and deploying some resources to AWS. Instead of just deploying some random resources, we want to create an S3 bucket and enable static website hosting. Ultimately, we serve a static HTML file.
Let’s get started by deploying some resources to AWS. Instead of just deploying some random resources, we want to create an S3 bucket and enable static website hosting. Ultimately, we serve a static HTML file.

## Bootstrap Terraform
## Creating a first bucket

1. Create a new folder and cd into it.
1. Create a new file `main.tf`
2. Add these lines to the `main.tf`:
```tf
terraform {
required_version = "~> 1.1.7"
}

provider "aws" {
region = "eu-central-1"
}
```
3. Run `terraform init`
4. Replace the `main.tf` file by adding the first resource:
1. Replace the `main.tf` file by adding the first resource:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok I think now I understand. The steps should be followed in a separate folder instead of switching von 0-.. to 1-.. and so on?

```tf
terraform {
required_version = "~> 1.1.7"
Expand All @@ -34,7 +21,7 @@ Let’s get started by bootstrapping Terraform and deploying some resources to A
force_destroy = true
}
```
5. Run `terraform apply` and confirm the deployment with `yes`.
2. Run `terraform apply` and confirm the deployment with `yes`.

We just created an empty S3 bucket. Go to the [S3 console](https://s3.console.aws.amazon.com/s3/buckets) and verify the existence.

Expand Down