Skip to content

Commit 4755eb2

Browse files
authored
Added iam-account (#1)
* Added iam-account
1 parent e337dbc commit 4755eb2

12 files changed

+217
-0
lines changed

.editorconfig

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
# Uses editorconfig to maintain consistent coding styles
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# Unix-style newlines with a newline ending every file
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
indent_size = 2
12+
indent_style = space
13+
insert_final_newline = true
14+
max_line_length = 80
15+
trim_trailing_whitespace = true
16+
17+
[*.{tf,tfvars}]
18+
indent_size = 2
19+
indent_style = space
20+
21+
[*.md]
22+
max_line_length = 0
23+
trim_trailing_whitespace = false
24+
25+
[Makefile]
26+
tab_width = 2
27+
indent_style = tab
28+
29+
[COMMIT_EDITMSG]
30+
max_line_length = 0

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.terraform
2+
terraform.tfstate
3+
*.tfstate*
4+
terraform.tfvars

.pre-commit-config.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: git://github.com/antonbabenko/pre-commit-terraform
3+
sha: v1.4.0
4+
hooks:
5+
- id: terraform_fmt
6+
- repo: git://github.com/pre-commit/pre-commit-hooks
7+
sha: v1.2.0
8+
hooks:
9+
- id: check-merge-conflict

LICENSE

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Licensed under the Apache License, Version 2.0 (the "License");
2+
you may not use this file except in compliance with the License.
3+
You may obtain a copy of the License at
4+
5+
http://www.apache.org/licenses/LICENSE-2.0
6+
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# terraform-aws-iam
22
Terraform module which creates IAM resources on AWS
3+
4+
- [ ] IAM account
5+
- [ ] IAM groups
6+
- [ ] IAM users
7+
- [ ] IAM assumable roles
8+
- [ ] IAM group with assumable roles policy

examples/iam-account/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
HTTP Security Group example
2+
===========================
3+
4+
Configuration in this directory creates set of Security Group and Security Group Rules resources in various combination.
5+
6+
Data sources are used to discover existing VPC resources (VPC and default security group).
7+
8+
Usage
9+
=====
10+
11+
To run this example you need to execute:
12+
13+
```bash
14+
$ terraform init
15+
$ terraform plan
16+
$ terraform apply
17+
```
18+
19+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.

examples/iam-account/main.tf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
provider "aws" {
2+
region = "eu-west-1"
3+
}
4+
5+
##############
6+
# IAM account
7+
##############
8+
module "iam_account" {
9+
source = "../../modules/iam-account"
10+
11+
account_alias = "test-account-awesome-company"
12+
13+
minimum_password_length = 6
14+
require_numbers = false
15+
}

examples/iam-account/outputs.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "this_caller_identity_account_id" {
2+
description = "The ID of the AWS account"
3+
value = "${module.iam_account.this_caller_identity_account_id}"
4+
}
5+
6+
output "this_iam_account_password_policy_expire_passwords" {
7+
description = "Indicates whether passwords in the account expire. Returns true if max_password_age contains a value greater than 0. Returns false if it is 0 or not present."
8+
value = "${module.iam_account.this_iam_account_password_policy_expire_passwords}"
9+
}

modules/iam-account/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# iam-account
2+
3+
Manage IAM account alias and password policy.
4+
5+
## Notes
6+
7+
* If IAM account alias was previously set (either via AWS console or during the creation of an account from AWS Organizations) you will see this error:
8+
```
9+
* aws_iam_account_alias.this: Error creating account alias with name my-account-alias
10+
```
11+
12+
If you want to manage IAM alias using Terraform (otherwise why are you reading this?) you need to import this resource like this:
13+
```
14+
$ terraform import module.iam_account.aws_iam_account_alias.this this
15+
16+
module.iam_account.aws_iam_account_alias.this: Importing from ID "this"...
17+
module.iam_account.aws_iam_account_alias.this: Import complete!
18+
Imported aws_iam_account_alias (ID: this)
19+
module.iam_account.aws_iam_account_alias.this: Refreshing state... (ID: this)
20+
21+
Import successful!
22+
```

modules/iam-account/main.tf

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
data "aws_caller_identity" "this" {
2+
count = "${var.get_caller_identity}"
3+
}
4+
5+
resource "aws_iam_account_alias" "this" {
6+
account_alias = "${var.account_alias}"
7+
}
8+
9+
resource "aws_iam_account_password_policy" "this" {
10+
count = "${var.create_account_password_policy ? 1 : 0}"
11+
12+
minimum_password_length = "${var.minimum_password_length}"
13+
allow_users_to_change_password = "${var.allow_users_to_change_password}"
14+
hard_expiry = "${var.hard_expiry}"
15+
password_reuse_prevention = "${var.password_reuse_prevention}"
16+
require_lowercase_characters = "${var.require_lowercase_characters}"
17+
require_uppercase_characters = "${var.require_uppercase_characters}"
18+
require_numbers = "${var.require_numbers}"
19+
require_symbols = "${var.require_symbols}"
20+
}

modules/iam-account/outputs.tf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "this_caller_identity_account_id" {
2+
description = "The AWS Account ID number of the account that owns or contains the calling entity"
3+
value = "${element(concat(data.aws_caller_identity.this.*.account_id, list("")), 0)}"
4+
}
5+
6+
output "this_caller_identity_arn" {
7+
description = "The AWS ARN associated with the calling entity"
8+
value = "${element(concat(data.aws_caller_identity.this.*.arn, list("")), 0)}"
9+
}
10+
11+
output "this_caller_identity_user_id" {
12+
description = "The unique identifier of the calling entity"
13+
value = "${element(concat(data.aws_caller_identity.this.*.user_id, list("")), 0)}"
14+
}
15+
16+
output "this_iam_account_password_policy_expire_passwords" {
17+
description = "Indicates whether passwords in the account expire. Returns true if max_password_age contains a value greater than 0. Returns false if it is 0 or not present."
18+
value = "${element(concat(aws_iam_account_password_policy.this.*.expire_passwords, list("")), 0)}"
19+
}

modules/iam-account/variables.tf

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
variable "get_caller_identity" {
2+
description = "Whether to get AWS account ID, User ID, and ARN in which Terraform is authorized"
3+
default = true
4+
}
5+
6+
variable "account_alias" {
7+
description = "AWS IAM account alias for this account"
8+
}
9+
10+
variable "create_account_password_policy" {
11+
description = "Whether to create AWS IAM account password policy"
12+
default = true
13+
}
14+
15+
variable "minimum_password_length" {
16+
description = "Minimum length to require for user passwords"
17+
default = 8
18+
}
19+
20+
variable "allow_users_to_change_password" {
21+
description = "Whether to allow users to change their own password"
22+
default = true
23+
}
24+
25+
variable "hard_expiry" {
26+
description = "Whether users are prevented from setting a new password after their password has expired (i.e. require administrator reset)"
27+
default = false
28+
}
29+
30+
variable "password_reuse_prevention" {
31+
description = "The number of previous passwords that users are prevented from reusing"
32+
default = true
33+
}
34+
35+
variable "require_lowercase_characters" {
36+
description = "Whether to require lowercase characters for user passwords"
37+
default = true
38+
}
39+
40+
variable "require_uppercase_characters" {
41+
description = "Whether to require uppercase characters for user passwords"
42+
default = true
43+
}
44+
45+
variable "require_numbers" {
46+
description = "Whether to require numbers for user passwords"
47+
default = true
48+
}
49+
50+
variable "require_symbols" {
51+
description = "Whether to require symbols for user passwords"
52+
default = true
53+
}

0 commit comments

Comments
 (0)