Skip to content

Commit

Permalink
Add changes to convert Edge Dictionaries to Config Store for Compute … (
Browse files Browse the repository at this point in the history
#95)

Add changes to convert Edge Dictionaries to Config Store for Compute services
  • Loading branch information
hrmsk66 authored Apr 7, 2024
1 parent 9d6b31d commit 8034868
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 89 deletions.
41 changes: 30 additions & 11 deletions cmd/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// computeCmd represents the service command
var computeCmd = &cobra.Command{
Use: "compute <service-id> <path-to-package>",
Short: "Generate TF files for an existing Fastly C@E service",
Short: "Generate TF files for an existing Fastly Compute service",
Args: cobra.ExactArgs(2),
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -85,16 +85,22 @@ var computeCmd = &cobra.Command{
return err
}

replaceDictionary, err := cmd.Flags().GetBool("replace-edge-dictionary")
if err != nil {
return err
}

c := cli.Config{
ID: args[0],
Package: packagePath,
ResourceName: resourceName,
Version: version,
Directory: workingDir,
ManageAll: manageAll,
ForceDestroy: forceDestroy,
SkipEditState: skipEditState,
TestMode: testMode,
ID: args[0],
Package: packagePath,
ResourceName: resourceName,
Version: version,
Directory: workingDir,
ManageAll: manageAll,
ForceDestroy: forceDestroy,
SkipEditState: skipEditState,
TestMode: testMode,
ReplaceDictionary: replaceDictionary,
}

return ImportCompute(c)
Expand All @@ -103,6 +109,9 @@ var computeCmd = &cobra.Command{

func init() {
serviceCmd.AddCommand(computeCmd)

// Persistent flags
serviceCmd.PersistentFlags().BoolP("replace-edge-dictionary", "r", false, "Generate TF files to replace edge dictionaries with config stores")
}

func ImportCompute(c cli.Config) error {
Expand Down Expand Up @@ -132,7 +141,7 @@ func ImportCompute(c cli.Config) error {
return err
}

// Create VCLServiceResourceProp struct
// Create ComputeServiceResourceProp struct
serviceProp := prop.NewComputeServiceResource(c.ID, c.ResourceName, c.Version)

if err = terraform.Import(tf, serviceProp, tempf); err != nil {
Expand Down Expand Up @@ -323,5 +332,15 @@ func ImportCompute(c cli.Config) error {

fmt.Fprintln(os.Stderr)
cli.BoldGreen(os.Stderr, "Completed!")

if c.ReplaceDictionary {
msg := `Note:
Running "terraform apply" will create a new draft version with Edge Dictionaries replaced by Config Stores.
It won't be activated as the "activate" attribute is set to "false" in the "fastly_compute_service" resource.
Please review the configuration and make any necessary changes before manually activating the new version.
`
fmt.Fprintln(os.Stderr)
cli.BoldYellow(os.Stderr, msg)
}
return nil
}
23 changes: 12 additions & 11 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ import (
)

type Config struct {
ID string
ResourceName string
WafID string
Package string
Directory string
Version int
Interactive bool
ManageAll bool
ForceDestroy bool
SkipEditState bool
TestMode bool
ID string
ResourceName string
WafID string
Package string
Directory string
Version int
Interactive bool
ManageAll bool
ForceDestroy bool
SkipEditState bool
TestMode bool
ReplaceDictionary bool
}

var Bold = color.New(color.Bold).SprintFunc()
Expand Down
Loading

0 comments on commit 8034868

Please sign in to comment.