Created
May 25, 2022 01:02
-
-
Save rodentskie/f49c55791556257173233ff77d499f5d to your computer and use it in GitHub Desktop.
cdktf mqbroker and mqconfiguration bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable no-new */ | |
import { | |
S3Backend, | |
TerraformOutput, | |
TerraformStack, | |
TerraformVariable, | |
} from 'cdktf'; | |
import { Construct } from 'constructs'; | |
import { MqBroker, MqConfiguration } from '@cdktf/provider-aws/lib/mq'; | |
import { SecurityGroup } from '@cdktf/provider-aws/lib/vpc'; | |
import { AwsProvider } from '@cdktf/provider-aws'; | |
export class AmazonMQAbstraction { | |
constructor( | |
scope: Construct, | |
config: { | |
environment: string; | |
region: string; | |
deploymentMode: string; | |
hostInstanceType: string; | |
username: string; | |
password: string; | |
engineVersion: string; | |
autoMinorVersionUpgrade: boolean; | |
isSingleInstance?: boolean; | |
} = { | |
environment: 'development', | |
region: 'eu-west-2', | |
deploymentMode: 'SINGLE_INSTANCE', | |
hostInstanceType: 'mq.t3.micro', | |
username: 'onewallet', | |
password: '57sf4e8fs5aq44r8gfd4', | |
engineVersion: '5.16.2', | |
autoMinorVersionUpgrade: false, | |
isSingleInstance: false, | |
}, | |
) { | |
const deploymentMode = new TerraformVariable(scope, 'deployment_mode', { | |
type: 'string', | |
default: config.deploymentMode, | |
}); | |
const engineVersion = new TerraformVariable(scope, 'engine_version', { | |
type: 'string', | |
default: config.engineVersion, | |
}); | |
const hostInstanceType = new TerraformVariable( | |
scope, | |
'host_instance_yype', | |
{ | |
type: 'string', | |
default: config.hostInstanceType, | |
}, | |
); | |
const autoMinorVersionUpgrade = new TerraformVariable( | |
scope, | |
'auto_minor_version_upgrade', | |
{ type: 'bool', default: config.autoMinorVersionUpgrade }, | |
); | |
const username = new TerraformVariable(scope, 'username', { | |
type: 'string', | |
default: config.username, | |
}); | |
const password = new TerraformVariable(scope, 'password', { | |
type: 'string', | |
default: config.password, | |
}); | |
new S3Backend(scope, { | |
bucket: `onewallet-infra-${config.environment}`, | |
region: config.region, | |
key: `mq.tfstate`, | |
}); | |
new AwsProvider(scope, 'aws', { | |
region: config.region, | |
}); | |
const securityGroup = new SecurityGroup(scope, 'security_group', { | |
name: `onewallet_activemq_mesh_${config.environment}`, | |
ingress: [ | |
{ | |
protocol: 'tcp', | |
fromPort: 5671, | |
toPort: 5671, | |
cidrBlocks: ['0.0.0.0/0'], | |
}, | |
{ | |
protocol: 'tcp', | |
fromPort: 8162, | |
toPort: 8162, | |
cidrBlocks: ['0.0.0.0/0'], | |
}, | |
{ | |
protocol: 'tcp', | |
fromPort: 61617, | |
toPort: 61617, | |
cidrBlocks: ['0.0.0.0/0'], | |
}, | |
], | |
egress: [ | |
{ | |
fromPort: 0, | |
toPort: 0, | |
protocol: '-1', | |
cidrBlocks: ['0.0.0.0/0'], | |
}, | |
], | |
}); | |
const mqConfigurationTwo = new MqConfiguration( | |
scope, | |
'mq_configuration_broker_two', | |
{ | |
name: `onewallet-broker-two-${config.environment}`, | |
engineType: 'ActiveMQ', | |
engineVersion: engineVersion.value, | |
description: 'test', | |
data: `<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<broker xmlns="http://activemq.apache.org/schema/core" schedulerSupport="true"> | |
<destinationInterceptors> | |
<virtualDestinationInterceptor> | |
<virtualDestinations> | |
<virtualTopic name=">" prefix="VirtualTopicConsumers.*." selectorAware="false"/> | |
</virtualDestinations> | |
</virtualDestinationInterceptor> | |
</destinationInterceptors> | |
<plugins> | |
<forcePersistencyModeBrokerPlugin persistenceFlag="true"/> | |
<statisticsBrokerPlugin/> | |
<timeStampingBrokerPlugin ttlCeiling="86400000" zeroExpirationOverride="86400000"/> | |
</plugins> | |
<destinationPolicy> | |
<policyMap> | |
<policyEntries> | |
<policyEntry queue=">"> | |
<deadLetterStrategy> | |
<sharedDeadLetterStrategy expiration="300000"/> | |
</deadLetterStrategy> | |
</policyEntry> | |
</policyEntries> | |
</policyMap> | |
</destinationPolicy> | |
</broker>`, | |
}, | |
); | |
new TerraformOutput(scope, 'mq_configuration_broker_two_id', { | |
value: mqConfigurationTwo.id, | |
}); | |
// const brokerTwo = | |
new MqBroker(scope, 'mq_broker_two', { | |
brokerName: `onewallet-activemq-two-${config.environment}`, | |
configuration: { | |
id: mqConfigurationTwo.id, | |
revision: mqConfigurationTwo.latestRevision, | |
}, | |
autoMinorVersionUpgrade: autoMinorVersionUpgrade.value, | |
engineType: 'ActiveMQ', | |
engineVersion: engineVersion.value, | |
storageType: 'efs', | |
deploymentMode: deploymentMode.value, | |
hostInstanceType: hostInstanceType.value, | |
securityGroups: [securityGroup.id], | |
publiclyAccessible: true, | |
user: [ | |
{ | |
username: username.value, | |
password: password.value, | |
}, | |
], | |
logs: { | |
audit: 'true', | |
general: true, | |
}, | |
}); | |
// if (config.isSingleInstance) return; | |
/* | |
const mqConfigurationOne = new MqConfiguration( | |
scope, | |
'mq_configuration_broker_one', | |
{ | |
name: `onewallet-broker-one-${config.environment}`, | |
engineType: 'ActiveMQ', | |
engineVersion: engineVersion.value, | |
data: `<<DATA | |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<broker xmlns="http://activemq.apache.org/schema/core" schedulerSupport="true"> | |
<destinationInterceptors> | |
<virtualDestinationInterceptor> | |
<virtualDestinations> | |
<virtualTopic name=">" prefix="VirtualTopicConsumers.*." selectorAware="false"/> | |
</virtualDestinations> | |
</virtualDestinationInterceptor> | |
</destinationInterceptors> | |
<plugins> | |
<forcePersistencyModeBrokerPlugin persistenceFlag="true"/> | |
<statisticsBrokerPlugin/> | |
<timeStampingBrokerPlugin ttlCeiling="86400000" zeroExpirationOverride="86400000"/> | |
</plugins> | |
<destinationPolicy> | |
<policyMap> | |
<policyEntries> | |
<policyEntry queue=">"> | |
<deadLetterStrategy> | |
<sharedDeadLetterStrategy expiration="300000"/> | |
</deadLetterStrategy> | |
</policyEntry> | |
</policyEntries> | |
</policyMap> | |
</destinationPolicy> | |
<networkConnectors> | |
<networkConnector name="duplex_connector" userName="${ | |
username.value | |
}" duplex="true" | |
uri="static:(${Fn.element( | |
brokerTwo.instances.get(0).endpoints, | |
0, | |
)})"/> | |
</networkConnectors> | |
</broker> | |
DATA`, | |
}, | |
); | |
new MqBroker(scope, 'mq_broker_one', { | |
brokerName: `onewallet-activemq-one-${config.environment}`, | |
configuration: { | |
id: mqConfigurationOne.id, | |
revision: mqConfigurationOne.latestRevision, | |
}, | |
autoMinorVersionUpgrade: autoMinorVersionUpgrade.value, | |
engineType: 'ActiveMQ', | |
engineVersion: engineVersion.value, | |
storageType: 'efs', | |
deploymentMode: deploymentMode.value, | |
hostInstanceType: hostInstanceType.value, | |
securityGroups: [securityGroup.id], | |
publiclyAccessible: true, | |
user: [ | |
{ | |
username: username.value, | |
password: password.value, | |
}, | |
], | |
logs: { | |
audit: 'true', | |
general: true, | |
}, | |
}); | |
*/ | |
} | |
} | |
export default class AmazonMQStack extends TerraformStack { | |
constructor( | |
scope: Construct, | |
name: string, | |
config?: { | |
environment: string; | |
region: string; | |
deploymentMode: string; | |
hostInstanceType: string; | |
username: string; | |
password: string; | |
engineVersion: string; | |
autoMinorVersionUpgrade: boolean; | |
isSingleInstance?: boolean; | |
}, | |
) { | |
super(scope, name); | |
new AmazonMQAbstraction(this, config); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ cdktf deploy onewallet-amqp-development --auto-approve | |
onewallet-amqp-development Initializing the backend... | |
onewallet-amqp-development Initializing provider plugins... | |
- Reusing previous version of hashicorp/aws from the dependency lock file | |
onewallet-amqp-development - Using previously-installed hashicorp/aws v4.15.1 | |
Terraform has been successfully initialized! | |
You may now begin working with Terraform. Try running "terraform plan" to see | |
any changes that are required for your infrastructure. All Terraform commands | |
should now work. | |
If you ever set or change modules or backend configuration for Terraform, | |
rerun this command to reinitialize your working directory. If you forget, other | |
commands will detect it and remind you to do so if necessary. | |
onewallet-amqp-development Terraform used the selected providers to generate the following execution | |
plan. Resource actions are indicated with the following symbols: | |
+ create | |
Terraform will perform the following actions: | |
onewallet-amqp-development # aws_mq_broker.mq_broker_two (mq_broker_two) will be created | |
+ resource "aws_mq_broker" "mq_broker_two" { | |
+ apply_immediately = false | |
+ arn = (known after apply) | |
+ authentication_strategy = (known after apply) | |
+ auto_minor_version_upgrade = false | |
+ broker_name = "onewallet-activemq-two-development" | |
+ deployment_mode = "SINGLE_INSTANCE" | |
+ engine_type = "ActiveMQ" | |
+ engine_version = "5.16.2" | |
+ host_instance_type = "mq.t3.micro" | |
+ id = (known after apply) | |
+ instances = (known after apply) | |
+ publicly_accessible = true | |
+ security_groups = (known after apply) | |
+ storage_type = "efs" | |
+ subnet_ids = (known after apply) | |
+ tags_all = (known after apply) | |
+ configuration { | |
+ id = (known after apply) | |
+ revision = (known after apply) | |
} | |
+ logs { | |
+ audit = "true" | |
+ general = true | |
} | |
+ maintenance_window_start_time { | |
+ day_of_week = (known after apply) | |
+ time_of_day = (known after apply) | |
+ time_zone = (known after apply) | |
} | |
+ user { | |
+ console_access = false | |
+ groups = [] | |
+ password = (sensitive value) | |
+ username = "onewallet" | |
} | |
} | |
# aws_mq_configuration.mq_configuration_broker_two (mq_configuration_broker_two) will be created | |
+ resource "aws_mq_configuration" "mq_configuration_broker_two" { | |
+ arn = (known after apply) | |
+ authentication_strategy = (known after apply) | |
+ data = <<-EOT | |
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<broker xmlns="http://activemq.apache.org/schema/core" schedulerSupport="true"> | |
<destinationInterceptors> | |
<virtualDestinationInterceptor> | |
<virtualDestinations> | |
<virtualTopic name=">" prefix="VirtualTopicConsumers.*." selectorAware="false"/> | |
</virtualDestinations> | |
</virtualDestinationInterceptor> | |
</destinationInterceptors> | |
<plugins> | |
<forcePersistencyModeBrokerPlugin persistenceFlag="true"/> | |
<statisticsBrokerPlugin/> | |
<timeStampingBrokerPlugin ttlCeiling="86400000" zeroExpirationOverride="86400000"/> | |
</plugins> | |
<destinationPolicy> | |
<policyMap> | |
<policyEntries> | |
<policyEntry queue=">"> | |
<deadLetterStrategy> | |
<sharedDeadLetterStrategy expiration="300000"/> | |
</deadLetterStrategy> | |
</policyEntry> | |
</policyEntries> | |
</policyMap> | |
</destinationPolicy> | |
</broker> | |
EOT | |
+ description = "test" | |
+ engine_type = "ActiveMQ" | |
+ engine_version = "5.16.2" | |
+ id = (known after apply) | |
+ latest_revision = (known after apply) | |
+ name = "onewallet-broker-two-development" | |
+ tags_all = (known after apply) | |
} | |
onewallet-amqp-development # aws_security_group.security_group (security_group) will be created | |
+ resource "aws_security_group" "security_group" { | |
+ arn = (known after apply) | |
+ description = "Managed by Terraform" | |
+ egress = [ | |
+ { | |
+ cidr_blocks = [ | |
+ "0.0.0.0/0", | |
] | |
+ description = "" | |
+ from_port = 0 | |
+ ipv6_cidr_blocks = [] | |
+ prefix_list_ids = [] | |
+ protocol = "-1" | |
+ security_groups = [] | |
+ self = false | |
+ to_port = 0 | |
}, | |
] | |
+ id = (known after apply) | |
+ ingress = [ | |
+ { | |
+ cidr_blocks = [ | |
+ "0.0.0.0/0", | |
] | |
+ description = "" | |
+ from_port = 5671 | |
+ ipv6_cidr_blocks = [] | |
+ prefix_list_ids = [] | |
+ protocol = "tcp" | |
+ security_groups = [] | |
+ self = false | |
+ to_port = 5671 | |
}, | |
+ { | |
+ cidr_blocks = [ | |
+ "0.0.0.0/0", | |
] | |
+ description = "" | |
+ from_port = 61617 | |
+ ipv6_cidr_blocks = [] | |
+ prefix_list_ids = [] | |
+ protocol = "tcp" | |
+ security_groups = [] | |
+ self = false | |
+ to_port = 61617 | |
}, | |
+ { | |
+ cidr_blocks = [ | |
+ "0.0.0.0/0", | |
] | |
+ description = "" | |
+ from_port = 8162 | |
+ ipv6_cidr_blocks = [] | |
+ prefix_list_ids = [] | |
+ protocol = "tcp" | |
+ security_groups = [] | |
+ self = false | |
+ to_port = 8162 | |
}, | |
] | |
+ name = "onewallet_activemq_mesh_development" | |
+ name_prefix = (known after apply) | |
+ owner_id = (known after apply) | |
+ revoke_rules_on_delete = false | |
+ tags_all = (known after apply) | |
+ vpc_id = (known after apply) | |
} | |
Plan: 3 to add, 0 to change, 0 to destroy. | |
Changes to Outputs: | |
+ mq_configuration_broker_two_id = (known after apply) | |
───────────────────────────────────────────────────────────────────────────── | |
Saved the plan to: plan | |
To perform exactly these actions, run the following command to apply: | |
terraform apply "plan" | |
onewallet-amqp-development aws_mq_configuration.mq_configuration_broker_two (mq_configuration_broker_two): Creating... | |
onewallet-amqp-development aws_security_group.security_group (security_group): Creating... | |
onewallet-amqp-development aws_mq_configuration.mq_configuration_broker_two (mq_configuration_broker_two): Creation complete after 2s [id=c-218071bd-5444-4ea7-ae26-abfea0339245] | |
onewallet-amqp-development aws_security_group.security_group (security_group): Creation complete after 4s [id=sg-005160b1010838140] | |
onewallet-amqp-development aws_mq_broker.mq_broker_two (mq_broker_two): Creating... | |
1 Stack deploying 0 Stacks done 0 Stacks waiting | |
[2022-05-25T08:54:07.177] [ERROR] default - ╷ | |
│ Error: BadRequestException: Configuration ID can't be empty. | |
│ { | |
│ RespMetadata: { | |
│ StatusCode: 400, | |
│ RequestID: "e2722fc9-5851-46d1-8643-36f27e6a6243" | |
│ }, | |
│ ErrorAttribute: "configuration.id", | |
│ Message_: "Configuration ID can't be empty." | |
│ } | |
│ | |
│ with aws_mq_broker.mq_broker_two, | |
│ on cdk.tf.json line 59, in resource.aws_mq_broker.mq_broker_two: | |
│ 59: } | |
onewallet-amqp-development ╷ | |
│ Error: BadRequestException: Configuration ID can't be empty. | |
│ { | |
│ RespMetadata: { | |
│ StatusCode: 400, | |
│ RequestID: "e2722fc9-5851-46d1-8643-36f27e6a6243" | |
│ }, | |
│ ErrorAttribute: "configuration.id", | |
│ Message_: "Configuration ID can't be empty." | |
│ } | |
│ | |
│ with aws_mq_broker.mq_broker_two (mq_broker_two), | |
│ on cdk.tf.json line 59, in resource.aws_mq_broker.mq_broker_two (mq_broker_two): | |
│ 59: } | |
│ | |
╵ | |
1 Stack deploying 0 Stacks done 0 Stacks waiting | |
non-zero exit code 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
main.ts