<commit_before>
SparkleFormation.dynamic(:iam_group) do |_name, _config = {}|
  _config = {} if _config.nil?

  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  resources.set!(_name) do
    registry! :default_config, :config, 
      path: "/",
      policies: nil,
      managed_policy_arns: nil

    registry! :apply_config, :config, _config

    type "AWS::IAM::Group"

    properties do
      state!(:config).each do |key, value|
        set!(key, value)
      end
    end
  end
end

SparkleFormation.dynamic(:iam_instance_profile) do |_name, _config = {}|
  _config = {} if _config.nil?

  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  resources.set!(_name) do
    registry! :default_config, :config, 
      path: "/",
      roles: nil

    registry! :apply_config, :config, _config

    type "AWS::IAM::InstanceProfile"

    properties do
      state!(:config).each do |key, value|
        set!(key, value)
      end
    end
  end
end


SparkleFormation.dynamic(:iam_role) do |_name, _config = {}|
  _config = {} if _config.nil?

  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  outputs.set!("#{_name}_arn") do
    value attr!(_name, :arn)
  end

  resources.set!(_name) do
    registry! :default_config, :config, 
      path: "/",
      policies: nil,
      managed_policy_arns: nil,
      principal: { Service: "ec2.amazonaws.com" }

    registry! :apply_config, :config, _config

    type "AWS::IAM::Role"

    properties do
      state!(:config).each do |key, value|
        case key.to_sym
        when :policies
          value = registry!(:iam_policies, value)
        when :principal
          key = :assume_role_policy_document
          value = registry!(:iam_policy_document, statement: [
            {
              effect: "Allow",
              action: "sts:AssumeRole",
              principal: value
            }
          ])
        end

        set!(key, value)
      end
    end
  end
end

SparkleFormation.dynamic(:iam_policy) do |_name, _config = {}|
  _config = {} if _config.nil?

  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  resources.set!(_name) do
    registry! :default_config, :config, 
      policy_name: _name,
      policy_document: nil,
      roles: nil,
      users: nil,
      groups: nil

    registry! :apply_config, :config, _config

    type "AWS::IAM::Policy"

    properties do
      state!(:config).each do |key, value|
        case key.to_sym
        when :policy_document
          value = registry!(:iam_policy_document, value)
        end
        set!(key, value)
      end
    end
  end
end

SparkleFormation.dynamic(:iam_managed_policy) do |_name, _config = {}|
  _config = {} if _config.nil?

  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  resources.set!(_name) do
    registry! :default_config, :config, 
      description: registry!(:context_name),
      policy_document: nil,
      roles: nil,
      users: nil,
      groups: nil

    registry! :apply_config, :config, _config

    type "AWS::IAM::ManagedPolicy"

    properties do
      state!(:config).each do |key, value|
        case key.to_sym
        when :policy_document
          value = registry!(:iam_policy_document, value)
        end
        set!(key, value)
      end
    end
  end
end
<commit_msg>Refactor iam to new registries<commit_after>
SparkleFormation.dynamic(:iam_group) do |_name, _config = {}|
  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  resources.set!(_name) do
    type "AWS::IAM::Group"
    set_state!(_config.delete(:state) || {})

    registry! :resource_config, :config, _config, 
      path: "/",
      policies: nil,
      managed_policy_arns: nil

    registry! :resource_properties, :config
  end
end

SparkleFormation.dynamic(:iam_instance_profile) do |_name, _config = {}|
  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  resources.set!(_name) do
    type "AWS::IAM::InstanceProfile"
    set_state!(_config.delete(:state) || {})

    registry! :resource_config, :config, _config,
      path: "/",
      roles: nil

    registry! :resource_properties, :config
  end
end

SparkleFormation.dynamic(:iam_role) do |_name, _config = {}|
  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  outputs.set!("#{_name}_arn") do
    value attr!(_name, :arn)
  end

  resources.set!(_name) do
    type "AWS::IAM::Role"
    set_state!(_config.delete(:state) || {})

    registry! :resource_config, :config, _config,
      path: "/",
      policies: nil,
      managed_policy_arns: nil,
      principal: { Service: "ec2.amazonaws.com" }

    properties do
      state!(:config).each do |key, value|
        case key.to_sym
        when :policies
          value = registry!(:iam_policies, value)
        when :principal
          key = :assume_role_policy_document
          value = registry!(:iam_policy_document, statement: [
            {
              effect: "Allow",
              action: "sts:AssumeRole",
              principal: value
            }
          ])
        end

        set!(key, value)
      end
    end
  end
end

SparkleFormation.dynamic(:iam_policy) do |_name, _config = {}|
  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  resources.set!(_name) do
    type "AWS::IAM::Policy"
    set_state!(_config.delete(:state) || {})

    registry! :resource_config, :config, _config,
      policy_name: _name,
      policy_document: nil,
      roles: nil,
      users: nil,
      groups: nil

    properties do
      state!(:config).each do |key, value|
        case key.to_sym
        when :policy_document
          value = registry!(:iam_policy_document, value)
        end
        set!(key, value)
      end
    end
  end
end

SparkleFormation.dynamic(:iam_managed_policy) do |_name, _config = {}|
  outputs.set!("#{_name}_id") do
    value ref!(_name)
  end

  resources.set!(_name) do
    type "AWS::IAM::ManagedPolicy"
    set_state!(_config.delete(:state) || {})

    registry! :resource_config, :config, _config,
      description: registry!(:context_name),
      policy_document: nil,
      roles: nil,
      users: nil,
      groups: nil

    properties do
      state!(:config).each do |key, value|
        case key.to_sym
        when :policy_document
          value = registry!(:iam_policy_document, value)
        end
        set!(key, value)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.12868801004394226, 'fraction_numerical': 0.00031387319522912746, 'mean_word_length': 2.5268400664084116, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3945299', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2098, 'n_words': 475}