From 38aaec1b733037493b527b8fd5e256bbf15206a1 Mon Sep 17 00:00:00 2001
From: alpineriveredge <alpineriveredge@gmail.com>
Date: Tue, 28 May 2024 23:28:53 +0900
Subject: [PATCH 1/2] Enhance codebuild resource

Enable codebuild properties tests
---
 doc/_resource_types/codebuild.md      | 14 +++++++
 doc/resource_types.md                 | 15 +++++++
 lib/awspec/helper/finder/codebuild.rb |  6 +--
 lib/awspec/stub/codebuild.rb          | 56 +++++++++++++++++++++++++++
 lib/awspec/type/codebuild.rb          |  3 ++
 5 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/doc/_resource_types/codebuild.md b/doc/_resource_types/codebuild.md
index 3a2e77657..7d5558ebb 100644
--- a/doc/_resource_types/codebuild.md
+++ b/doc/_resource_types/codebuild.md
@@ -1 +1,15 @@
 ### exist
+
+```ruby
+describe codebuild('my-codebuild1') do
+  it { should exist }
+end
+```
+
+### have_tag
+
+```ruby
+describe codebuild('my-codebuild1') do
+  it { should have_tag('env').value('dev') }
+end
+```
diff --git a/doc/resource_types.md b/doc/resource_types.md
index 87231dbd3..718ffccea 100644
--- a/doc/resource_types.md
+++ b/doc/resource_types.md
@@ -737,7 +737,22 @@ Codebuild resource type.
 
 ### exist
 
+```ruby
+describe codebuild('my-codebuild1') do
+  it { should exist }
+end
+```
+
+
+### have_tag
+
+```ruby
+describe codebuild('my-codebuild1') do
+  it { should have_tag('env').value('dev') }
+end
+```
 
+### its(:name), its(:arn), its(:description), its(:secondary_sources), its(:source_version), its(:secondary_source_versions), its(:secondary_artifacts), its(:service_role), its(:timeout_in_minutes), its(:queued_timeout_in_minutes), its(:encryption_key), its(:created), its(:last_modified), its(:webhook), its(:vpc_config), its(:file_system_locations), its(:build_batch_config), its(:concurrent_build_limit), its(:project_visibility), its(:public_project_alias), its(:resource_access_role)
 ## <a name="codedeploy">codedeploy</a>
 
 Codedeploy resource type.
diff --git a/lib/awspec/helper/finder/codebuild.rb b/lib/awspec/helper/finder/codebuild.rb
index edafe45dd..14c0e8097 100644
--- a/lib/awspec/helper/finder/codebuild.rb
+++ b/lib/awspec/helper/finder/codebuild.rb
@@ -4,10 +4,8 @@ module Awspec::Helper
   module Finder
     module Codebuild
       def find_codebuild_project(id)
-        projects = select_all_codebuild_projects.select do |project|
-          project == id
-        end
-        projects.single_resource(id)
+        res = codebuild_client.batch_get_projects({ names: [id] })
+        res.projects.single_resource(id)
       end
 
       def select_all_codebuild_projects
diff --git a/lib/awspec/stub/codebuild.rb b/lib/awspec/stub/codebuild.rb
index e2d868bc5..56792a0e0 100644
--- a/lib/awspec/stub/codebuild.rb
+++ b/lib/awspec/stub/codebuild.rb
@@ -2,6 +2,62 @@
 
 Aws.config[:codebuild] = {
   stub_responses: {
+    batch_get_projects: {
+      projects: [
+        {
+          name: 'my-codebuild1',
+          arn: 'arn:aws:codebuild:ap-northeast-1:123456789012:project/my-codebuild1',
+          source: {
+            type: 'S3',
+            location: 'example-bucket/test.zip',
+            insecure_ssl: false
+          },
+          secondary_sources: [],
+          secondary_source_versions: [],
+          artifacts: {
+            type: 'NO_ARTIFACTS'
+          },
+          secondary_artifacts: [],
+          cache: {
+            type: 'NO_CACHE'
+          },
+          environment: {
+            type: 'LINUX_CONTAINER',
+            image: 'aws/codebuild/amazonlinux2-x86_64-standard:5.0',
+            compute_type: 'BUILD_GENERAL1_SMALL',
+            environment_variables: [],
+            privileged_mode: false,
+            image_pull_credentials_type: 'CODEBUILD'
+          },
+          service_role: 'arn:aws:iam::123456789012:role/service-role/codebuild-my-codebuild1-service-role',
+          timeout_in_minutes: 60,
+          queued_timeout_in_minutes: 480,
+          encryption_key: 'arn:aws:kms:ap-northeast-1:123456789012:alias/aws/s3',
+          tags: [
+            {
+              key: 'env',
+              value: 'dev'
+            }
+          ],
+          created: Time.local(2024),
+          last_modified: Time.local(2024),
+          badge: {
+            badge_enabled: false
+          },
+          logs_config: {
+            cloud_watch_logs: {
+              status: 'ENABLED'
+            },
+            s3_logs: {
+              status: 'DISABLED',
+              encryption_disabled: false
+            }
+          },
+          project_visibility: 'PRIVATE'
+        }
+      ],
+      projects_not_found: []
+    },
     list_projects: {
       projects: %w[
         my-codebuild1
diff --git a/lib/awspec/type/codebuild.rb b/lib/awspec/type/codebuild.rb
index 944ad46ed..5279efd51 100644
--- a/lib/awspec/type/codebuild.rb
+++ b/lib/awspec/type/codebuild.rb
@@ -2,6 +2,9 @@
 
 module Awspec::Type
   class Codebuild < ResourceBase
+    aws_resource Aws::CodeBuild::Types::Project
+    tags_allowed
+
     def resource_via_client
       @resource_via_client ||= find_codebuild_project(@display_name)
     end

From 8b41e38fe8f547992ec8d46d2af502ea123110b6 Mon Sep 17 00:00:00 2001
From: alpineriveredge <alpineriveredge@gmail.com>
Date: Wed, 29 May 2024 01:14:08 +0900
Subject: [PATCH 2/2] Fix IAM date tests

---
 lib/awspec/generator/spec/iam_group.rb  | 2 +-
 lib/awspec/generator/spec/iam_policy.rb | 2 +-
 lib/awspec/generator/spec/iam_role.rb   | 2 +-
 lib/awspec/generator/spec/iam_user.rb   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/awspec/generator/spec/iam_group.rb b/lib/awspec/generator/spec/iam_group.rb
index 2ab5b6419..0b60c930d 100644
--- a/lib/awspec/generator/spec/iam_group.rb
+++ b/lib/awspec/generator/spec/iam_group.rb
@@ -27,7 +27,7 @@ def iam_group_spec_template
 describe iam_group('<%= group.group_name %>') do
   it { should exist }
   its(:arn) { should eq '<%= group.arn %>' }
-  its(:create_date) { should eq Time.parse('<%= group.create_date %>') }
+  its(:create_date) { should eq Time.parse('<%= group.create_date.utc %>') }
 <% select_iam_policy_by_group_name(group.group_name).each do |policy| %>  it { should have_iam_policy('<%= policy.policy_name %>') }
 <% end %>
 <%- inline_policies.each do |line| -%>
diff --git a/lib/awspec/generator/spec/iam_policy.rb b/lib/awspec/generator/spec/iam_policy.rb
index 3d6a69424..410b4e1e5 100644
--- a/lib/awspec/generator/spec/iam_policy.rb
+++ b/lib/awspec/generator/spec/iam_policy.rb
@@ -23,7 +23,7 @@ def policy_spec_template
   it { should_not be_attachable }
 <%- end -%>
   its(:arn) { should eq '<%= policy.arn %>' }
-  its(:update_date) { should eq Time.parse('<%= policy.update_date %>') }
+  its(:update_date) { should eq Time.parse('<%= policy.update_date.utc %>') }
   its(:attachment_count) { should eq <%= policy.attachment_count %> }
 <%- users = select_attached_users(policy.arn) -%>
 <%- if users.empty? -%>
diff --git a/lib/awspec/generator/spec/iam_role.rb b/lib/awspec/generator/spec/iam_role.rb
index 628996097..559fd05ed 100644
--- a/lib/awspec/generator/spec/iam_role.rb
+++ b/lib/awspec/generator/spec/iam_role.rb
@@ -27,7 +27,7 @@ def iam_role_spec_template
 describe iam_role('<%= role.role_name %>') do
   it { should exist }
   its(:arn) { should eq '<%= role.arn %>' }
-  its(:create_date) { should eq Time.parse('<%= role.create_date %>') }
+  its(:create_date) { should eq Time.parse('<%= role.create_date.utc %>') }
 <% select_iam_policy_by_role_name(role.role_name).each do |policy| %>  it { should have_iam_policy('<%= policy.policy_name %>') }
 <% end %>
 <%- inline_policies.each do |line| -%>
diff --git a/lib/awspec/generator/spec/iam_user.rb b/lib/awspec/generator/spec/iam_user.rb
index 4b4b4ce2e..c5db9bf89 100644
--- a/lib/awspec/generator/spec/iam_user.rb
+++ b/lib/awspec/generator/spec/iam_user.rb
@@ -27,7 +27,7 @@ def iam_user_spec_template
 describe iam_user('<%= user.user_name %>') do
   it { should exist }
   its(:arn) { should eq '<%= user.arn %>' }
-  its(:create_date) { should eq Time.parse('<%= user.create_date %>') }
+  its(:create_date) { should eq Time.parse('<%= user.create_date.utc %>') }
 <% select_iam_policy_by_user_name(user.user_name).each do |policy| %>  it { should have_iam_policy('<%= policy.policy_name %>') }
 <% end %>
 <%- inline_policies.each do |line| -%>