Browse Source

feat (BREAKING): upgrades to support Terraform 0.13 properly

tags/11.0.0
Guillaume Donval 3 months ago
parent
commit
f84e61e144
Signed by: guillaume.donval <guillaume.donval@fxinnovation.com> GPG Key ID: 172AC3F9180CD64E
6 changed files with 926 additions and 432 deletions
  1. +107
    -101
      README.md
  2. +24
    -17
      data.tf
  3. +145
    -128
      main.tf
  4. +56
    -33
      outputs.tf
  5. +592
    -151
      variables.tf
  6. +2
    -2
      versions.tf

+ 107
- 101
README.md View File

@@ -31,122 +31,129 @@ That’s why every extra volumes within an AutoScaling group will always be dest

| Name | Version |
|------|---------|
| terraform | >= 0.12 |
| aws | ~> 2.54 |
| terraform | >= 0.13 |
| aws | >= 3.1.0, < 4.0.0 |
| null | ~> 2.1 |

## Providers

| Name | Version |
|------|---------|
| aws | ~> 2.54 |
| aws | >= 3.1.0, < 4.0.0 |
| null | ~> 2.1 |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| ami | The AMI to use for the instances or the launch template. Default: latest AWS linux AMI (careful: when using the default, the AMI could be updated, thus triggering a destroy/recreate of your instances). | `string` | `""` | no |
| associate\_public\_ip\_address | Whether or not to associate a public ip address for each instances (or launch template) main network interface. | `bool` | `false` | no |
| autoscaling\_group\_default\_cooldown | The amount of time, in seconds, after a scaling activity completes before another scaling activity can start. | `number` | `null` | no |
| autoscaling\_group\_enabled\_metrics | A list of metrics to collect. The allowed values are GroupDesiredCapacity, GroupInServiceCapacity, GroupPendingCapacity, GroupMinSize, GroupMaxSize, GroupInServiceInstances, GroupPendingInstances, GroupStandbyInstances, GroupStandbyCapacity, GroupTerminatingCapacity, GroupTerminatingInstances, GroupTotalCapacity, GroupTotalInstances. | `set(string)` | `null` | no |
| autoscaling\_group\_health\_check\_grace\_period | Time (in seconds) after instance comes into service before checking health. | `number` | `null` | no |
| autoscaling\_group\_health\_check\_type | 'EC2' or 'ELB'. Controls how health checking is done. | `string` | `null` | no |
| autoscaling\_group\_max\_instance\_lifetime | The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 604800 and 31536000 seconds. | `number` | `null` | no |
| autoscaling\_group\_max\_size | The maximum size of the auto scale group. | `number` | `1` | no |
| autoscaling\_group\_metrics\_granularity | The granularity to associate with the metrics to collect. The only valid value is 1Minute. Default is 1Minute. | `string` | `null` | no |
| autoscaling\_group\_min\_elb\_capacity | Setting this causes Terraform to wait for this number of instances from this autoscaling group to show up healthy in the ELB only on creation. Updates will not wait on ELB instance number changes. | `number` | `null` | no |
| autoscaling\_group\_min\_size | The minimum size of the auto scale group. | `number` | `1` | no |
| autoscaling\_group\_name | The name of the auto scaling group. By default generated by Terraform. | `string` | `null` | no |
| autoscaling\_group\_suspended\_processes | A list of processes to suspend for the AutoScaling Group. The allowed values are Launch, Terminate, HealthCheck, ReplaceUnhealthy, AZRebalance, AlarmNotification, ScheduledActions, AddToLoadBalancer. Note that if you suspend either the Launch or Terminate process types, it can prevent your autoscaling group from functioning properly. | `set(string)` | `null` | no |
| ami | AMI to use for the instance (or the launch template). Default: latest AWS linux AMI - CAREFUL: when using the default, the AMI ID could get updated, thus triggering a destroy/recreate of your instances. Besides testing, it's recommended to set a value. | `any` | `null` | no |
| associate\_public\_ip\_address | Whether or not to associate a public ip address for the instance (or launch template) main network interface. | `bool` | `false` | no |
| autoscaling\_group\_default\_cooldown | The amount of time, in seconds, after a scaling activity completes before another scaling activity can start. | `number` | `-1` | no |
| autoscaling\_group\_desired\_capacity | Number of instances to immediately launch in the AutoScaling Group. If not specified, defaults to `var.autoscaling_group_min_size`. | `number` | `null` | no |
| autoscaling\_group\_enabled\_metrics | A list of metrics to collect. The allowed values are GroupDesiredCapacity, GroupInServiceCapacity, GroupPendingCapacity, GroupMinSize, GroupMaxSize, GroupInServiceInstances, GroupPendingInstances, GroupStandbyInstances, GroupStandbyCapacity, GroupTerminatingCapacity, GroupTerminatingInstances, GroupTotalCapacity, GroupTotalInstances. | `set(string)` | `[]` | no |
| autoscaling\_group\_health\_check\_grace\_period | Time (in seconds) after instance comes into service before checking health. | `number` | `-1` | no |
| autoscaling\_group\_health\_check\_type | Controls how health checking is done on `EC2` level or on `ELB` level. When using a load balancer `ELB` is recommended. | `string` | `null` | no |
| autoscaling\_group\_max\_instance\_lifetime | The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 604800 and 31536000 seconds. | `number` | `0` | no |
| autoscaling\_group\_max\_size | The maximum size of the AutoScaling Group. | `number` | `1` | no |
| autoscaling\_group\_metrics\_granularity | The granularity to associate with the metrics to collect. The only valid value is `1Minute`. Default is `1Minute`. | `string` | `null` | no |
| autoscaling\_group\_min\_elb\_capacity | Setting this causes Terraform to wait for this number of instances from this autoscaling group to show up healthy in the ELB only on creation. Updates will not wait on ELB instance number changes. [See documentation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#waiting-for-capacity). | `number` | `null` | no |
| autoscaling\_group\_min\_size | The minimum size of the AutoScaling Group. | `number` | `1` | no |
| autoscaling\_group\_name | The name of the AutoScaling Group. By default generated by Terraform. | `string` | `""` | no |
| autoscaling\_group\_subnet\_ids | IDs of the subnets to be used by the AutoScaling Group. If empty, all the default subnets of the current region will be used. This must have as many elements as the count: `var.autoscaling_group_subnet_ids_count`. | `list(string)` | <pre>[<br> ""<br>]</pre> | no |
| autoscaling\_group\_subnet\_ids\_count | How many subnets IDs to be used by the AutoScaling Group in the `var.autoscaling_group_subnet_ids`. If the value is “0”, default subnets will be used. Cannot be computed automatically from other variables in Terraform 0.13.X. | `number` | `0` | no |
| autoscaling\_group\_suspended\_processes | A list of processes to suspend for the AutoScaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. Note that if you suspend either the Launch or Terminate process types, it can prevent your autoscaling group from functioning properly. | `set(string)` | `[]` | no |
| autoscaling\_group\_tags | Tags specific to the AutoScaling Group. Will be merged with var.tags. | `map` | `{}` | no |
| autoscaling\_group\_target\_group\_arns | A list of aws\_alb\_target\_group ARNs, for use with Application or Network Load Balancing. | `list(string)` | `[]` | no |
| autoscaling\_group\_termination\_policies | A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are OldestInstance, NewestInstance, OldestLaunchConfiguration, ClosestToNextInstanceHour, OldestLaunchTemplate, AllocationStrategy, Default. | `list(string)` | `null` | no |
| autoscaling\_group\_wait\_for\_capacity\_timeout | A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. (See also Waiting for Capacity below.) Setting this to '0' causes Terraform to skip all Capacity Waiting behavior. | `string` | `null` | no |
| autoscaling\_group\_wait\_for\_elb\_capacity | Setting this will cause Terraform to wait for exactly this number of healthy instances from this autoscaling group in all attached load balancers on both create and update operations. (Takes precedence over min\_elb\_capacity behavior.) | `number` | `null` | no |
| autoscaling\_group\_termination\_policies | A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `OldestLaunchTemplate`, `AllocationStrategy`, `Default`. | `list(string)` | `[]` | no |
| autoscaling\_group\_wait\_for\_capacity\_timeout | A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. Setting this to '0' causes Terraform to skip all Capacity Waiting behavior. | `string` | `null` | no |
| autoscaling\_group\_wait\_for\_elb\_capacity | Setting this will cause Terraform to wait for exactly this number of healthy instances from this autoscaling group in all attached load balancers on both create and update operations. (Takes precedence over `var.min_elb_capacity` behavior.). | `number` | `null` | no |
| autoscaling\_schedule\_count | How many AutoScaling Schedule actions to create on the AutoScaling Group. Ignored if `var.use_autoscaling_group` is `false`. | `number` | `0` | no |
| autoscaling\_schedule\_desired\_capacities | Number of instances that should run in the AutoScaling Schedule actions. Set to -1 if you don't want to change the desired capacity at the scheduled time. Ignored if `var.use_autoscaling_group` or `var.autoscaling_schedule_enable` is `false`. | `list(number)` | <pre>[<br> 0<br>]</pre> | no |
| autoscaling\_schedule\_end\_times | Time for the AutoScaling Schedule actions to stop, in `YYYY-MM-DDThh:mm:ssZ` format in UTC/GMT only (for example, `2022-06-01T00:00:00Z` ). If you try to schedule your action in the past, Auto Scaling returns an error message. Ignored if `var.use_autoscaling_group` or `var.autoscaling_schedule_enable` is `false`. | `list(string)` | <pre>[<br> null<br>]</pre> | no |
| autoscaling\_schedule\_max\_sizes | The maximum sizes for the AutoScaling Schedule actions. Set to -1 if you don't want to change the maximum size at the scheduled time. Ignored if `var.use_autoscaling_group` or `var.autoscaling_schedule_enable` is `false`. | `list(number)` | <pre>[<br> 0<br>]</pre> | no |
| autoscaling\_schedule\_min\_sizes | The minimum sizes for the AutoScaling Schedule actions. Set to -1 if you don't want to change the minimum size at the scheduled time. Ignored if `var.use_autoscaling_group` or `var.autoscaling_schedule_enable` is `false`. | `list(number)` | <pre>[<br> 0<br>]</pre> | no |
| autoscaling\_schedule\_name | Name of the AutoScaling Schedule actions. Will be suffixed by numerical digits if `var.use_num_suffix` is `true`. If `var.use_num_suffix` is `false` maximum one Schedule must be created as name must be unique. Ignored if `var.use_autoscaling_group` or `var.autoscaling_schedule_enable` is `false`. | `string` | `"asg-schedule"` | no |
| autoscaling\_schedule\_recurrences | Times when recurring future AutoScaling Schedule actions will start. Start time is specified by the user following the Unix cron syntax format. Ignored if `var.use_autoscaling_group` or `var.autoscaling_schedule_enable` is `false`. | `list(string)` | <pre>[<br> null<br>]</pre> | no |
| autoscaling\_schedule\_start\_times | Time for the AutoScaling Schedule actions to start, in `YYYY-MM-DDThh:mm:ssZ` format in UTC/GMT only (for example, `2021-06-01T00:00:00Z` ). Defaults to the next minute. If you try to schedule your action in the past, Auto Scaling returns an error message. Ignored if `var.use_autoscaling_group` or `var.autoscaling_schedule_enable` is `false`. | `list(string)` | <pre>[<br> null<br>]</pre> | no |
| cpu\_core\_count | Sets the number of CPU cores for an instance (or launch template). This option is only supported on creation of instance type that support CPU Options CPU Cores and Threads Per CPU Core Per Instance Type - specifying this option for unsupported instance types will return an error from the EC2 API. | `number` | `null` | no |
| cpu\_credits | The credit option for CPU usage. Can be 'standard' or 'unlimited'. T3 instances are launched as unlimited by default. T2 instances are launched as standard by default. | `string` | `null` | no |
| cpu\_threads\_per\_core | (has no effect unless var.cpu\_core\_count is also set) If set to to 1, hyperthreading is disabled on the launched instance (or launch template). Defaults to 2 if not set. See Optimizing CPU Options for more information. | `number` | `null` | no |
| disable\_api\_termination | If true, enables EC2 Instance (or launch template) Termination Protection. This is NOT recommended as it will prevent Terraform to destroy and potentially block your pipeline. | `bool` | `false` | no |
| ebs\_optimized | If true, the launched EC2 instance (or launch template) will be EBS-optimized. Note that if this is not set on an instance type that is optimized by default then this will show as disabled but if the instance type is optimized by default then there is no need to set this and there is no effect to disabling it. | `bool` | `false` | no |
| ec2\_external\_primary\_network\_insterface\_id | IDs of the primary network interface to be attached to ec2 instances. | `list` | `[]` | no |
| cpu\_credits | The credit option for CPU usage. Can be `standard` or `unlimited`. For T type instances. T3 instances are launched as unlimited by default. T2 instances are launched as standard by default. | `string` | `null` | no |
| cpu\_threads\_per\_core | If set to to 1, hyperthreading is disabled on the launched instance (or launch template). Defaults to 2 if not set. See Optimizing CPU Options for more information (has no effect unless `var.cpu_core_count` is also set). | `number` | `null` | no |
| disable\_api\_termination | If true, enables EC2 Instance (or launch template) termination protection. **This is NOT recommended** as it will prevent Terraform to destroy and block your pipeline. | `bool` | `false` | no |
| ebs\_optimized | If true, the launched EC2 instance (or launch template) will be EBS-optimized. Note that if this is not set on an instance type that is optimized by default then this will show as disabled but if the instance type is optimized by default then there is no need to set this and there is no effect to disabling it. | `bool` | `null` | no |
| ec2\_external\_primary\_network\_interface\_id | ID of the primary Network Interface to be attached to EC2 instance. This value must be given if `var.ec2_primary_network_interface_create` is `false`. | `string` | `null` | no |
| ec2\_ipv4\_addresses | Specify one or more IPv4 addresses from the range of the subnet to associate with the primary network interface. | `list(string)` | `[]` | no |
| ec2\_ipv6\_addresses | Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface. | `list(string)` | `[]` | no |
| ec2\_network\_interface\_name | Name of the primary network interfaces. | `string` | `"nic"` | no |
| ec2\_network\_interface\_tags | Tags of the primary ENI of the instance. Will be merged with tags. | `map` | `{}` | no |
| ec2\_private\_ips | Private IPs of the instances. If set, the list must contain as many IP as the number of var.instance\_count. Careful: this list is one IP / instance. See var.ec2\_ipv4\_addresses for multiple IPs / instance. | `list(string)` | `null` | no |
| ec2\_network\_interface\_tags | Tags of the primary Network Interface of the EC2 instance. Will be merged with `var.tags`. | `map` | `{}` | no |
| ec2\_primary\_network\_interface\_create | Whether or not to create a primary Network Interface to be attached to EC2 instance. Ignored if `var.use_autoscaling_group` is `true`. If `false`, a value for `var.ec2_external_primary_network_interface_id` will be expected. | `bool` | `true` | no |
| ec2\_source\_dest\_check | Controls if traffic is routed to the instance when the destination address does not match the instance. Used for NAT or VPNs. | `bool` | `true` | no |
| ec2\_volume\_name | Tag name of the root block device of the instance. | `string` | `"root-volume"` | no |
| ec2\_volume\_tags | Tags of the root volume of the instance. Will be merged with tags. | `map` | `{}` | no |
| ec2\_subnet\_id | Subnet ID where to provision all the instance. Can be used instead or along with var.subnet\_ids. | `any` | `null` | no |
| ec2\_use\_default\_subnet | Whether or not to use the VPC default subnet instead of `var.ec2_subnet_id`. Cannot be computed from `var.ec2_subnet_id` automatically in Terraform 0.13. | `bool` | `true` | no |
| ec2\_volume\_name | Name (tag:Name) of the root block device of the instance. | `string` | `"root-volume"` | no |
| ec2\_volume\_tags | Tags of the root volume of the instance. Will be merged with `var.tags`. | `map` | `{}` | no |
| ephemeral\_block\_devices | Customize Ephemeral (also known as Instance Store) volumes on the instance (or launch template):<br> * device\_name (required, string): The name of the block device to mount on the instance.<br> * virtual\_name (optional, string): The Instance Store Device Name (e.g. "ephemeral0").<br> * no\_device (optional, string): Suppresses the specified device included in the AMI's block device mapping. | `list` | `[]` | no |
| external\_volume\_count | Number of external volumes to create. | `number` | `0` | no |
| external\_volume\_device\_names | Device names for the external volumes. | `list(string)` | <pre>[<br> ""<br>]</pre> | no |
| external\_volume\_name | Prefix of the external volumes to create. | `string` | `"extra-volumes"` | no |
| external\_volume\_num\_suffix\_offset | The starting point of the numerical suffix for external volumes. Will combine with var.num\_suffix\_offset. An offset of 1 here and num\_suffix\_offset of 2 would mean external volumes resources suffix starts at 4. | `number` | `1` | no |
| external\_volume\_sizes | Size of the external volumes. | `list(number)` | <pre>[<br> null<br>]</pre> | no |
| external\_volume\_tags | Tags for the external volumes. Will be merged with tags. Tags will be shared among all external volumes. | `map` | `{}` | no |
| external\_volume\_types | The type of EBS volume. Can be 'standard', 'gp2', 'io1', 'sc1' or 'st1' (Default: 'gp2'). | `list(string)` | <pre>[<br> null<br>]</pre> | no |
| extra\_network\_interface\_count | How many extra network interface to create per instance. This has no influence on the default network interface. | `number` | `0` | no |
| extra\_network\_interface\_eips\_count | How many extra network interfaces will have a public elastic IP. Should be the exact number of “true” in the var.extra\_network\_interface\_eips\_enabled list. | `number` | `0` | no |
| extra\_network\_interface\_eips\_enabled | Respectively, for each instance, a list of boolean that indicates whether or not the extra network interface should have an elastic IP or not. Should have as many “true” as var.extra\_network\_interface\_eips\_count. | `list(bool)` | `[]` | no |
| extra\_network\_interface\_name | Name of the extra network interfaces. | `string` | `"nic"` | no |
| extra\_network\_interface\_num\_suffix\_offset | The starting point of the numerical suffix for extra network interfaces. Will combine with var.num\_suffix\_offset. An offset of 1 here and num\_suffix\_offset of 2 would mean extra nic resources suffix starts at 4. | `number` | `1` | no |
| extra\_network\_interface\_private\_ips | List of private IPs to assign to the extra ENIs. Make sure you have as many element in the list as ENIs times the number of instances. | `list(list(string))` | <pre>[<br> null<br>]</pre> | no |
| extra\_network\_interface\_count | How many extra network interface to create for the EC2 instance. This has no influence on the primary Network Interface. Ignored if `var.use_autoscaling_group` is `true`. | `number` | `0` | no |
| extra\_network\_interface\_eips\_count | How many extra Network Interfaces will have a public Elastic IP. Should be the exact number of `true`s in the `var.extra_network_interface_eips_enabled` list. Ignored if `var.use_autoscaling_group` is `true`. | `number` | `0` | no |
| extra\_network\_interface\_eips\_enabled | List of boolean that indicates whether or not the extra Network Interface should have an Elastic IP or not. To disable/enable the EIP for specific NICs, use `false`/`true` respectively of the order of extra Network Interfaces. Should have as many `true`s as the number define in `var.extra_network_interface_eips_count`. Ignored if `var.use_autoscaling_group` is `true`. | `list(bool)` | `[]` | no |
| extra\_network\_interface\_name | Name (tag:Name) of the extra Network Interfaces for the EC2 instance. Will be suffixed by numerical digits if `var.use_num_suffix` is `true`, otherwise all extra Network Interfaces will have the same name. | `string` | `"nic"` | no |
| extra\_network\_interface\_num\_suffix\_offset | The starting point of the numerical suffix for extra Network Interfaces for the EC2 instance. Will combine with `var.num_suffix_offset`. An offset of `1` here and `var.num_suffix_offset` of `2` would mean `var.extra_network_interface_name` suffix starts at `4`. Default value is `1` to let the primary Network Interface have the starting suffix. | `number` | `1` | no |
| extra\_network\_interface\_private\_ips | List of lists containing private IPs to assign to the extra Network Interfaces for the EC2 instance. Each list must correspond to an extra Network Interface, in order. | `list(list(string))` | <pre>[<br> null<br>]</pre> | no |
| extra\_network\_interface\_private\_ips\_counts | Number of secondary private IPs to assign to the ENI. The total number of private IPs will be 1 + private\_ips\_count, as a primary private IP will be assigned to an ENI by default. Make sure you have as many element in the list as ENIs times the number of instances. | `list(number)` | <pre>[<br> null<br>]</pre> | no |
| extra\_network\_interface\_security\_group\_count | How many security groups to attach per extra ENI. This cannot be computed automatically from var.extra\_network\_interface\_security\_group\_ids in terraform 0.12. | `number` | `0` | no |
| extra\_network\_interface\_security\_group\_ids | List of security group IDs to assign to the extra ENIs. All ENIs will have the same security groups. | `list(list(string))` | `null` | no |
| extra\_network\_interface\_source\_dest\_checks | Whether to enable source destination checking for the extra ENIs. Default true. | `list(bool)` | <pre>[<br> null<br>]</pre> | no |
| extra\_network\_interface\_tags | Tags for the extra ENIs. Will be merged with var.tags. These tags will be shared among all extra ENIs. | `map` | `{}` | no |
| extra\_network\_interface\_security\_group\_count | How many Security Groups to attach per extra Network Interface. Must be the number of element of `var.extra_network_interface_security_group_ids`. This cannot be computed automatically in Terraform 0.13. | `number` | `0` | no |
| extra\_network\_interface\_security\_group\_ids | List of Security Group IDs to assign to the extra Network Interfaces for the EC2 instance. All extra Network Interfaces will have the same Security Groups. If not specified, all ENI will have the `default` Security Group of the VPC. | `list(string)` | `null` | no |
| extra\_network\_interface\_source\_dest\_checks | Whether or not to enable source destination checking for the extra Network Interfaces for the EC2 instance. Default to `true`. | `list(bool)` | <pre>[<br> null<br>]</pre> | no |
| extra\_network\_interface\_tags | Tags for the extra Network Interfaces for the EC2 instance. Will be merged with `var.tags`. These tags will be shared among all extra ENIs. | `map` | `{}` | no |
| extra\_volume\_count | Number of extra volumes to create for the instance (or the launch template). | `number` | `0` | no |
| extra\_volume\_device\_names | Device names for the extra volumes to attached to the instance (or the launch template). | `list(string)` | <pre>[<br> "/dev/xvdf1"<br>]</pre> | no |
| extra\_volume\_name | Name (tag:Name) of the extra volumes to create. Will be suffixed by numerical digits if `var.use_num_suffix` is `true`. Otherwise, all the extra volumes will share the same name. | `string` | `"vol"` | no |
| extra\_volume\_sizes | Size of the extra volumes for the instance (or launch template). | `list(number)` | <pre>[<br> 1<br>]</pre> | no |
| extra\_volume\_tags | Tags shared by all the extra volumes of the instance or **all** the volumes of a launch template. Will be merged with `var.tags`. | `map` | `{}` | no |
| extra\_volume\_types | The volume types of extra volumes to attach to the instance (or launch template). Can be `standard`, `gp2`, `io1`, `sc1` or `st1` (Default: `standard`). | `list(string)` | <pre>[<br> "gp2"<br>]</pre> | no |
| host\_id | The Id of a dedicated host that the instance will be assigned to. Use when an instance (or launch template) is to be launched on a specific dedicated host. | `string` | `null` | no |
| iam\_instance\_profile\_create | Whether or not to create an instance profile for the virtual machines. | `bool` | `false` | no |
| iam\_instance\_profile\_external\_name | Name of an instance profile to be used by the virtual machines. If this value is given, this will be used instead of creating a new instance profile. | `string` | `null` | no |
| iam\_instance\_profile\_iam\_role\_description | The description of the instance profile role. | `string` | `"Instance profile role"` | no |
| iam\_instance\_profile\_iam\_role\_name | The name of the instance profile role. If omitted, Terraform will assign a random, unique name. | `string` | `null` | no |
| iam\_instance\_profile\_iam\_role\_policy\_arns | The ARNs of the policies you want to apply to the instance profile role. | `list(string)` | `[]` | no |
| iam\_instance\_profile\_iam\_role\_policy\_count | How many policy ARNs there are in var.instance\_profile\_iam\_role\_policy\_arns. This value cannot be computed automatically in Terraform 0.12. | `number` | `0` | no |
| iam\_instance\_profile\_iam\_role\_tags | Tags to be used for the instance profile role. Will be merged with var.tags. | `map` | `{}` | no |
| iam\_instance\_profile\_name | The profile's name. If omitted, Terraform will assign a random, unique name. | `string` | `null` | no |
| iam\_instance\_profile\_path | Path in which to create the profile. Instance profile role will share the same path. | `string` | `"/"` | no |
| instance\_count | Number of instances to create. For AutoScaling Group, this value will be the desired capacity. Setting this value to 0 will disable the module. | `number` | `1` | no |
| instance\_initiated\_shutdown\_behavior | Shutdown behavior for the instance (or launch template). Amazon defaults this to stop for EBS-backed instances and terminate for instance-store instances. Cannot be set on instance-store instances. | `string` | `null` | no |
| instance\_tags | Tags that will be shared with all the instances (or instances launched by the AutoScaling Group). Will be merged with var.tags. | `map` | `{}` | no |
| iam\_instance\_profile\_create | Whether or not to create an Instance Profile (with its IAM Role) for the instance (or launch template). If `false`, you can use `var.iam_instance_profile_name` to use an external IAM Instance Profile. | `bool` | `false` | no |
| iam\_instance\_profile\_iam\_role\_description | Description of the IAM Role to be used by the Instance Profile. Ignored if `var.iam_instance_profile_create` is `false`. | `string` | `"Instance Profile Role"` | no |
| iam\_instance\_profile\_iam\_role\_name | Name of the IAM Role to be used by the Instance Profile. If omitted, Terraform will assign a random, unique name. Ignored if `var.iam_instance_profile_create` is `false`. | `string` | `null` | no |
| iam\_instance\_profile\_iam\_role\_policy\_arns | ARNs of the IAM Policies to be applied to the IAM Role of the Instance Profile. Ignored if `var.iam_instance_profile_create` is `false`. | `list(string)` | `[]` | no |
| iam\_instance\_profile\_iam\_role\_policy\_count | How many IAM Policy ARNs there are in `var.iam_instance_profile_iam_role_policy_arns`. This value cannot be computed automatically in Terraform 0.13. | `number` | `0` | no |
| iam\_instance\_profile\_iam\_role\_tags | Tags to be used for the Instance Profile Role. Will be merged with `var.tags`. Ignored if `var.iam_instance_profile_create` is `false`. | `map` | `{}` | no |
| iam\_instance\_profile\_name | The IAM profile's name for the instance (or launch template). If `var.iam_instance_profile_create` is `true` and this is null, Terraform will assign a random, unique name. If `var.iam_instance_profile_create` is `false` this value should be the name of an external IAM Instance Profile (keep it `null` to disable Instance Profile altogether). | `string` | `null` | no |
| iam\_instance\_profile\_path | Path in which to create the Instance Profile for the instance (or launch template). Instance Profile IAM Role will share the same path. Ignored if `var.iam_instance_profile_create` is `false`. | `any` | `null` | no |
| instance\_initiated\_shutdown\_behavior | Shutdown behavior for the instance (or launch template). Amazon defaults this to `stop` for EBS-backed instances and `terminate` for instance-store instances. Cannot be set on instance-store instances. | `string` | `null` | no |
| instance\_tags | Tags that will be shared with all the instances (or instances launched by the AutoScaling Group). Will be merged with `var.tags`. | `map` | `{}` | no |
| instance\_type | The type of instance (or launch template) to start. Updates to this field will trigger a stop/start of the EC2 instance, except with launch template. | `string` | `"t3.nano"` | no |
| ipv4\_address\_count | A number of IPv4 addresses to associate with the primary network interface of the instances or launch template. The total number of private IPs will be 1 + ipv4\_address\_count, as a primary private IP will be assigned to an ENI by default. | `number` | `0` | no |
| key\_pair\_create | Whether or not to create a key pair. | `bool` | `false` | no |
| key\_pair\_name | The name for the key pair. If this is not null and key\_pair\_create = false, this name will be used as a key pair. | `string` | `null` | no |
| key\_pair\_public\_key | The public key material. | `string` | `null` | no |
| key\_pair\_tags | Tags for the key pair. Will be merged with tags. | `map` | `{}` | no |
| ipv4\_address\_count | A number of IPv4 addresses to associate with the primary network interface of the instance (or launch template). The total number of private IPs will be 1 + `var.ipv4_address_count`, as a primary private IP will be assigned to an ENI by default. | `number` | `0` | no |
| key\_pair\_create | Whether or not to create a key pair. If `false`, use `var.key_pair_name` to inject an external key pair. | `bool` | `false` | no |
| key\_pair\_name | The name for the key pair. If this is not empty and `var.key_pair_create` = `false`, this name will be used as an external key pair. If you don't want any key pair, set this to `null`. | `string` | `null` | no |
| key\_pair\_public\_key | The public key material. Ignored if `var.key_pair_create` is `false`. | `string` | `null` | no |
| key\_pair\_tags | Tags specific for the key pair. Will be merged with `var.tags`. Ignored if `var.key_pair_create` is `false`. | `map` | `{}` | no |
| launch\_template\_ipv6\_address\_count | A number of IPv6 addresses to associate with the primary network interface of the launch template. | `number` | `0` | no |
| launch\_template\_name | The name of the launch template. If you leave this blank, Terraform will auto-generate a unique name. | `string` | `""` | no |
| launch\_template\_tags | Tags to be used by the launch template. Will be merge with var.tags. | `map` | `{}` | no |
| monitoring | If true, the launched EC2 instances (or launch template) will have detailed monitoring enabled: 1 minute granularity instead of 5 minutes. Incurs additional costs. | `bool` | `false` | no |
| name | Name prefix of the instances themselves (tag:Name) whether or not AutoScaling group is used. If enabled, will be suffixed by a var.num\_suffix\_digits count index. | `string` | `""` | no |
| num\_suffix\_digits | Number of significant digits to append to all resources of the module. | `number` | `2` | no |
| num\_suffix\_offset | The starting point of the numerical suffix. An offset of 1 would mean resources suffix starts at 2. | `number` | `0` | no |
| placement\_group | The Placement Group to start the instances (or launch template) in. | `string` | `null` | no |
| prefix | Prefix to be merge with all resources of the module except `iam_instance_profile_name` and `iam_instance_profile_iam_role_name`. | `string` | `""` | no |
| root\_block\_device\_delete\_on\_termination | Whether or not to delete the root block device on termination. \*\*Note: It's is strongly discouraged to set this to false, only change this value if you have no other choice as this will leave a volume that will not be managed by terraform (even if the tag says it does) and you may end up building up costs.\*\* | `bool` | `true` | no |
| root\_block\_device\_encrypted | Customize details about the root block device of the instance or launch template root volume: Enables EBS encryption on the volume (Default: true). Cannot be used with snapshot\_id. Must be configured to perform drift detection. | `string` | `true` | no |
| root\_block\_device\_iops | The amount of provisioned IOPS. This must be set with a volume\_type of 'io1'. | `string` | `null` | no |
| root\_block\_device\_volume\_size | Customize details about the root block device of the instance or launch template root volume: The size of the volume in gibibytes (GiB). | `string` | `null` | no |
| root\_block\_device\_volume\_type | Customize details about the root block device of the instance or launch template root volume: The type of volume. Can be 'standard', 'gp2', or 'io1'. (Default: 'gp2'). | `string` | `null` | no |
| subnet\_id | Subnet ID where to provision all the instances (or launch template). Can be used instead or along with var.subnet\_ids. | `string` | `""` | no |
| subnet\_ids | Subnet IDs where to provision the instances (or launch template). Can be used instead or along with var.subnet\_id. | `list(string)` | <pre>[<br> ""<br>]</pre> | no |
| subnet\_ids\_count | How many subnet IDs in subnet\_ids. Cannot be computed automatically from other variables in Terraform 0.12.X. | `number` | `0` | no |
| tags | Tags to be used for all this module resources. Will be merged with specific tags. | `map` | `{}` | no |
| tenancy | The tenancy of the instance (if the instance or launch template will be running in a VPC). An instance with a tenancy of dedicated runs on single-tenant hardware. The host tenancy is not supported for the import-instance command. | `string` | `"default"` | no |
| use\_autoscaling\_group | Whether or not to create an AutoScaling Group instead of EC2 instances. | `bool` | `false` | no |
| use\_external\_primary\_network\_interface | Use external primary network interface. If this toggle is true, this module will not manage the creation of the primary network interface. | `bool` | `false` | no |
| use\_num\_suffix | Always append numerical suffix to instance name, even if instance\_count is 1. | `bool` | `false` | no |
| monitoring | If `true`, the launched EC2 instance (or launch template) will have detailed monitoring enabled: 1 minute granularity instead of 5 minutes. Incurs additional costs. | `bool` | `false` | no |
| name | Name of the instance(s) themselves (tag:Name) whether or not AutoScaling group is used. | `string` | `"ec2"` | no |
| num\_suffix\_digits | Number of significant digits to append to multiple same resources of the module. For example, a `var.num_suffix_digits` of `3` would produce `-001`, `-002`… suffixes. Ignored if `var.use_num_suffix` is `false`. | `number` | `2` | no |
| num\_suffix\_offset | The starting point of the numerical suffix. An offset of 1 would mean resources suffixes will starts at 2. Ignored if `var.use_num_suffix` is `false`. | `number` | `0` | no |
| placement\_group | ID of the Placement Group to start the instance (or launch template) in. | `string` | `null` | no |
| prefix | Prefix to be added to with all resource's names of the module except `iam_instance_profile_name` and `iam_instance_profile_iam_role_name`. Prefix is mainly used for tests and should remain empty in normal circumstances. | `string` | `""` | no |
| primary\_network\_interface\_name | Name (tag:Name) of the primary network interface to be attached to the instance (or launch template). | `string` | `"nic"` | no |
| root\_block\_device\_delete\_on\_termination | Whether or not to delete the root block device on termination. **It's is strongly discouraged** to set this to `false`: only change this value if you have no other choice as this will leave a volume that will not be managed by terraform (even if the tag says it does) and you may end up building up costs.\*\* | `bool` | `true` | no |
| root\_block\_device\_encrypted | Customize details about the root block device of the instance (or launch template) root volume: enables EBS encryption on the volume. Cannot be used with snapshot\_id. Must be configured to perform drift detection. | `bool` | `true` | no |
| root\_block\_device\_iops | The amount of provisioned IOPS. This must be set when `var.root_block_device_volume_type` is `io1`. | `number` | `null` | no |
| root\_block\_device\_volume\_device | Device name of the root volume of the AMI. Only used for Launch Template. This value cannot be found by the AWS Terraform provider from the AMI ID alone. If this value is wrong, Terraform will create an extra volume, failing to setup root volume correctly. Can be `/dev/sda1` or `/dev/xdva`. | `string` | `"/dev/xvda"` | no |
| root\_block\_device\_volume\_size | Customize details about the root block device of the instance or launch template root volume: The size of the volume in gibibytes (GiB). | `number` | `8` | no |
| root\_block\_device\_volume\_type | Customize details about the root block device of the instance or launch template root volume: The type of volume. Can be `standard`, `gp2`, `io1`, `sc1` or `st1`. (Default: `gp2`). | `string` | `null` | no |
| tags | Tags to be used for all this module resources. Will be merged with specific tags for each kind of resource. | `map` | `{}` | no |
| tenancy | The tenancy of the instance (if the instance or launch template will be running in a VPC). An instance with a tenancy of `dedicated` runs on single-tenant hardware. The `host` tenancy is not supported for the import-instance command. | `any` | `null` | no |
| use\_autoscaling\_group | Whether or not to create an AutoScaling Group instead of an EC2 instance. If `true`, use look at `autoscaling_group` prefixed variables. | `bool` | `false` | no |
| use\_num\_suffix | Whether or not to append numerical suffix when multiple same resources need to be created like extra EBS volumes. | `bool` | `true` | no |
| user\_data | The user data to provide when launching the instance (or launch template). | `string` | `null` | no |
| volume\_kms\_key\_alias | Alias of the KMS key used to encrypt the volumes. DON'T prefix it with alias/ neither a / | `string` | `"default/ec2"` | no |
| volume\_kms\_key\_arn | KMS key used to encrypt the volumes. To be used when var.volume\_kms\_key\_create is set to false. | `string` | `null` | no |
| volume\_kms\_key\_create | Whether or not to create a KMS key to be used for volumes encryption. | `bool` | `false` | no |
| volume\_kms\_key\_customer\_master\_key\_spec | Specifies whether the key contains a symmetric key or an asymmetric key pair and the encryption algorithms or signing algorithms that the key supports for the KMS key to be used for volumes. Valid values: SYMMETRIC\_DEFAULT, RSA\_2048, RSA\_3072, RSA\_4096, ECC\_NIST\_P256, ECC\_NIST\_P384, ECC\_NIST\_P521, or ECC\_SECG\_P256K1. Defaults to SYMMETRIC\_DEFAULT. | `string` | `null` | no |
| volume\_kms\_key\_name | Name prefix for the KMS key to be used for volumes. Will be suffixes with a two-digit count index. | `string` | `null` | no |
| volume\_kms\_key\_policy | A valid policy JSON document for the KMS key to be used for volumes. | `string` | `null` | no |
| volume\_kms\_key\_tags | Tags for the KMS key to be used for volumes. Will be merge with var.tags. | `map` | `{}` | no |
| vpc\_security\_group\_ids | An list containing the list of security group IDs to associate with the main ENI of each instance (or launch template). If not defined, default the VPC security group will be used. | `list(list(string))` | `null` | no |
| volume\_kms\_key\_alias | Alias of the KMS key used to encrypt the root and extra volumes of the instance (or launch template). Do not prefix this value with `alias/` nor with a `/`. | `string` | `"default/ec2"` | no |
| volume\_kms\_key\_arn | ARN of an external KMS key used to encrypt the root and extra volumes. To be used when var.volume\_kms\_key\_create is set to false” (if “true”, this ARN will be ignored). | `string` | `null` | no |
| volume\_kms\_key\_create | Whether or not to create a KMS key to be used for root and extra volumes. If set to `false`, you can specify a `var.volume_kms_key_arn` as an external KMS key to use instead. If this value is `false` and `var.volume_kms_key_arn` empty, the default AWS KMS key for volumes will be used. | `bool` | `false` | no |
| volume\_kms\_key\_customer\_master\_key\_spec | Specifies whether the key contains a symmetric key or an asymmetric key pair and the encryption algorithms or signing algorithms that the key supports for the KMS key to be used for volumes. Valid values: `SYMMETRIC_DEFAULT`, `RSA_2048`, `RSA_3072`, `RSA_4096`, `ECC_NIST_P256`, `ECC_NIST_P384`, `ECC_NIST_P521`, or `ECC_SECG_P256K1`. Defaults to `SYMMETRIC_DEFAULT`. | `string` | `null` | no |
| volume\_kms\_key\_name | Name (tag:Name) for the KMS key to be used for root and extra volumes of the instance (or launch template). | `string` | `"kms-for-vol"` | no |
| volume\_kms\_key\_policy | A valid policy JSON document for the KMS key to be used for root and extra volumes of the instance (or launch template). This document can give or restrict accesses for the key. | `string` | `null` | no |
| volume\_kms\_key\_tags | Tags for the KMS key to be used for root and extra volumes. Will be merge with `var.tags`. | `map` | `{}` | no |
| vpc\_security\_group\_ids | List of security group IDs to associate with the main ENI of the instance (or launch template). If not defined, default the VPC security group will be used. | `list(string)` | `null` | no |

## Outputs

@@ -155,25 +162,21 @@ That’s why every extra volumes within an AutoScaling group will always be dest
| autoscaling\_group\_arn | n/a |
| autoscaling\_group\_id | n/a |
| availability\_zones | n/a |
| ec2\_arns | n/a |
| ec2\_ids | n/a |
| ec2\_primary\_network\_interface\_ids | n/a |
| ec2\_arn | n/a |
| ec2\_id | n/a |
| ec2\_primary\_network\_interface\_id | n/a |
| ec2\_private\_dns | n/a |
| ec2\_private\_ips | n/a |
| ec2\_private\_ip | n/a |
| ec2\_public\_dns | n/a |
| ec2\_public\_ips | n/a |
| ec2\_public\_ip | n/a |
| eip\_ids | n/a |
| eip\_network\_interfaces | n/a |
| eip\_private\_dns | n/a |
| eip\_private\_ips | n/a |
| eip\_public\_dns | n/a |
| eip\_public\_ips | n/a |
| external\_volume\_arns | n/a |
| external\_volume\_ids | n/a |
| extra\_network\_interface\_ids | n/a |
| extra\_network\_interface\_mac\_addresses | n/a |
| extra\_network\_interface\_private\_ips | n/a |
| extra\_network\_interface\_public\_ips | n/a |
| extra\_volume\_arns | n/a |
| extra\_volume\_ids | n/a |
| iam\_instance\_profile\_arn | n/a |
| iam\_instance\_profile\_iam\_role\_arn | n/a |
| iam\_instance\_profile\_iam\_role\_id | n/a |
@@ -188,6 +191,9 @@ That’s why every extra volumes within an AutoScaling group will always be dest
| launch\_template\_default\_version | n/a |
| launch\_template\_id | n/a |
| launch\_template\_latest\_version | n/a |
| network\_interface\_ids | n/a |
| network\_interface\_mac\_addresses | n/a |
| network\_interface\_private\_ips | n/a |
| subnet\_ids | n/a |

<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

+ 24
- 17
data.tf View File

@@ -2,44 +2,51 @@
# Defaults
####

data "aws_region" "current" {
count = var.instance_count > 0 ? 1 : 0
locals {
should_fetch_default_subnet = local.use_default_subnets
should_fetch_default_security_group = var.vpc_security_group_ids == null
should_fetch_default_vpc = local.should_fetch_default_subnet || local.should_fetch_default_security_group
should_fetch_default_ami = var.ami == null
}

data "aws_availability_zones" "default" {
count = local.should_fetch_default_subnet ? 1 : 0

state = "available"
}

data "aws_vpc" "default" {
count = local.use_default_subnets ? 1 : 0
count = local.should_fetch_default_vpc ? 1 : 0

default = true
}

data "aws_subnet_ids" "default" {
count = local.use_default_subnets ? 1 : 0
count = local.should_fetch_default_subnet ? length(data.aws_availability_zones.default.*.names[0]) : 0

vpc_id = data.aws_vpc.default.*.id[0]

filter {
name = "availability-zone"
values = ["${element(concat(data.aws_region.current.*.name, [""]), 0)}a", "${element(concat(data.aws_region.current.*.name, [""]), 0)}b"]
values = [element(data.aws_availability_zones.default.*.names[0], count.index)]
}
}

data "aws_security_group" "default" {
count = var.instance_count > 0 && var.vpc_security_group_ids == null ? 1 : 0
count = local.should_fetch_default_security_group ? 1 : 0

vpc_id = local.vpc_id
vpc_id = data.aws_vpc.default.*.id[0]
name = "default"
}

####
# Subnets
####
// This is needed to circumvent:
// https://github.com/terraform-providers/terraform-provider-aws/issues/1352

data "aws_subnet" "subnets" {
count = local.subnet_count
data "aws_subnet" "current" {
count = length(local.subnet_ids)

id = element(local.subnet_ids, count.index)
id = local.subnet_ids[count.index]
}

####
@@ -47,12 +54,12 @@ data "aws_subnet" "subnets" {
####

data "null_data_source" "ebs_block_device" {
count = var.instance_count > 0 ? var.external_volume_count : 0
count = var.extra_volume_count

inputs = {
device_name = element(var.external_volume_device_names, count.index)
type = element(var.external_volume_types, count.index)
size = element(var.external_volume_sizes, count.index)
device_name = element(var.extra_volume_device_names, count.index)
type = element(var.extra_volume_types, count.index)
size = element(var.extra_volume_sizes, count.index)
}
}

@@ -80,7 +87,7 @@ data "aws_iam_policy_document" "sts_instance" {
####

data "aws_ssm_parameter" "default_ami" {
count = var.instance_count > 0 ? 1 : 0
count = local.should_fetch_default_ami ? 1 : 0

name = "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
}

+ 145
- 128
main.tf View File

@@ -1,39 +1,35 @@
locals {
should_update_root_device = var.root_block_device_volume_type != null || var.root_block_device_volume_size != null || var.root_block_device_encrypted == true || var.root_block_device_iops != null
use_incremental_names = var.instance_count > 1 || (var.use_num_suffix && var.num_suffix_digits > 0)
use_default_subnets = var.instance_count > 0 && var.subnet_ids_count == 0

used_subnet_count = floor(min(local.subnet_count, var.instance_count))
use_incremental_names = var.use_num_suffix && var.num_suffix_digits > 0
num_suffix_starting_index = var.num_suffix_offset + 1

subnet_count = local.use_default_subnets ? length(data.aws_subnet_ids.default.*.ids) : var.subnet_ids_count
subnet_ids = split(",", local.use_default_subnets ? join(",", tolist(element(concat(data.aws_subnet_ids.default.*.ids, [""]), 0))) : join(",", distinct(compact(concat([var.subnet_id], var.subnet_ids)))))
vpc_id = element(concat(data.aws_subnet.subnets.*.vpc_id, [""]), 0)
use_default_subnets = var.use_autoscaling_group ? var.autoscaling_group_subnet_ids_count == 0 : var.ec2_use_default_subnet

tags = {
Terraform = true
managed-by = "Terraform"
}
subnet_ids = var.use_autoscaling_group ? (local.use_default_subnets ? flatten(data.aws_subnet_ids.default.*.ids) : var.autoscaling_group_subnet_ids) : (local.use_default_subnets ? [flatten(data.aws_subnet_ids.default.*.ids)[0]] : [var.ec2_subnet_id])
availability_zones = data.aws_subnet.current.*.availability_zone

security_group_ids = var.vpc_security_group_ids != null ? var.vpc_security_group_ids : (tolist([data.aws_security_group.default.*.id]))
iam_instance_profile = local.should_use_external_instance_profile ? var.iam_instance_profile_external_name : (local.should_create_instance_profile ? aws_iam_instance_profile.this.*.name[0] : null)
kms_key_arn = var.volume_kms_key_create ? aws_kms_key.this[0].arn : var.volume_kms_key_arn
security_group_ids = local.should_fetch_default_security_group ? data.aws_security_group.default.*.id : var.vpc_security_group_ids

num_suffix_starting_index = var.num_suffix_offset + 1
ami = var.ami != null ? var.ami : concat(data.aws_ssm_parameter.default_ami.*.value, [""])[0]

ami = var.ami != "" ? var.ami : concat(data.aws_ssm_parameter.default_ami.*.value, [""])[0]
tags = {
managed-by = "Terraform"
}
}

####
# AutoScaling Group
# Launch Template
####

resource "aws_launch_template" "this" {
count = var.use_autoscaling_group && var.instance_count > 0 ? 1 : 0
count = var.use_autoscaling_group ? 1 : 0

name = format("%s%s", var.prefix, var.launch_template_name)

name = format("%s%s", var.prefix, local.use_incremental_names ? format("%s-%0${var.num_suffix_digits}d", var.launch_template_name, count.index + local.num_suffix_starting_index) : var.launch_template_name)
image_id = local.ami
instance_type = var.instance_type
key_name = local.should_create_key_pair ? aws_key_pair.this.*.key_name[0] : var.key_pair_name
key_name = local.key_pair_name

user_data = var.user_data

@@ -71,7 +67,7 @@ resource "aws_launch_template" "this" {
for_each = local.should_update_root_device ? [1] : []

content {
device_name = "/dev/sda1"
device_name = var.root_block_device_volume_device

ebs {
delete_on_termination = true
@@ -79,7 +75,7 @@ resource "aws_launch_template" "this" {
iops = var.root_block_device_iops
volume_size = var.root_block_device_volume_size
volume_type = var.root_block_device_volume_type
kms_key_id = local.kms_key_arn
kms_key_id = local.volume_kms_key_arn
}
}
}
@@ -95,7 +91,7 @@ resource "aws_launch_template" "this" {
encrypted = true
volume_size = lookup(block_device_mappings.value.outputs, "size", null)
volume_type = lookup(block_device_mappings.value.outputs, "type", null)
kms_key_id = local.kms_key_arn
kms_key_id = local.volume_kms_key_arn
}
}
}
@@ -111,10 +107,10 @@ resource "aws_launch_template" "this" {
}

dynamic "iam_instance_profile" {
for_each = local.iam_instance_profile != null ? [1] : []
for_each = local.iam_instance_profile_name != null ? [1] : []

content {
name = local.iam_instance_profile
name = local.iam_instance_profile_name
}
}

@@ -127,9 +123,9 @@ resource "aws_launch_template" "this" {
}

network_interfaces {
description = format("%s%s", var.prefix, local.use_incremental_names ? "${format("%s-%0${var.num_suffix_digits}d", var.name, count.index + local.num_suffix_starting_index)} root network interface" : "${var.name} root network interface")
description = format("%s%s", var.prefix, local.use_incremental_names ? "${format("%s-%0${var.num_suffix_digits}d", var.primary_network_interface_name, count.index + local.num_suffix_starting_index)} root network interface" : "${var.primary_network_interface_name} root network interface")

security_groups = local.security_group_ids[0]
security_groups = local.security_group_ids
associate_public_ip_address = var.associate_public_ip_address
ipv6_address_count = var.launch_template_ipv6_address_count
ipv4_address_count = var.ipv4_address_count
@@ -140,7 +136,7 @@ resource "aws_launch_template" "this" {
for_each = var.placement_group != null ? [1] : []

content {
availability_zone = data.aws_subnet.subnets.*.availability_zone[0]
availability_zone = local.availability_zones[0]
group_name = var.placement_group
tenancy = var.tenancy
host_id = var.host_id
@@ -152,7 +148,7 @@ resource "aws_launch_template" "this" {

tags = merge(
{
"Name" = format("%s%s", var.prefix, local.use_incremental_names ? format("%s-%0${var.num_suffix_digits}d", var.name, count.index + local.num_suffix_starting_index) : var.name)
"Name" = format("%s%s", var.prefix, var.name)
},
var.tags,
var.instance_tags,
@@ -164,41 +160,45 @@ resource "aws_launch_template" "this" {

tags = merge(
{
"Name" = format("%s%s", var.prefix, var.external_volume_name)
"Name" = format("%s%s", var.prefix, local.use_incremental_names ? format("%s-%0${var.num_suffix_digits}d", var.extra_volume_name, local.num_suffix_starting_index) : var.extra_volume_name)
},
var.tags,
var.external_volume_tags,
var.extra_volume_tags,
local.tags,
)
}

lifecycle {
// credit_specification breaks idempotency (0.12.24 - AWS 2.59.0)
ignore_changes = [
credit_specification,
]
}
// lifecycle {
// // credit_specification breaks idempotency (0.12.24 - AWS 2.59.0)
// ignore_changes = [
// credit_specification,
// ]
// }
}

####
# AutoScaling Group
####

resource "aws_autoscaling_group" "this" {
count = var.use_autoscaling_group && var.instance_count > 0 ? 1 : 0
count = var.use_autoscaling_group ? 1 : 0

name = format("%s%s", var.prefix, (var.use_num_suffix && var.num_suffix_digits > 0) ? format("%s-%0${var.num_suffix_digits}d", var.autoscaling_group_name, count.index + local.num_suffix_starting_index) : var.autoscaling_group_name)
name = format("%s%s", var.prefix, var.autoscaling_group_name)

desired_capacity = var.instance_count
desired_capacity = var.autoscaling_group_desired_capacity
max_size = var.autoscaling_group_max_size
min_size = var.autoscaling_group_min_size

health_check_grace_period = var.autoscaling_group_health_check_grace_period
health_check_grace_period = var.autoscaling_group_health_check_grace_period == -1 ? null : var.autoscaling_group_health_check_grace_period
health_check_type = var.autoscaling_group_health_check_type
default_cooldown = var.autoscaling_group_default_cooldown
default_cooldown = var.autoscaling_group_default_cooldown == -1 ? null : var.autoscaling_group_default_cooldown

force_delete = false
wait_for_capacity_timeout = var.autoscaling_group_wait_for_capacity_timeout
min_elb_capacity = var.autoscaling_group_min_elb_capacity
wait_for_elb_capacity = var.autoscaling_group_wait_for_elb_capacity

vpc_zone_identifier = data.aws_subnet.subnets.*.id
vpc_zone_identifier = local.subnet_ids

launch_template {
id = aws_launch_template.this.*.id[0]
@@ -239,12 +239,32 @@ resource "aws_autoscaling_group" "this" {
}

resource "aws_autoscaling_attachment" "this" {
count = var.use_autoscaling_group && var.instance_count > 0 ? length(var.autoscaling_group_target_group_arns) : 0
count = var.use_autoscaling_group ? length(var.autoscaling_group_target_group_arns) : 0

autoscaling_group_name = aws_autoscaling_group.this.*.id[0]
alb_target_group_arn = element(var.autoscaling_group_target_group_arns, count.index)
}

resource "aws_autoscaling_schedule" "this" {
count = var.use_autoscaling_group ? var.autoscaling_schedule_count : 0

scheduled_action_name = local.use_incremental_names ? format("%s-%0${var.num_suffix_digits}d", var.autoscaling_schedule_name, count.index + local.num_suffix_starting_index) : var.autoscaling_schedule_name
min_size = element(var.autoscaling_schedule_min_sizes, count.index)
max_size = element(var.autoscaling_schedule_max_sizes, count.index)
desired_capacity = element(var.autoscaling_schedule_desired_capacities, count.index)
recurrence = element(var.autoscaling_schedule_recurrences, count.index)
start_time = element(var.autoscaling_schedule_start_times, count.index) != null ? element(var.autoscaling_schedule_start_times, count.index) : timeadd(timestamp(), "1m")
end_time = element(var.autoscaling_schedule_end_times, count.index)

autoscaling_group_name = aws_autoscaling_group.this.*.name[0]

lifecycle {
ignore_changes = [
start_time,
]
}
}

####
# EC2
####
@@ -254,12 +274,12 @@ locals {
}

resource "aws_instance" "this" {
count = var.use_autoscaling_group ? 0 : var.instance_count
count = var.use_autoscaling_group ? 0 : 1

ami = local.ami
instance_type = var.instance_type
user_data = var.user_data
key_name = local.should_create_key_pair ? aws_key_pair.this.*.key_name[0] : var.key_pair_name
key_name = local.key_pair_name
monitoring = var.monitoring
host_id = var.host_id

@@ -268,15 +288,15 @@ resource "aws_instance" "this" {

network_interface {
device_index = 0
network_interface_id = var.use_external_primary_network_interface ? element(var.ec2_external_primary_network_insterface_id, count.index) : element(aws_network_interface.this_primary.*.id, count.index)
network_interface_id = local.primary_eni_id
}

iam_instance_profile = local.iam_instance_profile
iam_instance_profile = local.iam_instance_profile_name

ebs_optimized = var.ebs_optimized
volume_tags = merge(
{
"Name" = format("%s%s", var.prefix, local.use_incremental_names ? format("%s-%0${var.num_suffix_digits}d", var.ec2_volume_name, count.index + (count.index * var.external_volume_count) + local.num_suffix_starting_index) : var.ec2_volume_name)
"Name" = format("%s%s", var.prefix, local.use_incremental_names ? format("%s-%0${var.num_suffix_digits}d", var.ec2_volume_name, count.index + (count.index * var.extra_volume_count) + local.num_suffix_starting_index) : var.ec2_volume_name)
},
var.tags,
var.ec2_volume_tags,
@@ -292,7 +312,7 @@ resource "aws_instance" "this" {
iops = var.root_block_device_iops
volume_size = var.root_block_device_volume_size
volume_type = var.root_block_device_volume_type
kms_key_id = var.volume_kms_key_create ? aws_kms_key.this[0].arn : var.volume_kms_key_arn
kms_key_id = local.volume_kms_key_arn
}
}

@@ -321,7 +341,7 @@ resource "aws_instance" "this" {

tags = merge(
{
"Name" = format("%s%s", var.prefix, local.use_incremental_names ? format("%s-%0${var.num_suffix_digits}d", var.name, count.index + local.num_suffix_starting_index) : var.name)
"Name" = format("%s%s", var.prefix, var.name)
},
var.tags,
var.instance_tags,
@@ -329,9 +349,6 @@ resource "aws_instance" "this" {
)

lifecycle {
# Due to several known issues in Terraform AWS provider related to arguments of aws_instance:
# (eg, https://github.com/terraform-providers/terraform-provider-aws/issues/2036)
# we have to ignore changes in the following arguments
ignore_changes = [
private_ip,
root_block_device,
@@ -341,17 +358,18 @@ resource "aws_instance" "this" {
}

locals {
should_create_primary_eni = var.instance_count > 0 && var.use_autoscaling_group == false && var.use_external_primary_network_interface == false
should_create_primary_eni = var.use_autoscaling_group == false && var.ec2_primary_network_interface_create

primary_eni_id = local.should_create_primary_eni ? aws_network_interface.this_primary.*.id[0] : var.ec2_external_primary_network_interface_id
}

resource "aws_network_interface" "this_primary" {
count = local.should_create_primary_eni ? var.instance_count : 0
count = local.should_create_primary_eni ? 1 : 0

description = format("%s%s", var.prefix, local.use_incremental_names ? "${format("%s-%0${var.num_suffix_digits}d", var.name, count.index + local.num_suffix_starting_index)} root network interface" : "${var.name} root network interface")
subnet_id = element(data.aws_subnet.subnets.*.id, count.index)
security_groups = element(local.security_group_ids, count.index)
subnet_id = local.subnet_ids[0]
security_groups = local.security_group_ids

private_ip = var.ec2_private_ips != null ? element(concat(var.ec2_private_ips, [""]), count.index) : null
private_ips_count = var.ipv4_address_count
private_ips = concat(var.ec2_ipv6_addresses, var.ec2_ipv4_addresses)

@@ -361,9 +379,9 @@ resource "aws_network_interface" "this_primary" {
{
"Name" = format("%s%s", var.prefix, local.use_incremental_names ? format(
"%s-%0${var.num_suffix_digits}d",
var.ec2_network_interface_name,
var.primary_network_interface_name,
count.index + (count.index * var.extra_network_interface_count) + local.num_suffix_starting_index
) : var.ec2_network_interface_name)
) : var.primary_network_interface_name)
},
var.tags,
var.ec2_network_interface_tags,
@@ -382,24 +400,24 @@ resource "aws_network_interface" "this_primary" {
####

locals {
should_create_instance_profile = var.instance_count > 0 && var.iam_instance_profile_create
should_use_external_instance_profile = var.instance_count > 0 && var.iam_instance_profile_external_name != null
should_create_instance_profile = var.iam_instance_profile_create == true

iam_instance_profile_name = local.should_create_instance_profile ? aws_iam_instance_profile.this.*.name[0] : var.iam_instance_profile_name
}

resource "aws_iam_instance_profile" "this" {
count = local.should_create_instance_profile ? 1 : 0

name = var.iam_instance_profile_name
name = var.iam_instance_profile_name != null ? format("%s%s", var.prefix, var.iam_instance_profile_name) : null
path = var.iam_instance_profile_path
// “roles” is known to be deprecated over “role”
// However, using “role” causes idempotency issue for now (terraform 0.12.24; AWS 2.59.0)
roles = [aws_iam_role.this_instance_profile.*.id[0]]

role = aws_iam_role.this_instance_profile.*.id[0]
}

resource "aws_iam_role" "this_instance_profile" {
count = local.should_create_instance_profile ? 1 : 0

name = var.iam_instance_profile_iam_role_name
name = var.iam_instance_profile_iam_role_name != null ? format("%s%s", var.prefix, var.iam_instance_profile_iam_role_name) : null
description = var.iam_instance_profile_iam_role_description
path = var.iam_instance_profile_path
assume_role_policy = data.aws_iam_policy_document.sts_instance.*.json[0]
@@ -423,40 +441,40 @@ resource "aws_iam_role_policy_attachment" "this_instance_profile" {
####

locals {
should_create_primary_eip = var.instance_count > 0 && var.associate_public_ip_address == true && var.use_autoscaling_group == false
should_create_eip_for_extra_network_interfaces = var.instance_count > 0 && var.extra_network_interface_eips_count > 0 && var.use_autoscaling_group == false
should_create_primary_eip = var.associate_public_ip_address == true && var.use_autoscaling_group == false
should_create_eip_for_extra_network_interfaces = var.extra_network_interface_eips_count > 0 && var.use_autoscaling_group == false

network_interface_with_eip_ids = local.should_create_eip_for_extra_network_interfaces ? [
for i, network_interface in aws_network_interface.this :
for i, network_interface in aws_network_interface.this_extra :
network_interface.id
if element(var.extra_network_interface_eips_enabled, i % var.extra_network_interface_count) == true
] : []
}

resource "aws_eip" "this" {
count = local.should_create_primary_eip ? var.instance_count : 0
resource "aws_eip" "this_primary" {
count = local.should_create_primary_eip ? 1 : 0

vpc = true
}

resource "aws_eip_association" "this" {
count = local.should_create_primary_eip ? var.instance_count : 0
resource "aws_eip_association" "this_primary" {
count = local.should_create_primary_eip ? 1 : 0

network_interface_id = element(aws_network_interface.this_primary.*.id, count.index)
allocation_id = element(aws_eip.this.*.id, count.index)
network_interface_id = aws_network_interface.this_primary.*.id[0]
allocation_id = aws_eip.this_primary.*.id[0]
}

resource "aws_eip" "extra" {
count = local.should_create_eip_for_extra_network_interfaces ? var.instance_count * var.extra_network_interface_eips_count : 0
resource "aws_eip" "this_extra" {
count = local.should_create_eip_for_extra_network_interfaces ? var.extra_network_interface_eips_count : 0

vpc = true
}

resource "aws_eip_association" "extra" {
count = local.should_create_eip_for_extra_network_interfaces ? var.instance_count * var.extra_network_interface_eips_count : 0
resource "aws_eip_association" "this_extra" {
count = local.should_create_eip_for_extra_network_interfaces ? var.extra_network_interface_eips_count : 0

network_interface_id = element(local.network_interface_with_eip_ids, count.index)
allocation_id = element(aws_eip.extra.*.id, count.index)
allocation_id = element(aws_eip.this_extra.*.id, count.index)
}

####
@@ -464,7 +482,9 @@ resource "aws_eip_association" "extra" {
####

locals {
should_create_key_pair = var.instance_count > 0 && var.key_pair_create
should_create_key_pair = var.key_pair_create

key_pair_name = local.should_create_key_pair ? aws_key_pair.this.*.key_name[0] : var.key_pair_name
}

resource "aws_key_pair" "this" {
@@ -484,10 +504,12 @@ resource "aws_key_pair" "this" {
####

locals {
should_create_kms_key = var.volume_kms_key_create && (var.root_block_device_encrypted || var.external_volume_count > 0) && var.use_autoscaling_group == false && var.instance_count > 0
should_create_kms_key = var.volume_kms_key_create && (var.root_block_device_encrypted || var.extra_volume_count > 0)

volume_kms_key_arn = local.should_create_kms_key ? aws_kms_key.this_volume.*.arn[0] : var.volume_kms_key_arn
}

resource "aws_kms_key" "this" {
resource "aws_kms_key" "this_volume" {
count = local.should_create_kms_key ? 1 : 0

description = "KMS key for ${format("%s%s", var.prefix, var.name)} instance(s) volume(s)."
@@ -496,7 +518,7 @@ resource "aws_kms_key" "this" {

tags = merge(
{
"Name" = format("%s%s", var.prefix, var.use_num_suffix == true ? format("%s-%0${var.num_suffix_digits}d", var.volume_kms_key_name, count.index + local.num_suffix_starting_index) : var.volume_kms_key_name)
"Name" = format("%s%s", var.prefix, var.volume_kms_key_name)
},
var.tags,
var.volume_kms_key_tags,
@@ -504,51 +526,49 @@ resource "aws_kms_key" "this" {
)
}

resource "aws_kms_alias" "this" {
resource "aws_kms_alias" "this_extra_volume" {
count = local.should_create_kms_key ? 1 : 0

name = format("alias/%s%s", var.prefix, var.volume_kms_key_alias)
target_key_id = aws_kms_key.this[0].key_id
target_key_id = aws_kms_key.this_volume[0].key_id
}

####
# EBS
# Extra EBS
####

locals {
external_volume_use_incremental_names = var.external_volume_count * var.instance_count > 1 || var.use_num_suffix == true
should_create_extra_volumes = var.external_volume_count > 0 && var.instance_count > 0 && var.use_autoscaling_group == false
external_volume_num_suffix_starting_index = local.num_suffix_starting_index + var.external_volume_num_suffix_offset
should_create_extra_volumes = var.extra_volume_count > 0 && var.use_autoscaling_group == false
}

resource "aws_volume_attachment" "this" {
count = local.should_create_extra_volumes ? var.external_volume_count * var.instance_count : 0
resource "aws_volume_attachment" "this_extra" {
count = local.should_create_extra_volumes ? var.extra_volume_count : 0

device_name = element(var.external_volume_device_names, count.index % var.external_volume_count)
volume_id = element(aws_ebs_volume.this.*.id, count.index)
instance_id = element(aws_instance.this.*.id, floor(count.index / var.external_volume_count) % var.instance_count)
device_name = element(var.extra_volume_device_names, count.index)
volume_id = element(aws_ebs_volume.this_extra.*.id, count.index)
instance_id = aws_instance.this.*.id[0]
}

resource "aws_ebs_volume" "this" {
count = local.should_create_extra_volumes ? var.external_volume_count * var.instance_count : 0
resource "aws_ebs_volume" "this_extra" {
count = local.should_create_extra_volumes ? var.extra_volume_count : 0

availability_zone = element(data.aws_subnet.subnets.*.availability_zone, (floor(count.index / var.external_volume_count) % var.instance_count) % local.used_subnet_count)
size = element(var.external_volume_sizes, count.index % var.external_volume_count)
type = element(var.external_volume_types, count.index % var.external_volume_count)
availability_zone = local.availability_zones[0]
size = element(var.extra_volume_sizes, count.index)
type = element(var.extra_volume_types, count.index)

encrypted = true
kms_key_id = var.volume_kms_key_create ? element(aws_kms_key.this.*.arn, 0) : var.volume_kms_key_arn
kms_key_id = local.volume_kms_key_arn

tags = merge(
{
"Name" = format("%s%s", var.prefix, local.external_volume_use_incremental_names ? format(
"Name" = format("%s%s", var.prefix, local.use_incremental_names ? format(
"%s-%0${var.num_suffix_digits}d",
var.external_volume_name,
count.index + (floor(count.index / var.external_volume_count) % var.instance_count) + local.external_volume_num_suffix_starting_index
) : var.external_volume_name)
var.extra_volume_name,
count.index + local.num_suffix_starting_index + 1
) : var.extra_volume_name)
},
var.tags,
var.external_volume_tags,
var.extra_volume_tags,
local.tags,
)
}
@@ -558,26 +578,26 @@ resource "aws_ebs_volume" "this" {
####

locals {
should_create_extra_network_interface = var.extra_network_interface_count > 0 && var.use_autoscaling_group == false && var.instance_count > 0
should_create_extra_network_interface = var.extra_network_interface_count > 0 && var.use_autoscaling_group == false
extra_network_interface_security_group_ids = var.extra_network_interface_security_group_ids == null ? local.security_group_ids : var.extra_network_interface_security_group_ids
extra_network_interface_num_suffix_starting_index = local.num_suffix_starting_index + var.extra_network_interface_num_suffix_offset
}

resource "aws_network_interface" "this" {
count = local.should_create_extra_network_interface ? var.extra_network_interface_count * var.instance_count : 0
description = "Extra network interface"
resource "aws_network_interface" "this_extra" {
count = local.should_create_extra_network_interface ? var.extra_network_interface_count : 0
description = "Extra network interface ${count.index} for ${var.name} instance."

subnet_id = element(data.aws_subnet.subnets.*.id, (floor(count.index / var.extra_network_interface_count) % var.instance_count) % local.used_subnet_count)
private_ips = element(var.extra_network_interface_private_ips, count.index % var.extra_network_interface_count)
private_ips_count = element(var.extra_network_interface_private_ips_counts, count.index % var.extra_network_interface_count)
source_dest_check = element(var.extra_network_interface_source_dest_checks, count.index % var.extra_network_interface_count)
subnet_id = local.subnet_ids[0]
private_ips = element(var.extra_network_interface_private_ips, count.index)
private_ips_count = element(var.extra_network_interface_private_ips_counts, count.index)
source_dest_check = element(var.extra_network_interface_source_dest_checks, count.index)

tags = merge(
{
"Name" = format("%s%s", var.prefix, local.use_incremental_names ? format(
"%s-%0${var.num_suffix_digits}d",
var.extra_network_interface_name,
count.index + (floor(count.index / var.extra_network_interface_count) % var.instance_count) + local.external_volume_num_suffix_starting_index
count.index + local.extra_network_interface_num_suffix_starting_index
) : var.extra_network_interface_name)
},
var.tags,
@@ -586,20 +606,17 @@ resource "aws_network_interface" "this" {
)
}

resource "aws_network_interface_attachment" "this" {
count = local.should_create_extra_network_interface ? var.extra_network_interface_count * var.instance_count : 0
resource "aws_network_interface_attachment" "this_extra" {
count = local.should_create_extra_network_interface ? var.extra_network_interface_count : 0

instance_id = element(aws_instance.this.*.id, floor(count.index / var.extra_network_interface_count) % var.instance_count)
network_interface_id = element(aws_network_interface.this.*.id, count.index)
device_index = (count.index % var.extra_network_interface_count) + 1
instance_id = aws_instance.this.*.id[0]
network_interface_id = aws_network_interface.this_extra.*.id[count.index]
device_index = count.index + 1
}

resource "aws_network_interface_sg_attachment" "this" {
count = local.should_create_extra_network_interface ? var.extra_network_interface_security_group_count * var.instance_count * var.extra_network_interface_count : 0
resource "aws_network_interface_sg_attachment" "this_extra" {
count = local.should_create_extra_network_interface ? var.extra_network_interface_security_group_count * var.extra_network_interface_count : 0

security_group_id = element(
element(local.extra_network_interface_security_group_ids, floor(count.index / var.instance_count) % var.instance_count),
count.index % var.extra_network_interface_security_group_count
)
network_interface_id = element(aws_network_interface.this.*.id, count.index % (var.instance_count * var.external_volume_count))
security_group_id = element(local.extra_network_interface_security_group_ids, count.index)
network_interface_id = element(aws_network_interface.this_extra.*.id, floor(count.index / var.extra_network_interface_security_group_count) % var.extra_network_interface_count)
}

+ 56
- 33
outputs.tf View File

@@ -46,32 +46,32 @@ output "autoscaling_group_arn" {
# EC2
####

output "ec2_arns" {
value = compact(concat(aws_instance.this.*.arn, [""]))
output "ec2_arn" {
value = concat(aws_instance.this.*.arn, [""])[0]
}

output "ec2_ids" {
value = compact(concat(aws_instance.this.*.id, [""]))
output "ec2_id" {
value = concat(aws_instance.this.*.id, [""])[0]
}

output "ec2_private_ips" {
value = compact(concat(aws_instance.this.*.private_ip, [""]))
output "ec2_private_ip" {
value = concat(aws_instance.this.*.private_ip, [""])[0]
}

output "ec2_primary_network_interface_ids" {
value = compact(concat(aws_instance.this.*.primary_network_interface_id, [""]))
output "ec2_primary_network_interface_id" {
value = concat(aws_instance.this.*.primary_network_interface_id, [""])[0]
}

output "ec2_private_dns" {
value = compact(concat(aws_instance.this.*.private_dns, [""]))
value = concat(aws_instance.this.*.private_dns, [""])[0]
}

output "ec2_public_dns" {
value = compact(concat(aws_instance.this.*.public_dns, [""]))
value = concat(aws_instance.this.*.public_dns, [""])[0]
}

output "ec2_public_ips" {
value = compact(concat(aws_instance.this.*.public_ip, [""]))
output "ec2_public_ip" {
value = concat(aws_instance.this.*.public_ip, [""])[0]
}

####
@@ -79,7 +79,7 @@ output "ec2_public_ips" {
####

output "kms_key_id" {
value = concat([var.volume_kms_key_arn], aws_kms_key.this.*.arn, [""])[0]
value = concat([var.volume_kms_key_arn], aws_kms_key.this_volume.*.arn, [""])[0]
}

####
@@ -131,57 +131,80 @@ output "key_pair_fingerprint" {
####

output "eip_ids" {
value = aws_eip.this.*.id
value = {
primary = aws_eip.this_primary.*.id
extra = aws_eip.this_extra.*.id
}
}

output "eip_private_ips" {
value = aws_eip.this.*.private_ip
value = {
primary = aws_eip.this_primary.*.private_ip
extra = aws_eip.this_extra.*.private_ip
}
}

output "eip_private_dns" {
value = aws_eip.this.*.private_dns
value = {
primary = aws_eip.this_primary.*.private_dns
extra = aws_eip.this_extra.*.private_dns
}
}

output "eip_public_ips" {
value = aws_eip.this.*.public_ip
value = {
primary = aws_eip.this_primary.*.public_ip
extra = aws_eip.this_extra.*.public_ip
}
}

output "eip_public_dns" {
value = aws_eip.this.*.public_dns
value = {
primary = aws_eip.this_primary.*.public_dns
extra = aws_eip.this_extra.*.public_dns
}
}

output "eip_network_interfaces" {
value = aws_eip.this.*.network_interface
value = {
primary = aws_eip.this_primary.*.network_interface
extra = aws_eip.this_extra.*.network_interface
}
}

####
# EBS
####

output "external_volume_ids" {
value = local.should_create_extra_volumes && concat(aws_instance.this.*.id, [""])[0] != "" && concat(aws_ebs_volume.this.*.id, [""])[0] != "" ? zipmap(aws_instance.this.*.id, chunklist(compact(concat(aws_ebs_volume.this.*.id, [""])), var.external_volume_count)) : {}
output "extra_volume_ids" {
value = aws_ebs_volume.this_extra.*.id
}

output "external_volume_arns" {
value = local.should_create_extra_volumes && concat(aws_instance.this.*.id, [""])[0] != "" && concat(aws_ebs_volume.this.*.id, [""])[0] != "" ? zipmap(aws_instance.this.*.id, chunklist(compact(concat(aws_ebs_volume.this.*.arn, [""])), var.external_volume_count)) : {}
output "extra_volume_arns" {
value = aws_ebs_volume.this_extra.*.arn
}

####
# Network Interfaces
####

output "extra_network_interface_ids" {
value = local.should_create_extra_network_interface && concat(aws_instance.this.*.id, [""])[0] != "" && concat(aws_network_interface.this.*.id, [""]) != "" ? zipmap(aws_instance.this.*.id, chunklist(compact(concat(aws_network_interface.this.*.id, [""])), var.extra_network_interface_count)) : {}
output "network_interface_ids" {
value = {
primary = aws_network_interface.this_primary.*.id
extra = aws_network_interface.this_extra.*.id
}
}

output "extra_network_interface_mac_addresses" {
value = local.should_create_extra_network_interface && concat(aws_instance.this.*.id, [""])[0] != "" && concat(aws_network_interface.this.*.id, [""]) != "" ? zipmap(aws_instance.this.*.id, chunklist(compact(concat(aws_network_interface.this.*.mac_address, [""])), var.extra_network_interface_count)) : {}
output "network_interface_mac_addresses" {
value = {
primary = aws_network_interface.this_primary.*.mac_address
extra = aws_network_interface.this_extra.*.mac_address
}
}

output "extra_network_interface_private_ips" {
value = local.should_create_extra_network_interface && concat(aws_instance.this.*.id, [""])[0] != "" && concat(aws_network_interface.this.*.id, [""]) != "" ? zipmap(aws_instance.this.*.id, chunklist(aws_network_interface.this.*.private_ips, var.extra_network_interface_count)) : {}
}

output "extra_network_interface_public_ips" {
value = local.should_create_extra_network_interface && var.extra_network_interface_eips_count > 0 && length(aws_instance.this.*.id) > 0 && concat(aws_network_interface.this.*.id, [""]) != "" ? zipmap(aws_instance.this.*.id, chunklist(aws_eip.extra.*.public_ip, var.extra_network_interface_eips_count)) : {}
output "network_interface_private_ips" {
value = {
primary = aws_network_interface.this_primary.*.private_ips
extra = aws_network_interface.this_extra.*.private_ips
}
}

+ 592
- 151
variables.tf
File diff suppressed because it is too large
View File


+ 2
- 2
versions.tf View File

@@ -1,8 +1,8 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"

required_providers {
aws = "~> 2.54"
aws = ">= 3.1.0, < 4.0.0"
null = "~> 2.1"
}
}

Loading…
Cancel
Save