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

Added instance_profile_name to ec2 driver #2370

Merged
merged 2 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
else {'instance': item.name} }}"
wait: true
assign_public_ip: true
instance_profile_name: "{{ item.instance_profile_name | default(omit) }}"
exact_count: 1
count_tag:
instance: "{{ item.name }}"
Expand Down
14 changes: 14 additions & 0 deletions molecule/driver/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ class EC2(Driver):
instance_type: t2.micro
vpc_subnet_id: subnet-1cb17175

If you want to attach an IAM role to the Molecule instance:

.. code-block:: yaml

driver:
name: ec2
platforms:
- name: instance
image_owner: 099720109477
image_name: ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-20190320
instance_type: t2.micro
vpc_subnet_id: subnet-1cb17175
instance_profile_name: example-iam-role

Use wildcards for getting the latest image. For example, the latest Ubuntu bionic image:

.. code-block:: yaml
Expand Down
1 change: 1 addition & 0 deletions molecule/test/resources/playbooks/ec2/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
instance: "{{ item.name }}"
wait: true
assign_public_ip: true
instance_profile_name: "{{ item.instance_profile_name | default(omit) }}"
exact_count: 1
count_tag:
instance: "{{ item.name }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ platforms:
image: ami-a5b196c0
instance_type: t2.micro
vpc_subnet_id: subnet-6456fd1f
instance_profile_name: instance-profile
provisioner:
name: ansible
config_options:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ platforms:
image: ami-a5b196c0
instance_type: t2.micro
vpc_subnet_id: subnet-6456fd1f
instance_profile_name: instance-profile
groups:
- foo
- bar
- name: instance-2
image: ami-a5b196c0
instance_type: t2.micro
vpc_subnet_id: subnet-6456fd1f
instance_profile_name: instance-profile
groups:
- foo
- baz
Expand Down
8 changes: 8 additions & 0 deletions molecule/test/unit/driver/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ def test_get_instance_config(mocker, _instance):
assert x == _instance._get_instance_config('foo')


def test_get_instance_profile(mocker, _instance):
m = mocker.patch('molecule.util.safe_load_file')
m.return_value = [{'instance': 'foo', 'instance_profile_name': 'instance-profile'}]

x = {'instance': 'foo', 'instance_profile_name': 'instance-profile'}
assert x == _instance._get_instance_config('foo')


def test_created(_instance):
assert 'false' == _instance._created()

Expand Down