Skip to content

Commit 6f4c2f6

Browse files
authored
Merge pull request #60 from pablo19sc/main
Adding AWS RAM share support (VPC Lattice service networks and services)
2 parents 5e8245e + adc2e3b commit 6f4c2f6

19 files changed

+273
-3
lines changed

.header.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ service_network = {
6161
}
6262
```
6363

64+
You can share VPC Lattice service networks using AWS RAM with this module. Check the section [Sharing VPC Lattice resources](#sharing-vpc-lattice-resources) for more information.
65+
6466
### VPC associations (var.vpc_associations)
6567

6668
When you associate a VPC with a service network, it enables all the targets within that VPC to be clients and communicate with other services associated to that same service network. You can make use of Security Groups to control the access of the VPC association, allowing some traffic segmentation before the traffic arrives to the Service Network.
@@ -299,3 +301,16 @@ services = {
299301
}
300302
}
301303
```
304+
305+
You can share VPC Lattice services using AWS RAM with this module. Check the section [Sharing VPC Lattice resources](#sharing-vpc-lattice-resources) for more information.
306+
307+
## Sharing VPC Lattice resources
308+
309+
With [AWS Resource Access Manager](https://aws.amazon.com/ram/) (RAM), you can share VPC Lattice service networks and services. With this module, you can use the variable `var.ram_share` to share VPC Lattice resources. The variable supports the following attributes:
310+
311+
- `resources_share_arn` = (Optional|string) ARN of an **existing** RAM Resource Share to use to associate principals and VPC Lattice resources. **This attribute and `resource_share_name` cannot be set at the same time.**
312+
- `resources_share_name` = (Optional|string) Name of the RAM Resource Share resource. This attribute creates a **new** resource using the specified name. **This attribute and `resources_share_arn` cannot be set at the same time.**
313+
- `allow_external_principals` = (Optional|boolean) Indicates whether principals outside your organization can be associated with a resource share. **This attribute is allowed only when `resources_share_name` is provided.**
314+
- `principals` = (Optional|list(string)) List of AWS principals to associated the resources with. Possible values are an AWS account ID, an AWS Organizations Organization ARN, or an AWS Organizations Organization Unit ARN.
315+
- `share_service_network` = (Optional|boolean) Indicates whether a created VPC Lattice service network should be associated or not. Defaults to `true`.
316+
- `share_services` = (Optional|list(string)) List of created VPC Lattice services to share. You should use the services' keys defined in `var.services`.

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ service_network = {
6262
}
6363
```
6464

65+
You can share VPC Lattice service networks using AWS RAM with this module. Check the section [Sharing VPC Lattice resources](#sharing-vpc-lattice-resources) for more information.
66+
6567
### VPC associations (var.vpc\_associations)
6668

6769
When you associate a VPC with a service network, it enables all the targets within that VPC to be clients and communicate with other services associated to that same service network. You can make use of Security Groups to control the access of the VPC association, allowing some traffic segmentation before the traffic arrives to the Service Network.
@@ -301,6 +303,19 @@ services = {
301303
}
302304
```
303305

306+
You can share VPC Lattice services using AWS RAM with this module. Check the section [Sharing VPC Lattice resources](#sharing-vpc-lattice-resources) for more information.
307+
308+
## Sharing VPC Lattice resources
309+
310+
With [AWS Resource Access Manager](https://aws.amazon.com/ram/) (RAM), you can share VPC Lattice service networks and services. With this module, you can use the variable `var.ram_share` to share VPC Lattice resources. The variable supports the following attributes:
311+
312+
- `resources_share_arn` = (Optional|string) ARN of an **existing** RAM Resource Share to use to associate principals and VPC Lattice resources. **This attribute and `resource_share_name` cannot be set at the same time.**
313+
- `resources_share_name` = (Optional|string) Name of the RAM Resource Share resource. This attribute creates a **new** resource using the specified name. **This attribute and `resources_share_arn` cannot be set at the same time.**
314+
- `allow_external_principals` = (Optional|boolean) Indicates whether principals outside your organization can be associated with a resource share. **This attribute is allowed only when `resources_share_name` is provided.**
315+
- `principals` = (Optional|list(string)) List of AWS principals to associated the resources with. Possible values are an AWS account ID, an AWS Organizations Organization ARN, or an AWS Organizations Organization Unit ARN.
316+
- `share_service_network` = (Optional|boolean) Indicates whether a created VPC Lattice service network should be associated or not. Defaults to `true`.
317+
- `share_services` = (Optional|list(string)) List of created VPC Lattice services to share. You should use the services' keys defined in `var.services`.
318+
304319
## Requirements
305320

306321
| Name | Version |
@@ -326,6 +341,10 @@ services = {
326341

327342
| Name | Type |
328343
|------|------|
344+
| [aws_ram_principal_association.ram_principal_association](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_principal_association) | resource |
345+
| [aws_ram_resource_association.ram_service_network_association](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_resource_association) | resource |
346+
| [aws_ram_resource_association.ram_services_association](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_resource_association) | resource |
347+
| [aws_ram_resource_share.ram_resource_share](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_resource_share) | resource |
329348
| [aws_vpclattice_auth_policy.service_auth_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpclattice_auth_policy) | resource |
330349
| [aws_vpclattice_auth_policy.service_network_auth_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpclattice_auth_policy) | resource |
331350
| [aws_vpclattice_service.lattice_service](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpclattice_service) | resource |
@@ -340,6 +359,7 @@ services = {
340359

341360
| Name | Description | Type | Default | Required |
342361
|------|-------------|------|---------|:--------:|
362+
| <a name="input_ram_share"></a> [ram\_share](#input\_ram\_share) | Configuration of the resources to share using AWS Resource Access Manager (RAM). VPC Lattice service networks and services can be shared using RAM.<br>More information about the format of this variable can be found in the "Usage - AWS RAM share" section of the README. | `any` | `{}` | no |
343363
| <a name="input_service_network"></a> [service\_network](#input\_service\_network) | Amazon VPC Lattice Service Network information. You can either create a new Service Network or reference a current one (to associate Services or VPCs). Setting the `name` attribute will create a **new** service network, while using the attribute `identifier` will reference an **existing** service network.<br>More information about the format of this variable can be found in the "Usage - Service Network" section of the README. | `any` | `{}` | no |
344364
| <a name="input_services"></a> [services](#input\_services) | Definition of the VPC Lattice Services to create. You can use this module to either create only Lattice services (not associated with any service network), or associated with a service network (if you create one or provide an identifier). You can define 1 or more Service using this module.<br>More information about the format of this variable can be found in the "Usage - Services" section of the README. | `any` | `{}` | no |
345365
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to apply to all the resources created in this module. | `map(string)` | `{}` | no |
@@ -351,6 +371,7 @@ services = {
351371
| Name | Description |
352372
|------|-------------|
353373
| <a name="output_listeners_by_service"></a> [listeners\_by\_service](#output\_listeners\_by\_service) | VPC Lattice Listener and Rules. Per Lattice Service, each Listener is composed by the following attributes:<br>- `attributes` = Full output of **aws\_vpclattice\_listener**.<br>- `rules` = Full output of **aws\_vpclattice\_listener\_rule**. |
374+
| <a name="output_ram_resource_share"></a> [ram\_resource\_share](#output\_ram\_resource\_share) | AWS Resource Access Manager resource share. Full output of **aws\_ram\_resource\_share**. |
354375
| <a name="output_service_network"></a> [service\_network](#output\_service\_network) | VPC Lattice resource attributes. Full output of **aws\_vpclattice\_service\_network**. |
355376
| <a name="output_services"></a> [services](#output\_services) | VPC Lattice Services. The output is composed by the following attributes (per Service created):<br>- `attributes` = Full output of **aws\_vpclattice\_service**.<br>- `service_network_association` = Full output of **aws\_vpclattice\_service\_network\_service\_association**. |
356377
| <a name="output_target_groups"></a> [target\_groups](#output\_target\_groups) | VPC Lattice Target Groups. Full output of **aws\_vpclattice\_target\_group**. |

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.1.0
1+
v0.2.0

data.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ locals {
1313
# Checking if Service Network auth policy should be created
1414
sn_auth_policy = (try(var.service_network.auth_type, "NONE") == "AWS_IAM") && (contains(keys(var.service_network), "auth_policy"))
1515

16+
1617
# ---------- VPC Lattice Service variables ---------
1718
# Service Association - if Service Network is created or passed
1819
create_service_association = local.create_service_network || local.sn_identifier_provided
@@ -23,6 +24,20 @@ locals {
2324
try({ for k, v in aws_vpclattice_target_group.lambda_lattice_target_group : k => v.id }, {}),
2425
try({ for k, v in aws_vpclattice_target_group.lattice_target_group : k => v.id }, {}),
2526
)
27+
28+
# ---------- AWS RAM SHARE ----------
29+
# Determining if a RAM resource share has to be created
30+
create_ram_resource_share = contains(keys(var.ram_share), "resource_share_name")
31+
# Determining if any RAM share configuration has to be created
32+
config_ram_share = length(keys(var.ram_share)) > 0
33+
# Getting RAM resource share ARN
34+
resource_share_arn = local.create_ram_resource_share ? aws_ram_resource_share.ram_resource_share[0].arn : try(var.ram_share.resource_share_arn, null)
35+
# Determining if the service network needs to be shared
36+
share_service_network = local.config_ram_share ? local.create_service_network && try(var.ram_share.share_service_network, true) : false
37+
# Default of var.ram_share.share_services - if not defined, all the created services will be included
38+
share_services = try(var.ram_share.share_services, keys(var.services))
39+
# Move var.ram_share.principals from list(string) to map(string)
40+
principals_map = { for index, principal in try(var.ram_share.principals, []) : index => principal }
2641
}
2742

2843
# Sanitizes tags for aws provider

examples/ram_share/.header.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Amazon VPC Lattice - Example: AWS RAM share
2+
3+
This example shows how you can use the VPC Lattice module to share service networks and services using [AWS Resource Access Manager](https://aws.amazon.com/ram/) RAM. The example creates the following:
4+
5+
* 1 VPC Lattice service network.
6+
* 3 VPC Lattice services - basic configuration (without listeners or targets).
7+
* 2 RAM shares. One is sharing the service network, and the other one is sharing 2 out of the 3 VPC Lattice services created.
8+
9+
**NOTE**: Given we automate these examples before merging new PRs, there's an [AWS Systems Manager parameter](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) data source configured to obtain an Account ID from a parameter configured in the AWS Account we use for the automated tests. Take that into account when doing your own tests, and please remember to keep this configuration when doing any PR to this repository.
10+
11+
In the `outputs.tf` file, you can see an example on how to obtain the information about the RAM share created (if applicable).

examples/ram_share/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!-- BEGIN_TF_DOCS -->
2+
# Amazon VPC Lattice - Example: AWS RAM share
3+
4+
This example shows how you can use the VPC Lattice module to share service networks and services using [AWS Resource Access Manager](https://aws.amazon.com/ram/) RAM. The example creates the following:
5+
6+
* 1 VPC Lattice service network.
7+
* 3 VPC Lattice services - basic configuration (without listeners or targets).
8+
* 2 RAM shares. One is sharing the service network, and the other one is sharing 2 out of the 3 VPC Lattice services created.
9+
10+
**NOTE**: Given we automate these examples before merging new PRs, there's an [AWS Systems Manager parameter](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html) data source configured to obtain an Account ID from a parameter configured in the AWS Account we use for the automated tests. Take that into account when doing your own tests, and please remember to keep this configuration when doing any PR to this repository.
11+
12+
In the `outputs.tf` file, you can see an example on how to obtain the information about the RAM share created (if applicable).
13+
14+
## Requirements
15+
16+
| Name | Version |
17+
|------|---------|
18+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0 |
19+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.66.0 |
20+
21+
## Providers
22+
23+
| Name | Version |
24+
|------|---------|
25+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.66.0 |
26+
27+
## Modules
28+
29+
| Name | Source | Version |
30+
|------|--------|---------|
31+
| <a name="module_vpclattice_service_network_share"></a> [vpclattice\_service\_network\_share](#module\_vpclattice\_service\_network\_share) | ../.. | n/a |
32+
| <a name="module_vpclattice_services_share"></a> [vpclattice\_services\_share](#module\_vpclattice\_services\_share) | ../.. | n/a |
33+
34+
## Resources
35+
36+
| Name | Type |
37+
|------|------|
38+
| [aws_ram_resource_share.vpclattice_resource_share](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ram_resource_share) | resource |
39+
| [aws_ssm_parameter.account_id](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ssm_parameter) | data source |
40+
41+
## Inputs
42+
43+
| Name | Description | Type | Default | Required |
44+
|------|-------------|------|---------|:--------:|
45+
| <a name="input_aws_region"></a> [aws\_region](#input\_aws\_region) | AWS Region to use. | `string` | `"eu-west-1"` | no |
46+
47+
## Outputs
48+
49+
No outputs.
50+
<!-- END_TF_DOCS -->

examples/ram_share/main.tf

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# --- examples/ram_share/main.tf ---
2+
3+
# Obtaining the AWS Account ID to share the resources with.
4+
# If you are testing outside the module automation, either change this value with an AWS Account you own, or create a Parameter with this value
5+
data "aws_ssm_parameter" "account_id" {
6+
name = "account_id_share"
7+
}
8+
9+
module "vpclattice_service_network_share" {
10+
source = "../.."
11+
12+
service_network = {
13+
name = "service-network"
14+
auth_type = "NONE"
15+
}
16+
17+
ram_share = {
18+
resource_share_name = "service-network-resource-share"
19+
allow_external_principals = true
20+
principals = [data.aws_ssm_parameter.account_id.value]
21+
}
22+
}
23+
24+
module "vpclattice_services_share" {
25+
source = "../.."
26+
27+
services = {
28+
service1 = {
29+
name = "service1"
30+
auth_type = "NONE"
31+
}
32+
service2 = {
33+
name = "service2"
34+
auth_type = "NONE"
35+
}
36+
service3 = {
37+
name = "service3"
38+
auth_type = "NONE"
39+
}
40+
}
41+
42+
ram_share = {
43+
resource_share_arn = aws_ram_resource_share.vpclattice_resource_share.arn
44+
principals = [data.aws_ssm_parameter.account_id.value]
45+
share_services = ["service1", "service2"]
46+
}
47+
}
48+
49+
resource "aws_ram_resource_share" "vpclattice_resource_share" {
50+
name = "services-resource-share"
51+
allow_external_principals = true
52+
}
53+

examples/ram_share/outputs.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# --- examples/ram_share/outputs.tf ---

examples/ram_share/providers.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# --- examples/ram_share/providers.tf ---
2+
3+
terraform {
4+
required_version = ">= 1.3.0"
5+
required_providers {
6+
aws = {
7+
source = "hashicorp/aws"
8+
version = ">= 4.66.0"
9+
}
10+
}
11+
}
12+
13+
# Provider definition
14+
provider "aws" {
15+
region = var.aws_region
16+
}

examples/ram_share/variablest.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# --- examples/ram_share/variables.tf ---
2+
3+
variable "aws_region" {
4+
type = string
5+
description = "AWS Region to use."
6+
default = "eu-west-1"
7+
}

0 commit comments

Comments
 (0)