Skip to content

Commit 905181d

Browse files
Add IAM instance profile to build_user module (#9)
* Add IAM instance profile to build_user module Add iam_instance_profile to build_user module and update policies for S3 access. * **modules/build_user/main.tf** - Add `aws_iam_instance_profile` resource to create the instance profile. * **locals.tf** - Update `build_user_iam_policy` to include access to all relevant S3 buckets and objects. * **main.tf** - Reference the new `iam_instance_profile` in the `build_user` module. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/HappyPathway/terraform-aws-image-pipeline?shareId=XXXX-XXXX-XXXX-XXXX). * terraform-docs: automated action --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 710cf8d commit 905181d

File tree

5 files changed

+85
-19
lines changed

5 files changed

+85
-19
lines changed

.terraform.lock.hcl

Lines changed: 54 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
| Name | Version |
1515
|------|---------|
16-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.49.0 |
16+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.86.0 |
17+
| <a name="provider_random"></a> [random](#provider\_random) | 3.6.3 |
18+
| <a name="provider_tls"></a> [tls](#provider\_tls) | 4.0.6 |
1719

1820
## Modules
1921

@@ -30,15 +32,19 @@
3032

3133
| Name | Type |
3234
|------|------|
35+
| [aws_key_pair.deployer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/key_pair) | resource |
3336
| [aws_secretsmanager_secret.secrets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
37+
| [aws_secretsmanager_secret.ssh_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |
3438
| [aws_secretsmanager_secret_version.secrets](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
39+
| [aws_secretsmanager_secret_version.ssh_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret_version) | resource |
3540
| [aws_security_group.packer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
3641
| [aws_security_group_rule.sg_rule](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
3742
| [aws_ssm_parameter.managed_parameters](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
38-
| [aws_ssm_parameter.nonmanaged_parameters](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ssm_parameter) | resource |
3943
| [aws_vpc_security_group_egress_rule.allow_all_traffic_ipv4](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_security_group_egress_rule) | resource |
4044
| [aws_vpc_security_group_egress_rule.allow_all_traffic_ipv6](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_security_group_egress_rule) | resource |
4145
| [aws_vpc_security_group_ingress_rule.allow_all_ssh_ipv4](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc_security_group_ingress_rule) | resource |
46+
| [random_pet.keyname](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource |
47+
| [tls_private_key.ssh](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
4248
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
4349
| [aws_iam_policy_document.build_user_default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
4450
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
@@ -52,6 +58,7 @@
5258
| <a name="input_ansible_bucket"></a> [ansible\_bucket](#input\_ansible\_bucket) | Ansible bucket details | <pre>object({<br> name = string,<br> key = string<br> })</pre> | `null` | no |
5359
| <a name="input_ansible_repo"></a> [ansible\_repo](#input\_ansible\_repo) | Source of Ansible Repo | <pre>object({<br> arn = optional(string)<br> repository_name = optional(string, "image-pipeline-ansible-playbooks")<br> branch = optional(string, "main")<br> })</pre> | `null` | no |
5460
| <a name="input_ansible_source_type"></a> [ansible\_source\_type](#input\_ansible\_source\_type) | Type of source to be used for the Ansible CodePipeline | `string` | `"CodeCommit"` | no |
61+
| <a name="input_assets_bucket_name"></a> [assets\_bucket\_name](#input\_assets\_bucket\_name) | Name of the S3 bucket used to store the deployment artifacts | `string` | `"image-pipeline-assets"` | no |
5562
| <a name="input_build_environment_variables"></a> [build\_environment\_variables](#input\_build\_environment\_variables) | n/a | <pre>list(object({<br> name = string<br> value = string<br> type = optional(string, "PLAINTEXT")<br> }))</pre> | `null` | no |
5663
| <a name="input_build_project_source"></a> [build\_project\_source](#input\_build\_project\_source) | Source Code Repo for Playbook | `string` | `"CODEPIPELINE"` | no |
5764
| <a name="input_build_projects"></a> [build\_projects](#input\_build\_projects) | List of Names of the CodeBuild projects to be created | <pre>list(object({<br> name = string,<br> vars = optional(map(string), {})<br> environment_variables = optional(list(object({<br> name = string<br> value = string<br> type = string<br> })), [])<br> buildspec = optional(string)<br> }))</pre> | <pre>[<br> {<br> "name": "build"<br> },<br> {<br> "name": "test"<br> }<br>]</pre> | no |
@@ -71,6 +78,8 @@
7178
| <a name="input_goss_repo"></a> [goss\_repo](#input\_goss\_repo) | Source of Goss Repo | <pre>object({<br> arn = optional(string)<br> repository_name = optional(string, "image-pipeline-goss-testing")<br> branch = optional(string, "main")<br> })</pre> | `null` | no |
7279
| <a name="input_goss_source_type"></a> [goss\_source\_type](#input\_goss\_source\_type) | Type of source to be used for the Goss CodePipeline | `string` | `"CodeCommit"` | no |
7380
| <a name="input_image"></a> [image](#input\_image) | n/a | <pre>object({<br> dest_tag = string<br> dest_docker_repo = string<br> source_image = string<br> source_tag = string<br> source_docker_repo = string<br> })</pre> | `null` | no |
81+
| <a name="input_image_volume_mapping"></a> [image\_volume\_mapping](#input\_image\_volume\_mapping) | n/a | <pre>list(object({<br> device_name = string<br> volume_size = number<br> volume_type = string<br> delete_on_termination = bool<br> encrypted = optional(bool, false)<br> iops = optional(number, null)<br> snapshot_id = optional(string, null)<br> throughput = optional(number, null)<br> virtual_name = optional(string, null)<br> kms_key_id = optional(string, null)<br> mount_path = optional(string, null)<br> }))</pre> | `[]` | no |
82+
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | n/a | `string` | `null` | no |
7483
| <a name="input_nonmanaged_parameters"></a> [nonmanaged\_parameters](#input\_nonmanaged\_parameters) | n/a | `list(string)` | <pre>[<br> "dest_tag"<br>]</pre> | no |
7584
| <a name="input_packer_bucket"></a> [packer\_bucket](#input\_packer\_bucket) | Source bucket details | <pre>object({<br> name = string,<br> key = string<br> })</pre> | `null` | no |
7685
| <a name="input_packer_config"></a> [packer\_config](#input\_packer\_config) | Name of Packer Config in Repo | `string` | `"build.pkr.hcl"` | no |
@@ -80,9 +89,11 @@
8089
| <a name="input_parameter_arns"></a> [parameter\_arns](#input\_parameter\_arns) | n/a | `list(string)` | `null` | no |
8190
| <a name="input_playbook"></a> [playbook](#input\_playbook) | n/a | `string` | `null` | no |
8291
| <a name="input_project_name"></a> [project\_name](#input\_project\_name) | Unique name for this project | `string` | n/a | yes |
92+
| <a name="input_required_packages"></a> [required\_packages](#input\_required\_packages) | n/a | <pre>list(object({<br> src = string<br> dest = string<br> }))</pre> | `[]` | no |
8393
| <a name="input_secret_arns"></a> [secret\_arns](#input\_secret\_arns) | n/a | `list(string)` | `null` | no |
8494
| <a name="input_secrets"></a> [secrets](#input\_secrets) | n/a | `map(string)` | `{}` | no |
8595
| <a name="input_shared_accounts"></a> [shared\_accounts](#input\_shared\_accounts) | n/a | `list(string)` | `null` | no |
96+
| <a name="input_shared_kms_key_arns"></a> [shared\_kms\_key\_arns](#input\_shared\_kms\_key\_arns) | n/a | `list(string)` | `[]` | no |
8697
| <a name="input_ssh_user"></a> [ssh\_user](#input\_ssh\_user) | SSH username | `string` | `null` | no |
8798
| <a name="input_stage_input"></a> [stage\_input](#input\_stage\_input) | Tags to be attached to the CodePipeline | <pre>list(object({<br> name = string,<br> category = string,<br> owner = string,<br> provider = string,<br> input_artifacts = list(string),<br> output_artifacts = list(string)<br> }))</pre> | <pre>[<br> {<br> "category": "Build",<br> "input_artifacts": [<br> "SourceOutput",<br> "SourceAnsibleOutput"<br> ],<br> "name": "build",<br> "output_artifacts": [<br> "BuildOutput"<br> ],<br> "owner": "AWS",<br> "provider": "CodeBuild"<br> },<br> {<br> "category": "Build",<br> "input_artifacts": [<br> "SourceOutput",<br> "SourceGossOutput"<br> ],<br> "name": "test",<br> "output_artifacts": [<br> "BuildTestOutput"<br> ],<br> "owner": "AWS",<br> "provider": "CodeBuild"<br> }<br>]</pre> | no |
8899
| <a name="input_state"></a> [state](#input\_state) | n/a | <pre>object({<br> bucket = string<br> key = string<br> region = string<br> dynamodb_table = string<br> })</pre> | n/a | yes |
@@ -102,9 +113,9 @@
102113
| <a name="output_iam_arn"></a> [iam\_arn](#output\_iam\_arn) | The ARN of the IAM Role used by the CodePipeline |
103114
| <a name="output_kms_arn"></a> [kms\_arn](#output\_kms\_arn) | The ARN of the KMS key used in the codepipeline |
104115
| <a name="output_managed_parameters"></a> [managed\_parameters](#output\_managed\_parameters) | n/a |
105-
| <a name="output_nonmanaged_parameters"></a> [nonmanaged\_parameters](#output\_nonmanaged\_parameters) | n/a |
106116
| <a name="output_s3_arn"></a> [s3\_arn](#output\_s3\_arn) | The ARN of the S3 Bucket |
107117
| <a name="output_s3_bucket"></a> [s3\_bucket](#output\_s3\_bucket) | The Name of the S3 Bucket |
108118
| <a name="output_sec_group"></a> [sec\_group](#output\_sec\_group) | n/a |
109119
| <a name="output_secrets"></a> [secrets](#output\_secrets) | n/a |
120+
| <a name="output_user"></a> [user](#output\_user) | n/a |
110121
<!-- END_TF_DOCS -->

locals.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ data "aws_iam_policy_document" "build_user_default" {
4040
],
4141
var.secret_arns == null ? [] : var.secret_arns)
4242
}
43+
44+
statement {
45+
effect = "Allow"
46+
actions = [
47+
"s3:*"
48+
]
49+
resources = concat([
50+
"arn:${data.aws_partition.current.partition}:s3:::${module.s3_artifacts_bucket.bucket}/*"
51+
],
52+
var.s3_bucket_arns == null ? [] : var.s3_bucket_arns)
53+
}
4354
}
4455

4556
locals {

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module "build_user" {
3737
account_id = local.account_id
3838
region = local.region
3939
build_user_iam_policy = local.build_user_iam_policy
40+
iam_instance_profile = aws_iam_instance_profile.build_user_instance_profile.name
4041
}
4142

4243

modules/build_user/main.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ resource "aws_secretsmanager_secret_version" "credentials" {
3434
aws_access_key_id = aws_iam_access_key.build_user.id
3535
})
3636
}
37+
38+
resource "aws_iam_instance_profile" "build_user_instance_profile" {
39+
name = "${var.project_name}-instance-profile"
40+
role = aws_iam_user.build_user.name
41+
}

0 commit comments

Comments
 (0)