Skip to content
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

Create per-resource functions to generate import id base64 data #149

Open
3 tasks
Tracked by #148
kklimonda-cl opened this issue Aug 30, 2024 · 0 comments
Open
3 tasks
Tracked by #148

Comments

@kklimonda-cl
Copy link
Contributor

kklimonda-cl commented Aug 30, 2024

  • Cast received types.Object into an actual resource Model structure
  • Fill Import State struct with data from the model (location, names etc.)
  • Marshal import state struct into JSON and return it

Figure out error handling between our code and terraform functions.

An example implementation for a simple Entry-type resource, although not complete - we need marshaling of Terraform Locations for it to work, and EncodeLocation() doesn't seem to work properly:

type AddressGroupImportStateStruct struct {
	Location AddressGroupLocation
	Name     string
}

func AddressGroupImportStateCreator(ctx context.Context, resource types.Object) (string, error) {
	var addressGroup AddressGroupDataSourceModel
	diags := resource.As(ctx, &addressGroup, basetypes.ObjectAsOptions{})
	if diags.HasError() {
		return "", fmt.Errorf("Failed to convert types.Object into Model")
	}

	importStruct := AddressGroupImportStateStruct{
		Location: addressGroup.Location,
		Name:     addressGroup.Name.ValueString(),
	}

	data, err := json.Marshal(importStruct)
	if err != nil {
		return "", err
	}

	return base64.StdEncoding.EncodeToString(data), nil
}

Uuid-style and Entry-style lists will require some tweaks: it would probably be enough to change Name string to Names []string and copy names from the map/list (depending on the resource type).

@kklimonda-cl kklimonda-cl changed the title Create per-resource functions that convert types.Object into JSON bytes by using those new structures Create per-resource functions to generate import id base64 data Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant