diff --git a/CHANGELOG.md b/CHANGELOG.md index 98451ef6..a47d8bc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. - When bringing your own certificate for VPN Servers, two separate certificates are now imported. Additional variables have been added to support the new imported certificate - Users can now create, update, and delete Classic Security Groups and their rules from the Classic Security Groups page `/forms/classicSecurityGroups` - Users can now add IBM i licenses to Power VS instances with IBM i images +- Users can now import existing VPC security groups for existing VPCs ### Fixes diff --git a/client/src/components/forms/duplicate-rules/CopyRuleObject.js b/client/src/components/forms/duplicate-rules/CopyRuleObject.js index f6d9f87d..0360611f 100644 --- a/client/src/components/forms/duplicate-rules/CopyRuleObject.js +++ b/client/src/components/forms/duplicate-rules/CopyRuleObject.js @@ -44,8 +44,18 @@ const CopyRuleObject = (props) => { className: "fieldWidthSmaller", groups: (props.source ? [""] : []).concat( props.isSecurityGroup - ? splat(props.craig.store.json.security_groups, "name") - : splat(props.data.acls, "name") + ? splat( + props.craig.store.json.security_groups.filter((sg) => { + if (!sg.use_data) return sg; + }), + "name" + ) + : splat( + props.data.acls.filter((acl) => { + if (!acl.use_data) return acl; + }), + "name" + ) ), disabled: (stateData) => { return stateData.v2; diff --git a/client/src/components/pages/CraigForms.js b/client/src/components/pages/CraigForms.js index 27a8862c..f02b8b70 100644 --- a/client/src/components/pages/CraigForms.js +++ b/client/src/components/pages/CraigForms.js @@ -1595,6 +1595,9 @@ function craigForms(craig) { security_groups: { jsonField: "security_groups", groups: [ + { + use_data: craig.security_groups.use_data, + }, { name: craig.security_groups.name, resource_group: craig.security_groups.resource_group, diff --git a/client/src/components/pages/vpc/VpcDeployments.js b/client/src/components/pages/vpc/VpcDeployments.js index 7fca7481..8ae320dc 100644 --- a/client/src/components/pages/vpc/VpcDeployments.js +++ b/client/src/components/pages/vpc/VpcDeployments.js @@ -662,7 +662,10 @@ class VpcDeploymentsDiagramPage extends React.Component { vpc_name: this.vpcName(), }} /> - {this.state.selectedItem === "security_groups" ? ( + {this.state.selectedItem === "security_groups" && + !craig.store.json[this.state.selectedItem][ + this.state.selectedIndex + ].use_data ? ( { rule.vpc = null; rule.sg = sg.name; @@ -256,6 +258,20 @@ function initSecurityGroupStore(store) { "security_groups" ), schema: { + use_data: { + type: "toggle", + default: false, + labelText: "Use Existing Security Group", + hideWhen: function (stateData, componentProps) { + return ( + getObjectFromArray( + componentProps.craig.store.json.vpcs, + "name", + stateData.vpc || "" // modal + )?.use_data !== true + ); + }, + }, name: nameField("security_groups", { size: "small" }), resource_group: resourceGroupsField(true), vpc: { @@ -266,6 +282,9 @@ function initSecurityGroupStore(store) { invalidText: selectInvalidText("vpc"), size: "small", groups: vpcGroups, + disabled: function (stateData) { + return stateData.use_data && !isNullOrEmptyString(stateData.vpc); + }, }, }, subComponents: { diff --git a/unit-tests/state/security-groups.test.js b/unit-tests/state/security-groups.test.js index 0cd80c08..ff88f4a0 100644 --- a/unit-tests/state/security-groups.test.js +++ b/unit-tests/state/security-groups.test.js @@ -619,6 +619,46 @@ describe("security groups", () => { ); }); }); + describe("security_groups.schema", () => { + let craig; + beforeEach(() => { + craig = newState(); + }); + it("should hide use_data", () => { + assert.isTrue( + craig.security_groups.use_data.hideWhen({}, { craig: craig }), + "it should hide when in modal" + ); + assert.isTrue( + craig.security_groups.use_data.hideWhen( + { vpc: "management" }, + { craig: craig } + ), + "it should hide when vpc does not use data" + ); + craig.store.json.vpcs.push({ + name: "data", + use_data: true, + }); + assert.isFalse( + craig.security_groups.use_data.hideWhen( + { vpc: "data" }, + { craig: craig } + ), + "it should be shown" + ); + }); + it("should disable vpc when using data for security group", () => { + assert.isFalse( + craig.security_groups.vpc.disabled({ use_data: true, vpc: "" }), + "it should not be disabled" + ); + assert.isTrue( + craig.security_groups.vpc.disabled({ use_data: true, vpc: "frog" }), + "it should be disabled" + ); + }); + }); describe("security_group.rules", () => { describe("security_groups.rules.create", () => { it("should add a new rule", () => {