Skip to content

Commit

Permalink
add: create crossplane-vpc (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroniscode authored Jul 25, 2024
1 parent 6386fcd commit 3262ee6
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/create/crossplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package create
import (
"github.com/awslabs/eksdemo/pkg/resource"
"github.com/awslabs/eksdemo/pkg/resource/crossplane/s3"
"github.com/awslabs/eksdemo/pkg/resource/crossplane/vpc"
"github.com/spf13/cobra"
)

Expand All @@ -28,5 +29,6 @@ func NewCrossplaneCmd() *cobra.Command {
func init() {
crossplane = []func() *resource.Resource{
s3.NewResource,
vpc.NewResource,
}
}
68 changes: 68 additions & 0 deletions pkg/resource/crossplane/vpc/vpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package vpc

import (
"github.com/awslabs/eksdemo/pkg/cmd"
"github.com/awslabs/eksdemo/pkg/manifest"
"github.com/awslabs/eksdemo/pkg/resource"
"github.com/awslabs/eksdemo/pkg/template"
)

type Options struct {
resource.CommonOptions
CidrBlock string
}

func NewResource() *resource.Resource {
options := &Options{
CommonOptions: resource.CommonOptions{
Name: "crossplane-vpc",
Namespace: "default",
NamespaceFlag: true,
},
CidrBlock: "10.0.0.0/16",
}

flags := cmd.Flags{
&cmd.StringFlag{
CommandFlag: cmd.CommandFlag{
Name: "cidr",
Description: "IPv4 CIDR block for your VPC",
},
Option: &options.CidrBlock,
},
}

return &resource.Resource{
Command: cmd.Command{
Name: "vpc",
Description: "Virtual Private Cloud",
CreateArgs: []string{"NAME"},
},

CreateFlags: flags,

Manager: &manifest.ResourceManager{
Template: &template.TextTemplate{
Template: yamlTemplate,
},
},

Options: options,
}
}

const yamlTemplate = `---
apiVersion: ec2.aws.upbound.io/v1beta1
kind: VPC
metadata:
name: {{ .Name }}
namespace: {{ .Namespace }}
spec:
forProvider:
region: {{ .Region }}
cidrBlock: {{ .CidrBlock }}
enableDnsSupport: true
enableDnsHostnames: true
tags:
Name: {{ .Name }}
`

0 comments on commit 3262ee6

Please sign in to comment.