fix(ec2): carry DeliverLogsPermissionArn through CreateFlowLogs and DescribeFlowLogs (#3172)

A flow log with a CloudWatch Logs destination delivers through an IAM
role given as DeliverLogsPermissionArn. The value was dropped on create
and never returned on describe, so Terraform read aws_flow_log's
iam_role_arn back empty and proposed replacing the flow log on every
plan. The Query handler and the AWS::EC2::FlowLog provisioner now pass
it through, DescribeFlowLogs returns it, and the provisioner treats a
change to it as the replacement AWS performs.

Ported from lex00/floci#96.
This commit is contained in:
lex00 authored and GitHub committed 2026-09-07 09:03:44 -04:00
1 parent e7256f5556
commit acc0904be4
7 files changed
+104 -13

No files matched your search

@@ -63,6 +63,7 @@ public class Ec2FlowLogCfnProvisioner implements CfnResourceProvisioner {
ctx.resolveOptional(props, "TrafficType"),
ctx.resolveOptional(props, "LogDestinationType"),
ctx.resolveOptional(props, "LogDestination"),
ctx.resolveOptional(props, "DeliverLogsPermissionArn"),
ctx.resolveOptional(props, "LogFormat"),
props != null && props.hasNonNull("MaxAggregationInterval")
? props.get("MaxAggregationInterval").asInt()
@@ -92,6 +93,8 @@ public class Ec2FlowLogCfnProvisioner implements CfnResourceProvisioner {
orDefault(ctx.resolveOptional(props, "LogDestinationType"), DEFAULT_LOG_DESTINATION_TYPE));
rejectIfChanged("LogDestination", existing.getLogDestination(),
ctx.resolveOptional(props, "LogDestination"));
rejectIfChanged("DeliverLogsPermissionArn", existing.getDeliverLogsPermissionArn(),
ctx.resolveOptional(props, "DeliverLogsPermissionArn"));
rejectIfChanged("LogFormat", existing.getLogFormat(), ctx.resolveOptional(props, "LogFormat"));
int requestedInterval = props != null && props.hasNonNull("MaxAggregationInterval")
? props.get("MaxAggregationInterval").asInt()
@@ -1417,6 +1417,7 @@ public class Ec2QueryHandler {
if (logDestination == null) {
logDestination = p.getFirst("LogDestinationArn");
}
String deliverLogsPermissionArn = p.getFirst("DeliverLogsPermissionArn");
String logFormat = p.getFirst("LogFormat");
int maxAgg = parseIntParam(p, "MaxAggregationInterval", 600);
@@ -1434,7 +1435,7 @@ public class Ec2QueryHandler {
.start("flowLogIdSet");
for (String resourceId : resourceIds) {
FlowLog fl = flowLogService.createFlowLog(region, resourceId, resourceType, trafficType,
logDestinationType, logDestination, logFormat, maxAgg);
logDestinationType, logDestination, deliverLogsPermissionArn, logFormat, maxAgg);
xml.elem("item", fl.getFlowLogId());
}
xml.end("flowLogIdSet")
@@ -1460,6 +1461,7 @@ public class Ec2QueryHandler {
.elem("trafficType", fl.getTrafficType())
.elem("logDestinationType", fl.getLogDestinationType())
.elem("logDestination", fl.getLogDestination())
.elem("deliverLogsPermissionArn", fl.getDeliverLogsPermissionArn())
.elem("flowLogStatus", fl.getFlowLogStatus())
.elem("deliverLogsStatus", fl.getDeliverLogsStatus())
.elem("maxAggregationInterval", String.valueOf(fl.getMaxAggregationInterval()))
@@ -117,7 +117,8 @@ public class FlowLogService {
public FlowLog createFlowLog(String region, String resourceId, String resourceType,
String trafficType, String logDestinationType,
String logDestination, String logFormat, int maxAggregationInterval) {
String logDestination, String deliverLogsPermissionArn,
String logFormat, int maxAggregationInterval) {
FlowLog fl = new FlowLog();
fl.setFlowLogId("fl-" + randomHex(17));
fl.setResourceId(resourceId);
@@ -125,6 +126,7 @@ public class FlowLogService {
fl.setTrafficType(trafficType != null ? trafficType : "ALL");
fl.setLogDestinationType(logDestinationType != null ? logDestinationType : "s3");
fl.setLogDestination(logDestination);
fl.setDeliverLogsPermissionArn(deliverLogsPermissionArn);
fl.setBucketName(bucketFromArn(logDestination));
fl.setLogFormat(logFormat);
fl.setMaxAggregationInterval(maxAggregationInterval);
@@ -25,6 +25,7 @@ public class FlowLog {
private String trafficType; // ALL | ACCEPT | REJECT
private String logDestinationType; // s3 | cloud-watch-logs
private String logDestination; // S3 bucket ARN, e.g. arn:aws:s3:::flow-logs-bucket
private String deliverLogsPermissionArn; // IAM role ARN used for cloud-watch-logs delivery
private String bucketName; // resolved bucket name from the ARN
private String logFormat; // optional custom format string (default format used if null)
private int maxAggregationInterval = 600; // seconds (60 or 600)
@@ -52,6 +53,11 @@ public class FlowLog {
public String getLogDestination() { return logDestination; }
public void setLogDestination(String logDestination) { this.logDestination = logDestination; }
public String getDeliverLogsPermissionArn() { return deliverLogsPermissionArn; }
public void setDeliverLogsPermissionArn(String deliverLogsPermissionArn) {
this.deliverLogsPermissionArn = deliverLogsPermissionArn;
}
public String getBucketName() { return bucketName; }
public void setBucketName(String bucketName) { this.bucketName = bucketName; }