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

ibm_cos_bucket is not idempotent #65

Open
treytabner opened this issue Jun 21, 2021 · 1 comment
Open

ibm_cos_bucket is not idempotent #65

treytabner opened this issue Jun 21, 2021 · 1 comment

Comments

@treytabner
Copy link

According to https://github.com/IBM-Cloud/ansible-collection-ibm/blob/master/docs/ibm_cos_bucket.rst, the ibm_cos_bucket module supports idempotency, but it doesn't look like it's working currently. Here is my test playbook:

---
- name: Create bucket
  hosts: localhost
  collections:
    - ibm.cloudcollection
  tasks:
    - name: create cos bucket
      ibm_cos_bucket:
        bucket_name: "randombucket128372187382173455467894"
        resource_instance_id: "crn:v1:bluemix:public:cloud-object-storage:global:a/5bd765d6cf2eac993e8b3749af9f9b2f:3ba4b8d4-2587-4cb7-abcb-20c92abd7b64::"
        storage_class: "standard"
        region_location: "us-south"

And when I first run the playbook, the bucket gets created:

TASK [create cos bucket] ***********************************************************************************************************************************
task path: /home/trey/test/test.yml:7
changed: [localhost] => {"changed": true, "rc": 0, "resource": {"activity_tracking": [], "allowed_ip": null, "archive_rule": [], "bucket_name": "randombucket128372187382173455467894", "crn": "crn:v1:bluemix:public:cloud-object-storage:global:a/5bd765d6cf2eac993e8b3749af9f9b2f:3ba4b8d4-2587-4cb7-abcb-20c92abd7b64:bucket:randombucket128372187382173455467894", "cross_region_location": null, "endpoint_type": "public", "expire_rule": [], "force_delete": true, "id": "crn:v1:bluemix:public:cloud-object-storage:global:a/5bd765d6cf2eac993e8b3749af9f9b2f:3ba4b8d4-2587-4cb7-abcb-20c92abd7b64:bucket:randombucket128372187382173455467894:meta:rl:us-south:public", "key_protect": null, "metrics_monitoring": [], "object_versioning": [], "region_location": "us-south", "resource_instance_id": "crn:v1:bluemix:public:cloud-object-storage:global:a/5bd765d6cf2eac993e8b3749af9f9b2f:3ba4b8d4-2587-4cb7-abcb-20c92abd7b64::", "retention_rule": [], "s3_endpoint_private": "s3.private.us-south.cloud-object-storage.appdomain.cloud", "s3_endpoint_public": "s3.us-south.cloud-object-storage.appdomain.cloud", "single_site_location": null, "storage_class": "standard", "timeouts": null}, "stderr": "", "stderr_lines": [], "stdout": "ibm_cos_bucket.ansible_20210621-160422: Creating...\nibm_cos_bucket.ansible_20210621-160422: Creation complete after 5s [id=crn:v1:bluemix:public:cloud-object-storage:global:a/5bd765d6cf2eac993e8b3749af9f9b2f:3ba4b8d4-2587-4cb7-abcb-20c92abd7b64:bucket:randombucket128372187382173455467894:meta:rl:us-south:public]\n\nApply complete! Resources: 1 added, 0 changed, 0 destroyed.\n", "stdout_lines": ["ibm_cos_bucket.ansible_20210621-160422: Creating...", "ibm_cos_bucket.ansible_20210621-160422: Creation complete after 5s [id=crn:v1:bluemix:public:cloud-object-storage:global:a/5bd765d6cf2eac993e8b3749af9f9b2f:3ba4b8d4-2587-4cb7-abcb-20c92abd7b64:bucket:randombucket128372187382173455467894:meta:rl:us-south:public]", "", "Apply complete! Resources: 1 added, 0 changed, 0 destroyed."]}

When I run it a second time:

TASK [create cos bucket] ***********************************************************************************************************************************
task path: /home/trey/barge-deploy/test.yml:7
fatal: [localhost]: FAILED! => {"changed": false, "msg": "", "rc": 1, "resource": {"_name": "ansible_20210621-160547", "_type": "ibm_cos_bucket", "target": "ibm_cos_bucket.ansible_20210621-160547"}, "stderr": "\nError: BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.\n\tstatus code: 409, request id: f3f6d093-381d-4c39-bf77-ad03c6054e38, host id: \n\n  on ibm_cos_bucket_ansible_20210621-160547.tf line 1, in resource \"ibm_cos_bucket\" \"ansible_20210621-160547\":\n   1: resource ibm_cos_bucket \"ansible_20210621-160547\" {\n\n\n", "stderr_lines": ["", "Error: BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.", "\tstatus code: 409, request id: f3f6d093-381d-4c39-bf77-ad03c6054e38, host id: ", "", "  on ibm_cos_bucket_ansible_20210621-160547.tf line 1, in resource \"ibm_cos_bucket\" \"ansible_20210621-160547\":", "   1: resource ibm_cos_bucket \"ansible_20210621-160547\" {", "", ""], "stdout": "ibm_cos_bucket.ansible_20210621-160547: Creating...\n", "stdout_lines": ["ibm_cos_bucket.ansible_20210621-160547: Creating..."]}
@Razique
Copy link

Razique commented Feb 21, 2022

I concur I had the same issue despite passing the id parameter, which is described as follows:

id (False, str, None)
(Required when updating or destroying existing resource) IBM Cloud Resource ID.

This is a workaround that you can use in the meanwhile:

    - name: Retrieve existing buckets
      ibm_cos_bucket_info:
        bucket_name: "{{ bucket.name }}"
        bucket_region: "{{ bucket.region_location }}"
        bucket_type: region_location
        resource_instance_id: "{{ storage_create.resource.id }}"
      register: bucket_info

    - name: Create storage bucket
      ibm_cos_bucket:
        allowed_ip: "{{ bucket.allowed_ip | default(omit) }}"
        activity_tracking: "{{ bucket.activity_tracking | default(omit) }}"
        archive_rule: "{{ bucket.archive_rule | default(omit) }}"
        bucket_name: "{{ bucket.name }}"
        endpoint_type: "{{ bucket.endpoint_type | default('public') }}"
        expire_rule: "{{ bucket.expire_rule | default(omit) }}"
        hard_quota: "{{ bucket.hard_quota | default(omit) }}"
        key_protect: "{{ kms_create.resource['keys'][0].crn }}"
        metrics_monitoring: "{{ bucket.metrics_monitoring | default(omit) }}"
        noncurrent_version_expiration: "{{ bucket.noncurrent_version_expiration | default(omit) }}"
        object_versioning: "{{ bucket.object_versioning | default(omit) }}"
        retention_rule: "{{ bucket.retention_rule | default(omit) }}"
        region_location: "{{ bucket.region_location | default(omit) }}"
        resource_instance_id: "{{ storage_create.resource.id }}"
        state: available
        storage_class: "{{ bucket.storage_class | default('standard') }}"
      when:
        - bucket_info.resource.id is defined

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

2 participants