<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by SuleBilgic on Medium]]></title>
        <description><![CDATA[Stories by SuleBilgic on Medium]]></description>
        <link>https://medium.com/@bilgicsule?source=rss-6fcedddd996b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YCPx6A6agYntFuRgd_Pl6Q.jpeg</url>
            <title>Stories by SuleBilgic on Medium</title>
            <link>https://medium.com/@bilgicsule?source=rss-6fcedddd996b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 07:31:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bilgicsule/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Migrate from Bitbucket to GitLab: Complete Technical Guide (Importer, Automation & Sync)]]></title>
            <link>https://medium.com/@bilgicsule/comprehensive-technical-guide-migrating-from-bitbucket-to-gitlab-d00f103a5fd7?source=rss-6fcedddd996b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d00f103a5fd7</guid>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[bitbucket]]></category>
            <category><![CDATA[gitlab]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[SuleBilgic]]></dc:creator>
            <pubDate>Sun, 24 Aug 2025 13:48:34 GMT</pubDate>
            <atom:updated>2025-08-24T13:56:15.186Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/343/0*6VSS0mRBISgnz3wl.jpeg" /></figure><p>Introduction</p><p>Migrating repositories from Bitbucket to GitLab is more than just moving code; it involves preserving commit history, user permissions, pull requests, LFS objects, and maintaining a seamless developer workflow. This guide provides a <strong>step-by-step technical migration process</strong> from Bitbucket Server or Cloud to GitLab.</p><h3>1. Prerequisites</h3><ul><li><strong>Bitbucket account</strong> with admin access to all repositories you want to migrate</li><li><strong>GitLab account</strong> with permissions to create groups and projects (admin recommended)</li><li><strong>Personal access tokens (PATs):</strong></li><li>GitLab: with api scope</li><li>Bitbucket: personal access token or password</li><li><strong>Python 3.7+ installed</strong></li></ul><h3>2. Migration Options</h3><h3>2.1 Using GitLab’s Built-in Bitbucket Importer</h3><p>GitLab provides a native importer to move Bitbucket Server projects, including:</p><ul><li>Repository description, git data, pull requests (with comments), and LFS objects</li><li>Maintains repository visibility (private/public)</li><li>Does <strong>not</strong> import: markdown attachments, emoji reactions, pull request approvals/rules, task lists</li></ul><p><strong>Steps:</strong></p><p>1- Log in to GitLab</p><p>2- Navigate to: <em>Create new → New project/repository → Import project → Bitbucket Server</em></p><p>3- Sign in to Bitbucket and grant GitLab access</p><p>4- Select the projects to import</p><p>5- Click <strong>Import</strong> (or <strong>Re-import</strong> to create a new copy of the same project)</p><h3>2.2 Automated Migration with Python Script</h3><p>For large-scale migrations, automation is highly recommended.</p><h4>Tools Used</h4><ul><li><strong>Atlassian Python API</strong> (reads metadata from Bitbucket)</li><li><strong>python-gitlab</strong> (interacts with GitLab API)</li><li>GitLab Import API (preserves projects, metadata, pull requests, and user mapping)</li></ul><h4>Setup</h4><pre>git clone https://github.com/at-gmbh/bitbucket-to-gitlab.git<br>pip install -r requirements.txt</pre><p><strong>Set required environment variables:</strong></p><pre>export BITBUCKET_URL=https://bitbucket.company.com<br>export BITBUCKET_USER=admin<br>export BITBUCKET_TOKEN=your_bitbucket_token<br>export GITLAB_URL=https://gitlab.company.com<br>export GITLAB_TOKEN=your_gitlab_token</pre><p>Run the script:</p><pre>python main.py</pre><p>This approach:</p><ul><li>Preserves group/project structure</li><li>Copies memberships and permissions</li><li>Migrates personal projects as well</li></ul><pre>Bitbucket Repo<br> │<br> ▼<br> Bitbucket Import / Python Script<br> │<br> ▼<br> GitLab Project<br> │<br> ▼<br> CI/CD / Webhook Sync</pre><h3>3. Keeping Repositories in Sync During Migration</h3><p>Teams often continue using Bitbucket during migration. Two main options exist:</p><h4>3.1 GitLab Repository Mirroring</h4><ul><li>Go to: <strong>Settings → Repository → Mirroring repositories</strong></li><li>Enter your Bitbucket repository URL</li><li>Choose <strong>Pull</strong> (Bitbucket → GitLab)</li><li>Set a sync interval (e.g., every 5 minutes)</li></ul><h4>3.2 GitLab CI/CD with Bitbucket Webhook</h4><ul><li>Add .gitlab-ci.yml to both repositories:</li></ul><pre>stages:<br>  - sync<br><br>sync_from_bitbucket:<br>  stage: sync<br>  script:<br>    - git config --global user.name &quot;your_username&quot;<br>    - git config --global user.email &quot;your_email@example.com&quot;<br>    - git clone --mirror @bitbucket.org/username/repository.git&quot;&gt;https://${BITBUCKET_USER}:${BITBUCKET_TOKEN}@bitbucket.org/username/repository.git bitbucket-mirror<br>    - cd bitbucket-mirror<br>    - git push --mirror @gitlab.com/group/project.git&quot;&gt;https://${GITLAB_TOKEN}@gitlab.com/group/project.git</pre><ul><li>Add secrets (BITBUCKET_USER, BITBUCKET_TOKEN, GITLAB_TOKEN) in GitLab CI/CD variables</li><li>Configure a Bitbucket webhook to trigger the pipeline on push or merge events</li></ul><h3>4. User Contribution Mapping</h3><ul><li>The importer matches users by email address</li><li>If no match is found:</li></ul><p>-The project creator is used as a fallback</p><p>-Reviewers are not assigned</p><p>-Mentions are converted to static text</p><ul><li>GitLab can create new groups if they don’t exist</li></ul><h3>5. Common Issues &amp; Troubleshooting</h3><ul><li><strong>LFS objects fail to import</strong><br> — Tokens or passwords may contain special characters; generate a new token.</li><li><strong>Import URL blocked</strong><br> — Reverse proxy misconfiguration; check import_url via GitLab API.</li><li><strong>Sync not working with CI/CD</strong><br> — Verify webhook trigger, pipeline token, and permissions.</li></ul><h3>6. Post-Migration Steps</h3><ol><li>Validate repository integrity: commits, branches, and tags</li></ol><p>2. Update CI/CD pipelines to match GitLab environment</p><p>3. Inform your development team and provide onboarding</p><h3>Conclusion</h3><p>Migrating from Bitbucket to GitLab can be straightforward for small projects using GitLab’s native importer, but for larger environments, automation with Python scripts and CI/CD mirroring is essential. By carefully planning user mapping, repository synchronization, and post-migration validation, you can ensure a <strong>zero-data-loss transition with minimal disruption</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d00f103a5fd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ From Zero to Linux Hero: Mastering Commands, Architecture, and Admin Essentials]]></title>
            <link>https://medium.com/@bilgicsule/from-zero-to-linux-hero-mastering-commands-architecture-and-admin-essentials-fec8d9dc8d28?source=rss-6fcedddd996b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fec8d9dc8d28</guid>
            <category><![CDATA[debian]]></category>
            <category><![CDATA[redhat-linux]]></category>
            <category><![CDATA[centos]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[SuleBilgic]]></dc:creator>
            <pubDate>Thu, 03 Jul 2025 19:59:05 GMT</pubDate>
            <atom:updated>2025-07-03T22:01:05.002Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*WQCRV6632ZupFWDV6XKKJQ@2x.jpeg" /></figure><h3><strong><em>🐧What is Linux?</em></strong></h3><p>Linux is an open-source kernel that forms the backbone of many operating systems used today. Known for its reliability, security, and flexibility, Linux is favored by both individual users and large-scale enterprises. It is based on UNIX and follows the “Unix philosophy”, promoting modular, reusable, and minimal components. From desktop computers and servers to embedded systems and supercomputers, Linux is used across a wide range of platforms.</p><h3>🧩 Linux Distributions</h3><p>The Linux kernel is bundled with various utilities, system tools, and graphical interfaces to create what are known as distributions (or distros). Popular distributions include Ubuntu, Fedora, Debian, and CentOS, each offering ready-to-use operating systems tailored for different user needs.</p><p>Linux provides both a Command Line Interface (CLI) and a Graphical User Interface (GUI). It plays a crucial role in software development, system administration, network infrastructure, and cloud environments.</p><h3>🗂️ Linux File System Hierarchy</h3><p>The Linux file system follows a hierarchical tree structure, with everything stemming from the root directory (/). Here’s a breakdown of commonly used directories, especially in Debian-based systems like Ubuntu:</p><p>•	/bin: Essential binary commands accessible by all users</p><p>•	/boot: Contains bootloader, kernel, and boot-related files</p><p>•	/dev: Virtual files for accessing hardware devices</p><p>•	/etc: System-wide configuration files</p><p>•	/home: Personal directories for each user</p><p>•	/lib, /lib64: Shared libraries required by binaries and system processes</p><p>•	/media: Mount points for external devices (USB, CD/DVD)</p><p>•	/mnt: Used for temporary mounting</p><p>•	/opt: Optional and third-party application software</p><p>•	/proc: Virtual file system with runtime system info</p><p>•	/root: Home directory of the root (admin) user</p><p>•	/run: Temporary runtime files for system processes</p><p>•	/sbin: System binaries for administrative tasks</p><p>•	/srv: Service-related data</p><p>•	/sys: Interface for interacting with hardware/kernel</p><p>•	/tmp: Temporary files</p><p>•	/usr: User-installed applications, documentation, libraries</p><p>•	/var: Variable data like logs, spool files, and databases</p><h3>🔧 Essential Linux Commands</h3><h4>📁 File and Directory Management</h4><p>•	ls: List files and directories</p><p>•	ls -l: Detailed listing</p><p>•	ls -a: Show hidden files</p><p>•	cd: Change directories</p><p>•	cd ..: Go up one level</p><p>•	cd ~: Go to home directory</p><p>•	mkdir: Create directories</p><p>•	mkdir -p: Create nested directories</p><p>•	rm: Delete files/directories</p><p>•	rm -r: Recursively remove</p><p>•	rm -f: Force remove without prompt</p><p>•	cp: Copy files/directories</p><p>•	cp -r: Copy recursively</p><p>•	mv: Move or rename files</p><p>•	cat, head, tail, less: View file contents</p><p>•	tail -f: Follow live file updates (e.g., logs)</p><h3>⚙️ Process and System Monitoring</h3><p>•	ps: List running processes</p><p>•	top / htop: Real-time system monitoring</p><p>•	kill, killall: Terminate processes</p><h3>🌐 Networking and Internet Utilities</h3><p>•	ping: Check network connectivity</p><p>•	ip / ifconfig: Display network interfaces</p><p>•	netstat / ss: View active connections and ports</p><p>•	traceroute: Track the route of data packets</p><p>•	nslookup / dig / host: DNS query tools</p><p>•	scp / rsync: Secure and efficient file transfer</p><p>•	ssh: Secure remote access</p><p>•	nmap: Port scanning and network discovery</p><p>•	iptables: Firewall configuration</p><p>•	curl / wget: Download data from the web</p><h3>🔐 Permissions and Ownership</h3><p>chmod: Modify file permissions</p><p>Symbolic Mode Examples:</p><p>•	chmod u+rw file.txt: Add read/write to owner</p><p>•	chmod g-x script.sh: Remove execute for group</p><p>Numeric Mode Examples:</p><p>•	chmod 755 script.sh: Owner full, others read &amp; execute</p><p>•	chmod 700 private.txt: Full access only for owner</p><p>chown: Change file owner and group</p><p>•	chown user:group file</p><p>chgrp: Change group ownership</p><p>•	chgrp group_name file</p><h3>💡 Other Useful Commands</h3><p>•	pwd: Show current directory</p><p>•	df / du: Disk space usage</p><p>•	mount / umount: Mount or unmount storage devices</p><p>•	tar, gzip, unzip: Archive and compress files</p><p>•	man, info: Access manuals and documentation</p><p>•	uname, uptime, dmesg: System information</p><p>•	crontab, at: Schedule recurring or one-time tasks</p><p>•	adduser, deluser, passwd: Manage user accounts</p><p>•	alias, export, source: Shell environment configuration</p><h3>👩‍💻Hands-On: Practice Your First Linux Commands</h3><p>Let’s reinforce what you’ve learned by running some basic commands directly in the terminal. Follow each step in your own Linux environment to get hands-on experience.</p><p>📁 Step 1: Create and Enter a New Directory</p><pre>mkdir ~/linux_practice<br>cd ~/linux_practice</pre><p>📄 Step 2: Create Simple Files and List Them</p><pre>touch file1.txt file2.txt<br>ls -l</pre><p>📝 Step 3: Add Content to a File and Display It</p><pre>echo &quot;Hello Linux!&quot; &gt; file1.txt<br>cat file1.txt</pre><p>📂 Step 4: Copy and Rename a File</p><pre>cp file1.txt hello.txt<br>mv hello.txt greeting.txt<br>ls</pre><p>❌ Step 5: Delete Files and Folders</p><pre>rm file2.txt<br>cd ..<br>rm -r linux_practice</pre><p>🔍 Step 6: Display System Information</p><p>These short exercises give you a feel for how to work with files, navigate the filesystem, and query basic system info using the command line. Mastering these will build a strong foundation for more advanced tasks.</p><h3>✅ Conclusion</h3><p>Linux stands as a versatile and powerful operating system, ideal for both beginners and experienced system administrators. Through its robust command-line tools and customizable distributions, Linux offers complete control over system behavior. The information and commands presented here serve as a solid foundation for anyone looking to explore or deepen their understanding of Linux.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*j3yAR8GHpxg8eqzB6AqDRw@2x.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fec8d9dc8d28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating Artifact Registry with Cloud Functions Using Terraform on Google Cloud Platform]]></title>
            <link>https://medium.com/@bilgicsule/integrating-artifact-registry-with-cloud-functions-using-terraform-on-google-cloud-platform-883af2119476?source=rss-6fcedddd996b------2</link>
            <guid isPermaLink="false">https://medium.com/p/883af2119476</guid>
            <category><![CDATA[cloud-functions]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[artifact-registry]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[SuleBilgic]]></dc:creator>
            <pubDate>Sat, 11 Jan 2025 14:27:14 GMT</pubDate>
            <atom:updated>2025-01-11T14:27:14.993Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*PG3MFoTe7s19EV2xgiCW4Q.jpeg" /></figure><p>Google Cloud Platform (GCP) provides a wide range of powerful tools to simplify cloud application development. Among these tools, <strong>Artifact Registry</strong> and <strong>Cloud Functions</strong> stand out. <strong>Artifact Registry</strong> is a managed service that allows you to securely store software artifacts, while <strong>Cloud Functions</strong> enables serverless computing that reacts to events. This article will walk you through integrating these two services using <strong>Terraform</strong>, showing how you can automate workflows and simplify cloud-based operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/1*B2pO4SCzrz37tgOhIzCZtA.jpeg" /></figure><h3><strong>What is Artifact Registry and How Does It Work?</strong></h3><p>A<strong>rtifact Registry</strong> is Google Cloud’s managed repository service designed to store and manage your software artifacts. Whether it’s Docker images, Maven packages, or npm modules, you can use Artifact Registry to safely store and retrieve build outputs. It seamlessly integrates with CI/CD pipelines, making it ideal for automating build and release processes.</p><p><strong>Benefits of Using Artifact Registry</strong></p><ul><li><strong>Secure Storage</strong>: Artifact Registry ensures that only authorized users can access your artifacts, and it can detect security vulnerabilities before they reach production.</li><li><strong>Automated Build and Deployment</strong>: It integrates with CI/CD systems like GitHub and Bitbucket, automating the process of building and uploading artifacts whenever new code is pushed.</li><li><strong>Flexible Artifact Support</strong>: It supports various artifact formats, including Docker images, Maven packages, and npm modules, allowing you to store different types of artifacts in one place.</li><li><strong>High Availability</strong>: You can distribute your artifacts across multiple regions for high availability, ensuring fast access from anywhere.</li></ul><h3><strong>Cloud Functions: Simplifying Serverless Computing</strong></h3><p><strong>Cloud Functions</strong> is a serverless platform on Google Cloud that allows you to execute your code in response to specific events, without the need to manage servers or underlying infrastructure. This event-driven architecture makes it easy to build scalable applications that only consume resources when triggered.</p><h3>Key Benefits of Cloud Functions</h3><ul><li><strong>Serverless Architecture</strong>: You don’t need to worry about provisioning or managing servers — just write your function and link it to events.</li><li><strong>Easy Integration</strong>: Cloud Functions integrate easily with other Google Cloud services like Google Cloud Storage (GCS) and Pub/Sub, allowing you to automate tasks like file processing or data transformation.</li><li><strong>Event-driven Execution</strong>: Cloud Functions run only when an event occurs, saving on compute resources and allowing for more cost-effective operations.</li></ul><h3>Integrating Artifact Registry with Cloud Functions Using Terraform</h3><p><strong>Terraform</strong> is an infrastructure-as-code tool that allows you to automate the deployment and management of resources on Google Cloud. In this section, we’ll explore how to integrate <strong>Artifact Registry</strong> with <strong>Cloud Functions</strong> using Terraform, creating a complete, automated cloud-based solution.</p><h3>1. Prerequisites</h3><p>Before we start, make sure you have the following:</p><ul><li><strong>Terraform</strong> installed locally.</li><li><strong>Google Cloud SDK</strong> for interacting with Google Cloud.</li><li>A <strong>Google Cloud project</strong> set up in your GCP console.</li><li><strong>Cloud Functions API</strong> enabled for your project.</li></ul><h3>2. Project Structure and Code Setup</h3><p>We’ll organize the project into two main directories:</p><ul><li><strong>src/</strong>: This folder will contain the source code for the Cloud Function.</li><li><strong>terraform/</strong>: This folder will house the Terraform configuration files.</li></ul><h4>Cloud Function Python Code</h4><p>Let’s write a simple Cloud Function that will be triggered when a file is uploaded to a GCS bucket. The function will log the file’s name and size for demonstration purposes.</p><p><strong>src/main.py</strong>:</p><pre><br>def file_upload_trigger(event, context):<br>    # Extract the file details from the event<br>    file_details = event<br><br>    # Get relevant information<br>    bucket_name = file_details[&#39;bucket&#39;]<br>    file_name = file_details[&#39;name&#39;]<br>    file_size = file_details[&#39;size&#39;]<br><br>    # Log the information<br>    print(f&quot;File uploaded: {file_name}, Bucket: {bucket_name}, Size: {file_size} bytes&quot;)<br><br>    # You can add additional processing logic here<br><br>    return &quot;File processing completed.&quot;</pre><p>This function gets triggered when a file is uploaded to a specific <strong>GCS bucket</strong>.</p><h3>3. Terraform Configuration</h3><h4>Setting Up the Google Cloud Provider</h4><p>We need to declare the Google provider in Terraform to interact with Google Cloud.</p><p><strong>provider.tf</strong>:</p><pre>provider &quot;google&quot; {<br>  project = var.project_id<br>  region  = var.region<br>}</pre><p>Next, let’s create an Artifact Registry repository where the Cloud Function code will be stored.</p><p><strong>artifact-registry.tf</strong>:</p><pre>resource &quot;google_artifact_registry_repository&quot; &quot;function_artifact_repo&quot; {<br>  project       = var.project_id<br>  location      = var.region<br>  repository_id = &quot;cloud-function-repo&quot;<br>  format        = &quot;DOCKER&quot;<br>  description   = &quot;Artifact repository for Cloud Function images&quot;<br>}</pre><h4>Cloud Function Configuration</h4><p>Now, let’s configure the Cloud Function, which will be triggered by file uploads to a specific bucket.</p><p><strong>cloudfunction.tf</strong>:</p><pre>resource &quot;google_cloudfunctions_function&quot; &quot;upload_function&quot; {<br>  name                  = &quot;cloud-function-upload-trigger&quot;<br>  description           = &quot;Cloud Function that gets triggered on file upload&quot;<br>  runtime               = &quot;python39&quot;<br>  project               = var.project_id<br>  region                = var.region<br>  source_archive_bucket = google_storage_bucket.source_bucket.name<br>  source_archive_object = google_storage_bucket_object.zip.name<br>  entry_point           = &quot;file_upload_trigger&quot;<br>  event_trigger {<br>    event_type = &quot;google.storage.object.finalize&quot;<br>    resource   = &quot;input-bucket-${var.project_id}&quot;<br>  }<br>  docker_repository = &quot;projects/${var.project_id}/locations/${var.region}/repositories/${google_artifact_registry_repository.function_artifact_repo.name}&quot;<br>}</pre><h3>4. Deploying the Infrastructure</h3><p>Now, it’s time to deploy the infrastructure using Terraform. Follow these steps to initialize, plan, and apply your changes:</p><pre>$ terraform init         # Initialize the Terraform workspace<br>$ terraform plan         # Review the execution plan<br>$ terraform apply -auto-approve  # Apply the changes</pre><h3>5. Testing the Setup</h3><p>Once the infrastructure is deployed, you can test it by uploading a file to the <strong>input bucket</strong> in Google Cloud Storage.</p><ul><li>Go to the <strong>GCS Console</strong> and upload a file to the <strong>input bucket</strong>.</li><li>You can check the <strong>Cloud Functions</strong> console to see if the function was triggered successfully.</li></ul><h3>6. Cleaning Up Resources</h3><p>After testing, you may want to clean up your resources to avoid incurring unnecessary costs. You can do this by running the following command:</p><pre>$ terraform destroy --auto-approve</pre><h3>Conclusion</h3><p>This guide explored the integration of Artifact Registry and Cloud Functions on Google Cloud Platform using Terraform. By automating the configuration of these services, a streamlined, serverless workflow is created for handling file uploads, processing, and artifact storage. Any questions or suggestions can be shared in the comments.</p><p>Also, feel free to share this article with colleagues!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=883af2119476" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Generate Self-Signed Certificates and Keys Using OpenSSL]]></title>
            <link>https://medium.com/@bilgicsule/generate-self-signed-certificates-and-keys-using-openssl-ad1d998671f5?source=rss-6fcedddd996b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad1d998671f5</guid>
            <category><![CDATA[ssl-certificate]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[SuleBilgic]]></dc:creator>
            <pubDate>Thu, 15 Aug 2024 20:58:16 GMT</pubDate>
            <atom:updated>2024-08-15T21:00:06.792Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Generate Self-Signed Certificates and Keys Using OpenSSL</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*nMdf4Ed5nakFS9JxZUUWVg.png" /></figure><p>Creating self-signed certificates and keys with OpenSSL is a common task for setting up secure communication channels, particularly in development or testing environments where a fully-trusted certificate authority (CA) is not necessary. OpenSSL is a widely-used open-source toolkit for working with Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols.</p><p>Here’s a step-by-step guide on how to create self-signed certificates and keys using OpenSSL:</p><ol><li>Install OpenSSL: Ensure that OpenSSL is installed on your system. If not, you can download and install it from the official <a href="https://www.openssl.org/">OpenSSL website</a> or use your operating system’s package manager to install it.</li><li>Generate a Private Key: The first step is to generate a private key. You can do this using the following OpenSSL command:</li></ol><pre>openssl genpkey -algorithm RSA -out key.pem</pre><ol><li>This command generates a new RSA private key and saves it to a file named key.pem.</li><li>Generate a Self-Signed Certificate: Once you have the private key, you can use it to generate a self-signed certificate:</li></ol><pre>openssl req -new -x509 -key key.pem -out cert.pem -days 365</pre><ol><li>This command creates a new self-signed X.509 certificate using the private key (key.pem) generated earlier. The -days option specifies the validity period of the certificate in days (365 in this example).</li><li>Provide Certificate Information: During the certificate generation process, OpenSSL will prompt you to provide information such as country, state, locality, organization, and common name. This information will be embedded in the certificate.</li><li>Verify the Certificate: You can verify the contents of the generated certificate using the following command:</li></ol><pre>openssl x509 -text -noout -in cert.pem</pre><ol><li>This command displays detailed information about the certificate.</li><li>(Optional) Convert Formats: Depending on your requirements, you may need to convert the certificate and private key to different formats (e.g., PEM, DER). You can use OpenSSL commands like openssl rsa and openssl x509 to perform these conversions.</li><li>Usage: Once you have the self-signed certificate (cert.pem) and private key (key.pem), you can use them in your applications to enable secure communication over HTTPS, TLS, or other protocols that require SSL/TLS certificates.</li></ol><p>Remember that self-signed certificates are not trusted by default by web browsers and other clients, so they are primarily suitable for development, testing, or internal use cases where trust validation is not critical. In production environments, it’s recommended to use certificates signed by a trusted CA.</p><p>Database components from MariaDB Corporation support data-in-transit encryption, which secures data transmitted over the network. The server and the clients encrypt data using the Transport Layer Security (TLS) protocol, which is a newer version of the Secure Socket Layer (SSL) protocol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*QOsErP3alr9CI652MkojZg.jpeg" /></figure><h3>Creating the Certificate Authority’s Certificate and Keys</h3><ol><li>Generate a private key for the CA:</li></ol><pre>openssl genrsa 2048 &gt; ca-key.pem</pre><p>2. Generate the X509 certificate for the CA:</p><pre>openssl req -new -x509 -nodes -days 365000 \<br>   -key ca-key.pem \<br>   -out ca-cert.pem</pre><h3>Creating the Server’s Certificate and Keys</h3><ol><li>Generate the private key and certificate request:</li></ol><pre>openssl req -newkey rsa:2048 -nodes -days 365000 \<br>   -keyout server-key.pem \<br>   -out server-req.pem</pre><p>2. Generate the X509 certificate for the server:</p><pre>openssl x509 -req -days 365000 -set_serial 01 \<br>   -in server-req.pem \<br>   -out server-cert.pem \<br>   -CA ca-cert.pem \<br>   -CAkey ca-key.pem</pre><h3>Creating the Client’s Certificate and Keys</h3><ol><li>Generate the private key and certificate request:</li></ol><pre>openssl req -newkey rsa:2048 -nodes -days 365000 \<br>   -keyout client-key.pem \<br>   -out client-req.pem</pre><p>2. Generate the X509 certificate for the client:</p><pre>openssl x509 -req -days 365000 -set_serial 01 \<br>   -in client-req.pem \<br>   -out client-cert.pem \<br>   -CA ca-cert.pem \<br>   -CAkey ca-key.pem</pre><h3>Verifying the Certificates</h3><ol><li>Verify the server certificate:</li></ol><pre>openssl verify -CAfile ca-cert.pem \<br>   ca-cert.pem \<br>   server-cert.pem</pre><p>2. Verify the client certificate:</p><pre>openssl verify -CAfile ca-cert.pem \<br>   ca-cert.pem \<br>   client-cert.pem</pre><p><strong>If you liked the article, I would be happy if you click on the </strong><a href="https://medium.com/@bilgicsule"><strong>Medium Following</strong></a><strong> button to encourage me to write and not miss future articles.</strong></p><p>Your clapping, following, and subscribing help my articles to reach a broader audience. Thank you in advance for them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad1d998671f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Provisioning a Kubernetes Cluster Using Terraform on Amazon Web Services]]></title>
            <link>https://medium.com/@bilgicsule/provisioning-a-kubernetes-cluster-using-terraform-on-amazon-web-services-2023070937b5?source=rss-6fcedddd996b------2</link>
            <guid isPermaLink="false">https://medium.com/p/2023070937b5</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <dc:creator><![CDATA[SuleBilgic]]></dc:creator>
            <pubDate>Sat, 11 May 2024 15:19:44 GMT</pubDate>
            <atom:updated>2024-05-12T09:59:44.667Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*C7nASiicxGZ4If5uUcQRoA.jpeg" /></figure><p>The HashiCorp Terraform is a tool for infrastructure as code (IaC), enabling the definition of computing resources on cloud servers or on-premise servers. This allows users to create a human-readable Terraform configuration code, facilitating the provisioning of new resources to their desired cloud or on-premise servers. Through the Terraform language, users craft configuration files that serve as easily understandable blueprints for resource allocation.</p><p>Reference: <a href="https://developer.hashicorp.com/terraform/intro">https://developer.hashicorp.com/terraform/intro</a></p><h3>Preparation</h3><p>· An IAM user with full administrative access on an AWS Free-tier account<br>· Visual Studio Code or AWS Cloud9 (I am using Visual Studio Code)</p><h3><strong>Guide</strong></h3><p><strong>(0) Establishing Connection to AWS Service</strong></p><p>Before accessing AWS resources, our local server must establish a connection with the AWS service. To achieve this, we’ll utilize the Terraform AWS provider outlined below.</p><p>In consideration of security, especially regarding sensitive information, such as our AWS Access Key and Secret Access Key, we refrain from explicitly stating these values, except for the AWS region. Instead, we opt to configure Environment variables for these values within our local Linux command prompt.</p><p>Please be aware: while you have the option to execute the “aws configure” command on your local Linux server for Terraform-AWS communication, this method is not endorsed by HashiCorp Terraform. Personally, I encountered certain issues when attempting to retrieve data on AWS resources created by Terraform. Therefore, it’s advisable to explicitly set your Terraform environment variables on our local Linux server for the sake of security.</p><pre>export AWS_ACCESS_KEY_ID = &quot;xxxxxxxxx&quot;<br>export AWS_SECRET_ACCESS_KEY = &quot;yyyyyyyyy&quot;</pre><p>(1) In the Terraform code you provided, the configuration consists of a terraform block and a provider block.</p><p>The terraform block serves to configure Terraform settings. In this instance, it delineates the requisite providers and their versions. Within the required_providers block, it is stated that the configuration necessitates the AWS provider from HashiCorp, with a version constraint of “~&gt; 4.0”. This specification implies that Terraform will employ a version of the AWS provider that falls within the 4.x.x range, wherein x denotes any compatible version that does not entail a major version alteration.</p><p>The provider block undertakes the configuration of the AWS provider, defining the region as “us-east-1”. Tasked with interfacing with the Amazon Web Services (AWS) API, the AWS provider facilitates resource management within an AWS account. By designating the region, Terraform is instructed to operate within the “us-east-1” region, more commonly recognized as the N. Virginia region.</p><p>Equipped with these configurations, Terraform will leverage the AWS provider to oversee resources within the specified region. You can then proceed to define AWS resources such as EC2 instances, S3 buckets, or VPCs, whereby Terraform will effectuate the creation, updating, or deletion of said resources in accordance with your Terraform code.</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 4.0&quot;<br>    }<br>  }<br>}<br><br>provider &quot;aws&quot; {<br>  region  = &quot;us-east-1&quot;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ITyunsSSHnJlvfQxcdSX-g.png" /></figure><p>(2) The Terraform code you provided is using two data blocks, aws_caller_identity and aws_region, to retrieve information about the current AWS caller identity and the current AWS region, respectively.</p><p>The aws_caller_identity data source retrieves information about the identity that is making the Terraform API request. This includes the AWS account ID, the ARN (Amazon Resource Name) of the IAM user or role, and the user-friendly account alias if one is set. This data can be useful for various purposes, such as logging or resource tagging.</p><p>The aws_region data source retrieves information about the AWS region where the Terraform provider is configured to operate. This data can be used to ensure that resources are created in the correct region or to provide region-specific configuration options.</p><p>By incorporating these data sources into your Terraform configuration, you gain the capability to dynamically fetch and utilize the present AWS caller identity and region within your resource specifications or variable allocations. This functionality enables your infrastructure code to adjust to the precise context of the AWS environment in which it is deployed, enhancing its flexibility and reusability across various regions and accounts.</p><pre>data &quot;aws_caller_identity&quot; &quot;current&quot; {}<br><br>data &quot;aws_region&quot; &quot;current&quot; {}</pre><p>(3) In the Terraform code you provided, the locals block is used to define local variables. Local variables are useful for storing intermediate values or calculations within your Terraform configuration.</p><p>In your example, the locals block defines three local variables: name, keyname, and instancetype. Here&#39;s a breakdown of each variable:</p><ol><li>name =&quot;sule&quot;: This variable is set to the string value &quot;sule&quot;. It can be used to specify a name or identifier for a resource, such as an EC2 instance, that you are creating in your Terraform configuration. You can change the value of this variable to suit your specific requirements.</li><li>keyname = &quot;Devops&quot;: This variable is set to the string value &quot;Devops&quot;. It can be used to specify the name of an SSH key pair that you want to associate with an EC2 instance. The key pair allows you to securely connect to the instance using SSH. You can modify the value of this variable based on the SSH key pair you have created in your AWS account.</li><li>instancetype = &quot;t3a.medium&quot;: This variable is set to the string value &quot;t3a.medium&quot;. It can be used to specify the instance type for an EC2 instance. The instance type determines the hardware specifications of the instance, such as CPU, memory, and network performance. You can adjust the value of this variable to select the appropriate instance type for your workload.</li></ol><p>By using local variables, you can centralize and manage these values in one place, making it easier to update and reuse them throughout your Terraform configuration. Additionally, using local variables can improve readability and maintainability of your code by providing meaningful names for commonly used values.</p><pre>locals {<br>  # change here, optional<br>  name = &quot;sule&quot;<br>  keyname = &quot;Devops&quot;<br>  instancetype = &quot;t3a.medium&quot;<br>  ami = &quot;ami-0557a15b87f6559cf&quot;<br>}</pre><p>(4) The Terraform code you provided defines two resources of type aws_instance. Let&#39;s go through each resource individually:</p><ol><li>Resource “aws_instance” “master”:</li></ol><ul><li>This resource represents an EC2 instance and is identified by the resource name “master”.</li><li>The attributes of the EC2 instance are specified using various arguments:</li><li>ami: It is set to the value of the local variable local.ami. The local variable ami is expected to hold the ID of the Amazon Machine Image (AMI) to be used for the EC2 instance.</li><li>instance_type: It is set to the value of the local variable local.instancetype. The local variable instancetype is expected to hold the instance type for the EC2 instance (e.g., &quot;t3a.medium&quot;).</li><li>key_name: It is set to the value of the local variable local.keyname. The local variable keyname is expected to hold the name of the SSH key pair to associate with the EC2 instance.</li><li>iam_instance_profile: It is set to the name attribute of the resource aws_iam_instance_profile.ec2connectprofile. This attribute specifies the IAM instance profile to associate with the EC2 instance.</li><li>user_data: It is set to the rendered output of the data.template_file.master. The data.template_file retrieves the content of a template file, and in this case, it is expected to be used as the user data for the EC2 instance.</li><li>vpc_security_group_ids: It is set to an array containing the ID of the security group aws_security_group.tf-k8s-master-sec-gr. This specifies the security group(s) to associate with the EC2 instance.</li><li>tags: It is a map of key-value pairs that assigns tags to the EC2 instance. In this case, it sets the &quot;Name&quot; tag to &quot;${local.name}-kube-master&quot;.</li></ul><p>2. Resource “aws_instance” “worker”:</p><ul><li>This resource represents another EC2 instance and is identified by the resource name “worker”.</li><li>Similar to the “master” resource, it specifies various attributes for the EC2 instance.</li><li>The key differences compared to the “master” resource are as follows:</li><li>The user_data argument is set to the rendered output of data.template_file.worker.</li><li>It includes a depends_on attribute, which specifies that the &quot;worker&quot; instance depends on the &quot;master&quot; instance. This ensures that the &quot;worker&quot; instance is created only after the &quot;master&quot; instance has been successfully created.</li></ul><p>With these resource definitions, Terraform will create two EC2 instances using the specified attributes and configurations. The “worker” instance is dependent on the “master” instance, meaning that Terraform will create the “master” instance first before creating the “worker” instance.</p><pre>resource &quot;aws_instance&quot; &quot;master&quot; {<br>  ami                  = local.ami<br>  instance_type        = local.instancetype<br>  key_name             = local.keyname<br>  iam_instance_profile = aws_iam_instance_profile.ec2connectprofile.name<br>  user_data            = data.template_file.master.rendered<br>  vpc_security_group_ids = [aws_security_group.tf-k8s-master-sec-gr.id]<br>  tags = {<br>    Name = &quot;${local.name}-kube-master&quot;<br>  }<br>}<br><br>resource &quot;aws_instance&quot; &quot;worker&quot; {<br>  ami                  = local.ami<br>  instance_type        = local.instancetype<br>  key_name             = local.keyname<br>  iam_instance_profile = aws_iam_instance_profile.ec2connectprofile.name<br>  vpc_security_group_ids = [aws_security_group.tf-k8s-master-sec-gr.id]<br>  user_data            = data.template_file.worker.rendered<br>  tags = {<br>    Name = &quot;${local.name}-kube-worker&quot;<br>  }<br>  depends_on = [aws_instance.master]<br>}</pre><p>(5) The Terraform code you provided defines two IAM-related resources: aws_iam_instance_profile and aws_iam_role.</p><ol><li>Resource “aws_iam_instance_profile” “ec2connectprofile”:</li></ol><ul><li>This resource represents an IAM instance profile and is identified by the resource name “ec2connectprofile”.</li><li>The attributes of the IAM instance profile are specified using various arguments:</li><li>name: It is set to &quot;ec2connectprofile-${local.name}&quot;. The local.name variable is expected to hold a specific name or identifier.</li><li>role: It is set to the name attribute of the resource aws_iam_role.ec2connectcli. This attribute specifies the IAM role associated with the instance profile.</li></ul><p>2. Resource “aws_iam_role” “ec2connectcli”:</p><ul><li>This resource represents an IAM role and is identified by the resource name “ec2connectcli”.</li><li>The attributes of the IAM role are specified using various arguments:</li><li>name: It is set to &quot;ec2connectcli-${local.name}&quot;. The local.name variable is expected to hold a specific name or identifier.</li><li>assume_role_policy: It is set to the JSON-encoded policy document that defines the trust relationship for the IAM role. In this case, the policy document allows the EC2 service (ec2.amazonaws.com) to assume the role by allowing the sts:AssumeRole action.</li></ul><p>These IAM resources are commonly used when configuring EC2 instances with specific permissions and access control. The aws_iam_role resource defines a role with a specific trust policy, allowing EC2 instances to assume this role. The aws_iam_instance_profile resource associates the IAM role with an instance profile, enabling the EC2 instances to inherit the permissions and access granted by the role.</p><p>By using these resources in your Terraform configuration, you can create and manage IAM roles and instance profiles, which are fundamental components for managing fine-grained access control and permissions within your AWS environment.</p><pre>resource &quot;aws_iam_instance_profile&quot; &quot;ec2connectprofile&quot; {<br>  name = &quot;ec2connectprofile-${local.name}&quot;<br>  role = aws_iam_role.ec2connectcli.name<br>}<br><br>resource &quot;aws_iam_role&quot; &quot;ec2connectcli&quot; {<br>  name = &quot;ec2connectcli-${local.name}&quot;<br>  assume_role_policy = jsonencode({<br>    Version = &quot;2012-10-17&quot;<br>    Statement = [<br>      {<br>        Action = &quot;sts:AssumeRole&quot;<br>        Effect = &quot;Allow&quot;<br>        Sid    = &quot;&quot;<br>        Principal = {<br>          Service = &quot;ec2.amazonaws.com&quot;<br>        }<br>      },<br>    ]<br>  })</pre><p>(6) The code you provided contains an inline_policy block that defines an inline IAM policy for an IAM role or user. Inline policies are directly attached to a specific IAM entity and are part of the IAM entity&#39;s policy document. Let&#39;s break down the inline policy configuration:</p><p>Here’s an explanation of the inline policy configuration:</p><ul><li>name: It specifies the name of the inline policy. In this case, it is set to &quot;my_inline_policy&quot;.</li><li>policy: It defines the policy document using JSON encoding. The policy document contains a Version field indicating the version of the policy language being used. In this case, it is set to &quot;2012-10-17&quot;. The Statement field is an array that contains one or more policy statements.</li><li>First Statement:</li><li>Effect: It specifies the effect of the policy statement, which can be either &quot;Allow&quot; or &quot;Deny&quot;. In this case, it is set to &quot;Allow&quot;.</li><li>Action: It specifies the action(s) allowed or denied by the policy statement. Here, it allows the &quot;ec2-instance-connect:SendSSHPublicKey&quot; action, which is used for EC2 Instance Connect to send an SSH public key during instance launch.</li><li>Resource: It specifies the resource(s) to which the policy statement applies. The value is an ARN (Amazon Resource Name) pattern using Terraform interpolation to dynamically populate the AWS region (data.aws_region.current.name) and AWS account ID (data.aws_caller_identity.current.account_id) based on the current context. The pattern includes the wildcard * to match all EC2 instances in the specified region and account.</li><li>Condition: It specifies additional conditions that must be met for the policy statement to take effect. In this case, it checks if the value of the &quot;ec2:osuser&quot; condition key is equal to &quot;ubuntu&quot;.</li><li>Second Statement:</li><li>Effect: It is set to &quot;Allow&quot;.</li><li>Action: It allows the &quot;ec2:DescribeInstances&quot; action, which allows the entity associated with this policy to describe EC2 instances.</li><li>Resource: It is set to &quot;*&quot; to indicate that the statement applies to all resources.</li></ul><p>This inline policy allows the IAM entity associated with the role or user to perform the specified actions on EC2 instances. The first statement specifically allows sending SSH public keys during EC2 instance launch, but only if the instance’s operating system user is “ubuntu”. The second statement allows describing all EC2 instances.</p><pre>inline_policy {<br>    name = &quot;my_inline_policy&quot;<br><br>    policy = jsonencode({<br>      Version = &quot;2012-10-17&quot;<br>      Statement = [<br>        {<br>          &quot;Effect&quot; : &quot;Allow&quot;,<br>          &quot;Action&quot; : &quot;ec2-instance-connect:SendSSHPublicKey&quot;,<br>          &quot;Resource&quot; : &quot;arn:aws:ec2:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:instance/*&quot;,<br>          &quot;Condition&quot; : {<br>            &quot;StringEquals&quot; : {<br>              &quot;ec2:osuser&quot; : &quot;ubuntu&quot;<br>            }<br>          }<br>        },<br>        {<br>          &quot;Effect&quot; : &quot;Allow&quot;,<br>          &quot;Action&quot; : &quot;ec2:DescribeInstances&quot;,<br>          &quot;Resource&quot; : &quot;*&quot;<br>        }<br>      ]<br>    })<br>  }<br>}</pre><p>(7) The Terraform code you provided includes two data blocks that use the template_file data source.</p><ol><li>data &quot;template_file&quot; &quot;worker&quot;:</li></ol><ul><li>This block defines a data source named “worker” using the template_file data source type.</li><li>The template argument specifies the file path to a template file named &quot;worker.sh&quot;.</li><li>The vars block is used to provide variable values to be used within the template file.</li><li>The region variable is set to the value of data.aws_region.current.name, which retrieves the current AWS region.</li><li>The master-id variable is set to aws_instance.master.id, which retrieves the ID of the &quot;master&quot; EC2 instance.</li><li>The master-private variable is set to aws_instance.master.private_ip, which retrieves the private IP address of the &quot;master&quot; EC2 instance.</li></ul><p>2. data &quot;template_file&quot; &quot;master&quot;:</p><ul><li>This block defines a data source named “master” using the template_file data source type.</li><li>The template argument specifies the file path to a template file named &quot;master.sh&quot;.</li></ul><p>The template_file data source is used to read the content of the specified template file and perform variable substitution using the provided variable values. The template files, &quot;worker.sh&quot; and &quot;master.sh&quot;, should be located in the same directory as the Terraform configuration file.</p><p>These data sources are useful when you need to dynamically generate or configure files based on variables or other information. In this case, the template files may contain shell scripts or configuration files that can be customized based on the region, the ID and private IP of the “master” EC2 instance, or any other data you wish to include.</p><pre>data &quot;template_file&quot; &quot;worker&quot; {<br>  template = file(&quot;worker.sh&quot;)<br>  vars = {<br>    region = data.aws_region.current.name<br>    master-id = aws_instance.master.id<br>    master-private = aws_instance.master.private_ip<br>  }<br><br>}<br><br>data &quot;template_file&quot; &quot;master&quot; {<br>  template = file(&quot;master.sh&quot;)<br>}</pre><p>(8) The Terraform code you provided defines a resource of type aws_security_group named &quot;tf-k8s-master-sec-gr&quot;. This resource represents a security group that controls inbound and outbound traffic for your EC2 instances.</p><p>Let’s break down the configuration of the aws_security_group resource:</p><ul><li>name: It is set to &quot;${local.name}-k8s-master-sec-gr&quot;, where local.name is a local variable that holds a specific name or identifier. The name of the security group will be derived from this value.</li><li>tags: It is a map of key-value pairs that assigns tags to the security group. In this case, it sets the &quot;Name&quot; tag to &quot;${local.name}-k8s-master-sec-gr&quot;, which is the same as the security group&#39;s name.</li><li>ingress blocks: These blocks define inbound rules for the security group. Each ingress block represents a separate rule. In this configuration, the following ingress rules are defined:</li><li>The first rule allows all traffic within the security group itself (self = true).</li><li>The second rule allows inbound SSH traffic on port 22 from any source IP address (0.0.0.0/0).</li><li>The third rule allows inbound HTTP traffic on port 80 from any source IP address.</li><li>The fourth rule allows inbound TCP traffic in the range of ports 30000–32767 from any source IP address.</li><li>egress block: This block defines outbound rules for the security group. In this configuration, it allows all outbound traffic (0.0.0.0/0) with any protocol on any port.</li></ul><p>The security group rules specified in the ingress and egress blocks determine the allowed inbound and outbound traffic for the associated EC2 instances. In this case, the security group allows inbound SSH, HTTP, and a range of TCP ports traffic, while allowing all outbound traffic.</p><p>Note: The configuration provided allows traffic from any source IP address (0.0.0.0/0) on certain ports, which may introduce security risks. It is recommended to restrict the allowed IP ranges and protocols based on your specific requirements and security best practices.</p><pre>resource &quot;aws_security_group&quot; &quot;tf-k8s-master-sec-gr&quot; {<br>  name = &quot;${local.name}-k8s-master-sec-gr&quot;<br>  tags = {<br>    Name = &quot;${local.name}-k8s-master-sec-gr&quot;<br>  }<br><br>  ingress {<br>    from_port = 0<br>    protocol  = &quot;-1&quot;<br>    to_port   = 0<br>    self = true<br>  }<br><br>  ingress {<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  ingress {<br>    from_port   = 30000<br>    to_port     = 32767<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    protocol    = &quot;-1&quot;<br>    to_port     = 0<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}</pre><p>(9) The Terraform code you provided defines four outputs that retrieve and expose the DNS information for the “master” and “worker” EC2 instances. These outputs can be useful for obtaining the DNS addresses of the instances after they have been provisioned. Here’s an explanation of each output:</p><p>1. output &quot;master_public_dns&quot;:</p><ul><li>This output exposes the public DNS address of the “master” EC2 instance.</li><li>The value is obtained by referencing the public_dns attribute of the aws_instance.master resource.</li></ul><p>2. output &quot;master_private_dns&quot;:</p><ul><li>This output exposes the private DNS address of the “master” EC2 instance.</li><li>The value is obtained by referencing the private_dns attribute of the aws_instance.master resource.</li></ul><p>3. output &quot;worker_public_dns&quot;:</p><ul><li>This output exposes the public DNS address of the “worker” EC2 instance.</li><li>The value is obtained by referencing the public_dns attribute of the aws_instance.worker resource.</li></ul><p>4. output &quot;worker_private_dns&quot;:</p><ul><li>This output exposes the private DNS address of the “worker” EC2 instance.</li><li>The value is obtained by referencing the private_dns attribute of the aws_instance.worker resource.</li></ul><p>By defining these outputs, you can easily access and display the DNS addresses of the provisioned EC2 instances using the Terraform output command (terraform output). This can be helpful when you need to access the instances via DNS or when you want to retrieve the DNS information for further configuration or integration purposes.</p><pre>output &quot;master_public_dns&quot; {<br>  value = aws_instance.master.public_dns<br>}<br><br>output &quot;master_private_dns&quot; {<br>  value = aws_instance.master.private_dns<br>}<br><br>output &quot;worker_public_dns&quot; {<br>  value = aws_instance.worker.public_dns<br>}<br><br>output &quot;worker_private_dns&quot; {<br>  value = aws_instance.worker.private_dns<br>}</pre><p>(10) The provided script is a Bash script that sets up a Kubernetes master node. It performs the following steps:</p><ol><li>Updates the package list and upgrades the installed packages.</li><li>Sets the hostname of the machine to “kube-master”.</li><li>Installs necessary packages for Kubernetes, such as apt-transport-https, ca-certificates, and curl.</li><li>Adds the Google Cloud apt repository key.</li><li>Adds the Kubernetes apt repository to the package sources.</li><li>Updates the package list again to include the Kubernetes packages.</li><li>Installs specific versions of Kubernetes components: kubelet, kubeadm, kubectl, kubernetes-cni, and docker.io.</li><li>Holds the installed Kubernetes packages to prevent them from being automatically upgraded.</li><li>Starts and enables the Docker service.</li><li>Adds the current user to the docker group.</li><li>Modifies the kernel parameters in /etc/sysctl.d/k8s.conf to enable network bridging and IP forwarding.</li><li>Applies the kernel parameters using sysctl --system.</li><li>Creates the /etc/containerd/config.toml file with default configuration for the container runtime.</li><li>Modifies the config.toml file to enable systemd cgroup integration.</li><li>Restarts and enables the containerd service.</li><li>Pulls the necessary container images required by kubeadm.</li><li>Initializes the Kubernetes control plane using kubeadm init, specifying the pod network CIDR and ignoring preflight errors.</li><li>Creates the .kube directory in the home directory of the user &quot;ubuntu&quot;.</li><li>Copies the admin.conf file to the user’s .kube/config file, allowing them to access the cluster.</li><li>Changes the ownership of the .kube/config file to the user &quot;ubuntu&quot;.</li><li>Switches to the “ubuntu” user and applies the Kubernetes network configuration using the Flannel CNI plugin.</li></ol><p>Note: This script assumes that it is run with root privileges, as it uses commands like apt-get and modifies system-level configurations.</p><pre>#! /bin/bash<br>apt-get update -y<br>apt-get upgrade -y<br>hostnamectl set-hostname kube-master<br>apt-get install -y apt-transport-https ca-certificates curl<br>curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -<br>echo &quot;deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://apt.kubernetes.io/ kubernetes-xenial main&quot; | sudo tee /etc/apt/sources.list.d/kubernetes.list<br>apt-get update<br>apt-get install -y kubelet=1.26.3-00 kubeadm=1.26.3-00 kubectl=1.26.3-00 kubernetes-cni docker.io<br>apt-mark hold kubelet kubeadm kubectl<br>systemctl start docker<br>systemctl enable docker<br>usermod -aG docker ubuntu<br>newgrp docker<br>cat &lt;&lt;EOF | sudo tee /etc/sysctl.d/k8s.conf<br>net.bridge.bridge-nf-call-iptables  = 1<br>net.bridge.bridge-nf-call-ip6tables = 1<br>net.ipv4.ip_forward                 = 1<br>EOF<br>sysctl --system<br>mkdir /etc/containerd<br>containerd config default | sudo tee /etc/containerd/config.toml &gt;/dev/null 2&gt;&amp;1<br>sed -i &#39;s/SystemdCgroup \= false/SystemdCgroup \= true/g&#39; /etc/containerd/config.toml<br>systemctl restart containerd<br>systemctl enable containerd<br>kubeadm config images pull<br>kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=All<br>mkdir -p /home/ubuntu/.kube<br>cp -i /etc/kubernetes/admin.conf /home/ubuntu/.kube/config<br>chown ubuntu:ubuntu /home/ubuntu/.kube/config<br>su - ubuntu -c &#39;kubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml&#39;</pre><p>(11) The provided script is a Bash script that sets up a Kubernetes worker node. It performs the following steps:</p><ol><li>Updates the package list and upgrades the installed packages.</li><li>Sets the hostname of the machine to “kube-worker”.</li><li>Installs necessary packages for Kubernetes, such as apt-transport-https, ca-certificates, and curl.</li><li>Adds the Google Cloud apt repository key.</li><li>Adds the Kubernetes apt repository to the package sources.</li><li>Updates the package list again to include the Kubernetes packages.</li><li>Installs specific versions of Kubernetes components: kubelet, kubeadm, kubectl, kubernetes-cni, and docker.io.</li><li>Holds the installed Kubernetes packages to prevent them from being automatically upgraded.</li><li>Starts and enables the Docker service.</li><li>Adds the current user to the docker group.</li><li>Switches to the “docker” group.</li><li>Modifies the kernel parameters in /etc/sysctl.d/k8s.conf to enable network bridging and IP forwarding.</li><li>Applies the kernel parameters using sysctl --system.</li><li>Creates the /etc/containerd/config.toml file with default configuration for the container runtime.</li><li>Modifies the config.toml file to enable systemd cgroup integration.</li><li>Restarts and enables the containerd service.</li><li>Downloads the get-pip.py script from the internet.</li><li>Installs pip for Python 3 using the downloaded script.</li><li>Upgrades the pyopenssl package using pip.</li><li>Installs the ec2instanceconnectcli package using pip3.</li><li>Installs the mssh package.</li><li>Uses a loop to wait until the master node is ready by checking its status using kubectl get no.</li><li>Joins the Kubernetes cluster by running kubeadm join command, providing the necessary parameters like the master node&#39;s address, token, and CA certificate hash. The values for these parameters are fetched using the mssh command to execute remote commands on the master node.</li><li>Note: This script assumes that it is run with root privileges, as it uses commands like apt-get and modifies system-level configurations. It also assumes that the variables ${master-id}, ${region}, and ${master-private} are replaced with appropriate values before executing the script.</li></ol><pre>#! /bin/bash<br>apt-get update -y<br>apt-get upgrade -y<br>hostnamectl set-hostname kube-worker<br>apt-get install -y apt-transport-https ca-certificates curl<br>curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -<br>echo &quot;deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://apt.kubernetes.io/ kubernetes-xenial main&quot; | sudo tee /etc/apt/sources.list.d/kubernetes.list<br>apt-get update<br>apt-get install -y kubelet=1.26.3-00 kubeadm=1.26.3-00 kubectl=1.26.3-00 kubernetes-cni docker.io<br>apt-mark hold kubelet kubeadm kubectl<br>systemctl start docker<br>systemctl enable docker<br>usermod -aG docker ubuntu<br>newgrp docker<br>cat &lt;&lt;EOF | sudo tee /etc/sysctl.d/k8s.conf<br>net.bridge.bridge-nf-call-iptables  = 1<br>net.bridge.bridge-nf-call-ip6tables = 1<br>net.ipv4.ip_forward                 = 1<br>EOF<br>sysctl --system<br>mkdir /etc/containerd<br>containerd config default | sudo tee /etc/containerd/config.toml &gt;/dev/null 2&gt;&amp;1<br>sed -i &#39;s/SystemdCgroup \= false/SystemdCgroup \= true/g&#39; /etc/containerd/config.toml<br>systemctl restart containerd<br>systemctl enable containerd<br>wget https://bootstrap.pypa.io/get-pip.py<br>python3 get-pip.py<br>pip install pyopenssl --upgrade<br>pip3 install ec2instanceconnectcli<br>apt install -y mssh<br>until [[ $(mssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t ${master-id} -r ${region} ubuntu@${master-id} kubectl get no | awk &#39;NR == 2 {print $2}&#39;) == Ready ]]; do echo &quot;master node is not ready&quot;; sleep 3; done;<br>kubeadm join ${master-private}:6443 --token $(mssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t ${master-id} -r ${region} ubuntu@${master-id} kubeadm token list | awk &#39;NR == 2 {print $1}&#39;) --discovery-token-ca-cert-hash sha256:$(mssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t ${master-id} -r ${region} ubuntu@${master-id} openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2&gt;/dev/null | openssl dgst -sha256 -hex | sed &#39;s/^.* //&#39;) --ignore-preflight-errors=All</pre><p>Congratulations on successfully creating a Kubernetes cluster! 🎉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2023070937b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Modules on AWS]]></title>
            <link>https://medium.com/@bilgicsule/terraform-modules-on-aws-156e7982b5de?source=rss-6fcedddd996b------2</link>
            <guid isPermaLink="false">https://medium.com/p/156e7982b5de</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <dc:creator><![CDATA[SuleBilgic]]></dc:creator>
            <pubDate>Sun, 28 Apr 2024 12:41:43 GMT</pubDate>
            <atom:updated>2024-05-12T10:00:50.393Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learning Outcome</h3><p>✔️ Use Terraform Modules</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Do7ZMIRGIREZwhxKFzzOEA.png" /></figure><h3>Part 1 — Terraform Modules</h3><p>A module serves as a collection of several resources that are used in conjunction with one another. When you execute terraform plan or terraform apply, the .tf files in your current working directory collectively create the root module. This root module can invoke additional modules and link them by passing output values from one module to the input values of another. In your home directory, create the following directories: terraform-modules, modules, dev, prod. Add the specified files within these directories</p><pre>mkdir terraform-modules &amp;&amp; cd terraform-modules &amp;&amp; mkdir dev modules prod &amp;&amp; cd dev &amp;&amp; touch dev-vpc.tf &amp;&amp; cd ../modules &amp;&amp; touch main.tf outputs.tf variables.tf &amp;&amp; cd ../prod &amp;&amp; touch prod-vpc.tf &amp;&amp; cd ../modules</pre><pre>terraform-modules<br>   ├── dev<br>   │   └── dev-vpc.tf<br>   ├── modules<br>   │   ├── main.tf<br>   │   ├── outputs.tf<br>   │   └── variables.tf<br>   └── prod<br>       └── prod-vpc.tf</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*Bp0YeOVrBX7MyYiLyTaJBA.png" /></figure><ul><li>Go to the modules/main.tf file, add the followings.</li></ul><pre>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}<br><br>resource &quot;aws_vpc&quot; &quot;module_vpc&quot; {<br>  cidr_block = var.vpc_cidr_block<br>  tags = {<br>    Name = &quot;terraform-vpc-${var.environment}&quot;<br>  }<br>}<br><br>resource &quot;aws_subnet&quot; &quot;public_subnet&quot; {<br>  cidr_block = var.public_subnet_cidr<br>  vpc_id = aws_vpc.module_vpc.id<br>  tags = {<br>    Name = &quot;terraform-public-subnet-${var.environment}&quot;<br>  }<br>}<br><br>resource &quot;aws_subnet&quot; &quot;private_subnet&quot; {<br>  cidr_block = var.private_subnet_cidr<br>  vpc_id = aws_vpc.module_vpc.id<br>  tags = {<br>    Name = &quot;terraform-private-subnet-${var.environment}&quot;<br>  }<br>}<br>This is not a real public subnet. Because</pre><p>❗<strong> This isn’t a genuine public subnet, because we haven’t linked it to an internet gateway. What determines whether subnets are private or public are the route table entries.</strong></p><ul><li>Go to the modules/variables.tf file, add the followings.</li></ul><pre>variable &quot;environment&quot; {<br>  default = &quot;sule&quot;<br>}<br># you can give any name here, this is just a value to show the difference from other sources.<br><br>variable &quot;vpc_cidr_block&quot; {<br>  default = &quot;10.0.0.0/16&quot;<br>  description = &quot;this is our vpc cidr block&quot;<br>}<br><br>variable &quot;public_subnet_cidr&quot; {<br>  default = &quot;10.0.1.0/24&quot;<br>  description = &quot;this is our public subnet cidr block&quot;<br>}<br><br>variable &quot;private_subnet_cidr&quot; {<br>  default = &quot;10.0.2.0/24&quot;<br>  description = &quot;this is our private subnet cidr block&quot;<br>}<br>Go to the modules/outputs.tf file, add the followings.<br>output &quot;vpc_id&quot; {<br>  value = aws_vpc.module_vpc.id<br>}<br><br>output &quot;vpc_cidr&quot; {<br>  value = aws_vpc.module_vpc.cidr_block<br>}<br><br>output &quot;public_subnet_cidr&quot; {<br>  value = aws_subnet.public_subnet.cidr_block<br>}<br><br>output &quot;private_subnet_cidr&quot; {<br>  value = aws_subnet.private_subnet.cidr_block<br>}</pre><ul><li>Go to the dev/dev-vpc.tf file, add the followings.</li></ul><pre>module &quot;tf-vpc&quot; {<br>  source = &quot;../modules&quot;<br>  environment = &quot;DEV&quot;<br>  }<br><br>output &quot;vpc-cidr-block&quot; {<br>  value = module.tf-vpc.vpc_cidr<br>}</pre><ul><li>Go to the prod/prod-vpc.tf file, add the followings.</li></ul><pre>module &quot;tf-vpc&quot; {<br>  source = &quot;../modules&quot;<br>  environment = &quot;PROD&quot;<br>  }<br><br>output &quot;vpc-cidr-block&quot; {<br>  value = module.tf-vpc.vpc_cidr<br>}</pre><ul><li>Go to the dev folder and run the command below.</li></ul><pre>terraform init<br><br>terraform apply</pre><p>&gt;&gt; terraform init is a command that initializes a Terraform working directory, setting up the backend and downloading any necessary providers and modules.</p><p>&gt;&gt; terraform apply is a command that executes the Terraform configuration, creating or updating infrastructure resources as defined in the plan.</p><ul><li>Go to the AWS console and check the VPC and subnets.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*Hq52670xmPd-sVO8Z21iwg.png" /></figure><ul><li>Go to the prod folder and run the command below.</li></ul><pre>terraform init<br><br>terraform apply</pre><ul><li>Go to the AWS console and check the VPC and subnets.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*CfTjYgxq_k7OHoH5rRYZZw.png" /></figure><h3>Destroy</h3><p>The terraform destroy command removes resources that are outlined in your Terraform configuration. This command is the opposite of terraform apply because it deletes all the resources specified in the configuration. However, it doesn&#39;t impact resources running outside the current configuration.</p><ul><li>Go to the prod and dev folders and run the command below.</li></ul><pre>terraform destroy -auto-approve</pre><p>🌐<a href="https://registry.terraform.io/providers/tfproviders/aws/latest/docs">For more details, you can explore the official Terraform AWS provider documentation1</a><a href="https://cto.ai/blog/exploring-the-terraform-ecosystem-providers-and-modules/"> and learn about the power of modules in the Terraform ecosystem</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=156e7982b5de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform and Terraform Installation on AWS]]></title>
            <link>https://medium.com/@bilgicsule/terraform-and-terraform-installation-on-aws-dd4cf272038b?source=rss-6fcedddd996b------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd4cf272038b</guid>
            <category><![CDATA[hashicorp]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-cloud]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <dc:creator><![CDATA[SuleBilgic]]></dc:creator>
            <pubDate>Sat, 20 Apr 2024 10:03:50 GMT</pubDate>
            <atom:updated>2024-04-20T10:03:50.130Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*5a005nmYJApWW0yAX6NlDA.png" /></figure><h3>Content :</h3><ul><li>What is Terraform and its Purpose?</li><li>Installation of Terraform on AWS</li><li>Creating and Configuring Terraform Files</li><li>Terraform Commands and Usage</li></ul><p>Terraform represents an open-source tool for infrastructure codification, enabling the definition and provisioning of infrastructure assets in a declarative manner. Through Terraform, users can generate, adjust, and remove infrastructure resources spanning various cloud service providers including Amazon Web Services, Microsoft Azure, and Google Cloud Platform.</p><p>Terraform empowers users to streamline infrastructure management processes within a cloud environment, facilitating efficient resource administration while minimizing manual errors and accelerating infrastructure deployment. Leveraging an intuitive configuration language, Terraform enables straightforward definition of infrastructure resources and their interdependencies.</p><p>Furthermore, Terraform boasts a sophisticated state management system, meticulously monitoring the current infrastructure state and facilitating seamless resource updates and management operations over time. This robust feature ensures perpetual alignment with desired infrastructure states, effectively mitigating the risk of configuration drift.</p><p>In essence, Terraform stands as a robust solution for orchestrating infrastructure resources within cloud environments, offering automation capabilities that enhance operational efficiency and streamline infrastructure management workflows.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*hoZA0RB3MgOgotbQfbfhLA.jpeg" /></figure><p>If you want to use Terraform on an EC2 instance on Amazon, you should use these commands. Of course, you can also use them on your own computer, if you are using a linux-based processor. I am also providing the <a href="https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli">link</a> here, which you can use to benefit from this information. If you are using another operating system other than Linux, I leave a <a href="https://phoenixnap.com/kb/how-to-install-terraform">link</a> here, if you follow the steps in this link, you can install terraform.</p><p>You can do this on amazon linux Instance.</p><pre><strong>Install yum-config-manager to manage your repositories.</strong><br><br><br>sudo yum install -y yum-utils</pre><pre><strong>Update the installed packages and package cache on your instance.</strong><br><br>sudo yum update -y</pre><pre><strong>Install yum-config-manager to manage your repositories.</strong><br><br>sudo yum install -y yum-utils</pre><pre><strong>Use yum-config-manager to add the official HashiCorp Linux repository to the directory of /etc/yum.repos.d.</strong><br><br>sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo</pre><pre><strong>Install Terraform.</strong><br><br>sudo yum -y install terraform</pre><pre><strong>Verify that the installation</strong><br><br>terraform version</pre><pre><strong>list Terraform&#39;s available subcommands.</strong><br><br>terraform -help<br>Usage: terraform [-version] [-help] &lt;command&gt; [args]<br><br>The available commands for execution are listed below.<br>The most common, useful commands are shown first, followed by<br>less common or more advanced commands. If you are just getting<br>started with Terraform, stick with the common commands. For the<br>other commands, please read the help and docs before usage.<br><br>Common co</pre><pre><strong>Add any subcommand to terraform -help to learn more about what it does and available options.</strong><br><br>terraform -help apply<br>or<br>terraform apply -help</pre><p>Congratulations, you have successfully installed terraform!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*30NX6ZQT_nVA2pZDJfaTZg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd4cf272038b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>