inspec/test/integration/build/aws.tf
Chris Redekop c8d4244ef4 Add has_roles to aws_ec2_instance (#90)
* Rename EC2-instance resources

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* Add interim updates

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* testing for issue 82

Signed-off-by: Simon Varlow <simon.varlow@d2l.com>

* completed integration for EC2 roles

Signed-off-by: Simon Varlow <simon.varlow@d2l.com>

* adding in the beginning of the unit test for issue 82

Signed-off-by: Simon Varlow <simon.varlow@d2l.com>

* Fix unit tests

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* Add has_roles? examples

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* Remove redundant gsub

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* corrected OpenStruct format

Signed-off-by: Simon Varlow <simon.varlow@d2l.com>

* setting up variable for InstanceProfile

Signed-off-by: Simon Varlow <simon.varlow@d2l.com>

* Updated the unit test so all variables are at the top

Signed-off-by: Simon Varlow <simon.varlow@d2l.com>

* Fixed Rubocop issues that were detected

Signed-off-by: Simon Varlow <simon.varlow@d2l.com>

* Updating README.md to include changes to aws_ec2

Signed-off-by: Simon Varlow <simon.varlow@d2l.com>

* Add failing IT for has_roles?

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* Add negative IT and fix uncovered issue

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* Fix Rubocop issue

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* Fix integration test

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* Fix Rubocop issues and unit tests

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>

* Pin AWS dependency to '~> 2'

Signed-off-by: Chris Redekop <chris.redekop@d2l.com>
2017-10-26 15:56:32 -04:00

98 lines
2 KiB
HCL

terraform {
required_version = "~> 0.10.0"
}
provider "aws" {}
resource "aws_iam_role" "example" {
name = "${terraform.env}.example"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_instance_profile" "example" {
name = "${terraform.env}.example"
role = "${aws_iam_role.example.name}"
}
resource "aws_instance" "example" {
ami = "ami-0d729a60"
instance_type = "t2.micro"
iam_instance_profile = "${aws_iam_instance_profile.example.name}"
tags {
Name = "${terraform.env}.Example"
X-Project = "inspec"
}
}
resource "aws_instance" "no_roles_instance" {
ami = "ami-0d729a60"
instance_type = "t2.micro"
tags {
Name = "${terraform.env}.NoRoles"
X-Project = "inspec"
}
}
resource "aws_iam_user" "mfa_not_enabled_user" {
name = "${terraform.env}.mfa_not_enabled_user"
}
resource "aws_iam_user" "console_password_enabled_user" {
name = "${terraform.env}.console_password_enabled_user"
force_destroy = true
}
resource "aws_iam_user_login_profile" "user_login_profile" {
user = "${aws_iam_user.console_password_enabled_user.name}"
pgp_key = "${var.login_profile_pgp_key}"
}
resource "aws_iam_user" "access_key_user" {
name = "${terraform.env}.access_key_user"
}
resource "aws_iam_access_key" "access_key" {
user = "${aws_iam_user.access_key_user.name}"
pgp_key = "${var.login_profile_pgp_key}"
}
output "mfa_not_enabled_user" {
value = "${aws_iam_user.mfa_not_enabled_user.name}"
}
output "console_password_enabled_user" {
value = "${aws_iam_user.console_password_enabled_user.name}"
}
output "access_key_user" {
value = "${aws_iam_user.access_key_user.name}"
}
output "example_ec2_name" {
value = "${aws_instance.example.tags.Name}"
}
output "example_ec2_id" {
value = "${aws_instance.example.id}"
}
output "no_roles_ec2_id" {
value = "${aws_instance.no_roles_instance.id}"
}