-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/gh 118 aws virtual network #624
Open
HildericSB
wants to merge
24
commits into
develop
Choose a base branch
from
feature/GH-118-AWS_virtual_network
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e239dfc
yorc.nodes.aws.VPC type added
HildericSB abb3328
yorc.nodes.aws.Subnet
HildericSB 2ac0497
vpc [WIP_UNSTABLE]
HildericSB b5d5a88
VPC in aws rsc
HildericSB 3018a87
vpc test => ok
HildericSB e312cfb
generating VPC => ok
HildericSB 76acd95
Subnet
HildericSB 5f6f7ae
Adding networkInterfaces
HildericSB 24106e6
ENI creation => OK
HildericSB c153828
fix for connectionCheck
HildericSB 0424e32
fix test
HildericSB 51961bf
getTagsMap fn added
HildericSB 68dd3ac
fix string to bool params
HildericSB c40d9a4
yorc.nodes.aws.Subnet fixes
HildericSB 5b7793d
Instance can have an already existing subnet
HildericSB f6f018a
Implementing security groups WIP
HildericSB f639f6d
Default VPC system - NeedCleanup
HildericSB 6d2699f
new test + vpc nested sg fix
HildericSB 33de3d6
Subnet test + small fix
HildericSB fbefb3f
test+fix aws_instance
HildericSB ac366ba
clean up
HildericSB f4cf22b
VPC+Subnet relationship fix
HildericSB c014b18
Merge branch 'develop' into feature/GH-118-AWS_virtual_network
HildericSB c0641d8
Removing apify, only SSH connection allowed
HildericSB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,18 +75,16 @@ func (g *awsGenerator) generateAWSInstance(ctx context.Context, cfg config.Confi | |
} | ||
instance.KeyName = keyName.RawString() | ||
|
||
// security_groups needs to contain a least one occurrence | ||
secGroups, err := deployments.GetNodePropertyValue(ctx, deploymentID, nodeName, "security_groups") | ||
if err != nil { | ||
return err | ||
} | ||
if secGroups == nil || secGroups.RawString() == "" { | ||
return errors.Errorf("Missing mandatory parameter 'security_groups' node type for %s", nodeName) | ||
} | ||
|
||
for _, secGroup := range strings.Split(strings.NewReplacer("\"", "", "'", "").Replace(secGroups.RawString()), ",") { | ||
secGroup = strings.TrimSpace(secGroup) | ||
instance.SecurityGroups = append(instance.SecurityGroups, secGroup) | ||
if secGroups.RawString() != "" { | ||
for _, secGroup := range strings.Split(strings.NewReplacer("\"", "", "'", "").Replace(secGroups.RawString()), ",") { | ||
secGroup = strings.TrimSpace(secGroup) | ||
instance.SecurityGroups = append(instance.SecurityGroups, secGroup) | ||
} | ||
} | ||
|
||
// Get connection info (user, private key) | ||
|
@@ -141,6 +139,76 @@ func (g *awsGenerator) generateAWSInstance(ctx context.Context, cfg config.Confi | |
if placementGroup != nil { | ||
instance.PlacementGroup = placementGroup.RawString() | ||
} | ||
|
||
// Network | ||
subnetID, err := deployments.GetNodePropertyValue(ctx, deploymentID, nodeName, "subnet_id") | ||
if err != nil { | ||
return err | ||
} | ||
if subnetID != nil { | ||
instance.SubnetID = subnetID.RawString() | ||
} | ||
hasNetwork, _, err := deployments.HasAnyRequirementFromNodeType(ctx, deploymentID, nodeName, "network", "yorc.nodes.aws.VPC") | ||
if err != nil { | ||
return err | ||
} | ||
if hasNetwork { | ||
networkRequirements, err := deployments.GetRequirementsByTypeForNode(ctx, deploymentID, nodeName, "network") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
i := 0 | ||
for _, networkReq := range networkRequirements { | ||
networkInterface := &NetworkInterface{} | ||
// TODO : Check if subnet and security group are defined in relationship | ||
// networkInterface.SubnetID, err = deployments.LookupInstanceAttributeValue(ctx, deploymentID, networkReq.RequirementAssignment.Node, instanceName, "subnet_id") | ||
// if err != nil { | ||
// return err | ||
// } | ||
|
||
// If not, use default one | ||
defaultSubnetID, err := deployments.LookupInstanceAttributeValue(ctx, deploymentID, networkReq.RequirementAssignment.Node, instanceName, "default_subnet_id") | ||
if err != nil { | ||
return err | ||
} | ||
networkInterface.SubnetID = defaultSubnetID | ||
|
||
// With default Security Group | ||
defaultSecurityGroup, err := deployments.LookupInstanceAttributeValue(ctx, deploymentID, networkReq.RequirementAssignment.Node, instanceName, "default_security_group") | ||
if err != nil { | ||
return err | ||
} | ||
networkInterface.SecurityGroups = make([]string, 1) | ||
networkInterface.SecurityGroups = append(networkInterface.SecurityGroups, defaultSecurityGroup) | ||
|
||
name := strings.ToLower("network-inteface-" + strconv.Itoa(i)) | ||
name = strings.Replace(strings.ToLower(name), "_", "-", -1) | ||
|
||
// First interface will be considered as default one | ||
if i == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identical blocks of code found in 2 locations. Consider refactoring. |
||
instance.NetworkInterface = map[string]string{ | ||
"network_interface_id": "${aws_network_interface." + name + ".id}", | ||
"device_index": strconv.Itoa(i), | ||
} | ||
} else { | ||
// Others interfaces are considered attachment | ||
networkInterface.Attachment = map[string]string{ | ||
"instance": "${aws_instance." + instance.Tags.Name + ".id}", | ||
"device_index": strconv.Itoa(i), | ||
} | ||
} | ||
|
||
commons.AddResource(infrastructure, "aws_network_interface", name, networkInterface) | ||
|
||
i++ | ||
} | ||
|
||
// No security groups on instance level when defining customs ENI | ||
// (So the instance will have be in the default security groups on creation) | ||
instance.SecurityGroups = nil | ||
} | ||
|
||
// Add the AWS instance | ||
commons.AddResource(infrastructure, "aws_instance", instance.Tags.Name, &instance) | ||
|
||
|
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO found