-
Notifications
You must be signed in to change notification settings - Fork 0
Add s3 datasources for bootstrap bucket. Add testing patterns. #2
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| locals { | ||
| create_s3_bootstrap_policy = !var.code_package_public && var.cloud_provider == "aws" && length(var.bootstrap_objectstorage_bucket_name) != 0 | ||
| } | ||
|
|
||
| data "aws_iam_policy_document" "assume_role" { | ||
| count = var.cloud_provider == "aws" ? 1 : 0 | ||
|
|
||
| statement { | ||
| actions = ["sts:AssumeRole"] | ||
|
|
||
| principals { | ||
| type = "Service" | ||
| identifiers = ["ec2.amazonaws.com"] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # Policy allowing fetching code package from S3 | ||
| data "aws_iam_policy_document" "s3_bootstrap" { | ||
| count = local.create_s3_bootstrap_policy ? 1 : 0 | ||
|
|
||
| statement { | ||
| actions = [ | ||
| "s3:GetObject", | ||
| ] | ||
|
|
||
| resources = [ | ||
| "${data.aws_s3_bucket.bootstrap[0].arn}/*", | ||
| ] | ||
| } | ||
| } | ||
|
|
||
| data "aws_s3_bucket" "bootstrap" { | ||
| count = local.create_s3_bootstrap_policy ? 1 : 0 | ||
| bucket = var.bootstrap_objectstorage_bucket_name | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| locals { | ||
| create_new_ssh_key = var.create_ssh_keypair && (length(var.ssh_public_key) == 0) | ||
| create_aws_key_pair = (var.create_ssh_keypair && (length(var.ssh_public_key) > 0)) || local.create_new_ssh_key | ||
| } | ||
|
|
||
| # Generate RSA Key if create_ssh_keypair=true and No public key specified | ||
| resource "tls_private_key" "generated_ssh_key_pair" { | ||
| count = local.create_new_ssh_key ? 1 : 0 | ||
| algorithm = "RSA" | ||
| } | ||
|
|
||
| # Create AWS Key Pair if create_ssh_keypair=true and No public key specified or create_ssh_keypair=true and key specified. | ||
| resource "aws_key_pair" "ssh" { | ||
| count = local.create_aws_key_pair ? 1 : 0 | ||
|
|
||
| key_name_prefix = var.name | ||
| public_key = try(tls_private_key.generated_ssh_key_pair[0].public_key_openssh, var.ssh_public_key) | ||
|
|
||
| tags = merge( | ||
| { "Name" = var.name }, | ||
| var.tags, | ||
| var.key_pair_tags, | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Testing | ||
| This directory will contain tfvars used for testing as well as simple terraform code to create any required objects for tests to pass. | ||
| There may be exceptions to this where cost comes into play. | ||
|
|
||
| ## Build AWS Testing Objects | ||
| In this directory execute `terraform plan -var-file="aws-testing.tfvars"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| aws_tests = true | ||
|
|
||
| bootstrap_objectstorage_bucket_name = "test-cs-tf-userdata-launcher-bootstrap" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| resource "aws_s3_bucket" "bootstrap" { | ||
| count = var.aws_tests ? 1 : 0 | ||
|
|
||
| bucket = var.bootstrap_objectstorage_bucket_name | ||
|
|
||
| tags = { | ||
| Name = var.bootstrap_objectstorage_bucket_name | ||
| Environment = "Testing" | ||
| Repo = "terraform-cloud-userdata-launcher" | ||
| } | ||
| } | ||
|
|
||
| resource "aws_s3_bucket_acl" "bootstrap" { | ||
| count = var.aws_tests ? 1 : 0 | ||
|
|
||
| bucket = aws_s3_bucket.bootstrap[0].id | ||
| acl = "private" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| variable "aws_tests" {} | ||
| variable "bootstrap_objectstorage_bucket_name" {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| terraform { | ||
| required_version = ">= 0.13.1" | ||
|
|
||
| required_providers { | ||
| aws = { | ||
| source = "hashicorp/aws" | ||
| version = ">= 3.63" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generates a new key, and doesn't use var.ssh_public_key, yet it's count is based on length of var.ssh_public_key being > 0... I'm confused on exactly what the intent is here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks wrong. Should be
== 0. Adding a new commit to fix and add comments to make it more clear.