Skip to content

Replace instance_state_parser with ResourceData interface #13

@jimmy-btn

Description

@jimmy-btn

See func (d *ResourceData) State() *terraform.InstanceState { for a good example.

The core of this function is:

        rawMap := make(map[string]interface{})
	for k := range d.schema {
		source := getSourceSet
		if d.partial {
			source = getSourceState
			if _, ok := d.partialMap[k]; ok {
				source = getSourceSet
			}
		}

		raw := d.get([]string{k}, source)
		if raw.Exists && !raw.Computed {
			rawMap[k] = raw.Value
			if raw.ValueProcessed != nil {
				rawMap[k] = raw.ValueProcessed
			}
		}
	}

Within this, the call to d.get(...) which uses a combination of the Schema and InstanceState to build a nested and correctly typed representation of the resource.

Next steps are:

  1. Work out how a ResourceData is constructed and initialized with the correct set of FieldWriters (MapFieldWriter, MergeFieldWriter etc)

  2. Confirm that the representation that is returned works for lists and lists of nested resources

  3. Write a class to convert from this representation to a Resource for printing

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions